cifs: update smb2_queryfs() to use compounding
[linux-block.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>
f29ebb47 22#include <linux/falloc.h>
026e93dc 23#include <linux/scatterlist.h>
4fa8e504 24#include <linux/uuid.h>
026e93dc 25#include <crypto/aead.h>
1080ef75 26#include "cifsglob.h"
2dc7e1c0
PS
27#include "smb2pdu.h"
28#include "smb2proto.h"
28ea5290
PS
29#include "cifsproto.h"
30#include "cifs_debug.h"
b42bf888 31#include "cifs_unicode.h"
2e44b288 32#include "smb2status.h"
6fc05c25 33#include "smb2glob.h"
834170c8 34#include "cifs_ioctl.h"
09902f8d 35#include "smbdirect.h"
28ea5290
PS
36
37static int
38change_conf(struct TCP_Server_Info *server)
39{
40 server->credits += server->echo_credits + server->oplock_credits;
41 server->oplock_credits = server->echo_credits = 0;
42 switch (server->credits) {
43 case 0:
44 return -1;
45 case 1:
46 server->echoes = false;
47 server->oplocks = false;
f96637be 48 cifs_dbg(VFS, "disabling echoes and oplocks\n");
28ea5290
PS
49 break;
50 case 2:
51 server->echoes = true;
52 server->oplocks = false;
53 server->echo_credits = 1;
f96637be 54 cifs_dbg(FYI, "disabling oplocks\n");
28ea5290
PS
55 break;
56 default:
57 server->echoes = true;
e0ddde9d
SF
58 if (enable_oplocks) {
59 server->oplocks = true;
60 server->oplock_credits = 1;
61 } else
62 server->oplocks = false;
63
28ea5290 64 server->echo_credits = 1;
28ea5290
PS
65 }
66 server->credits -= server->echo_credits + server->oplock_credits;
67 return 0;
68}
69
70static void
71smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
72 const int optype)
73{
74 int *val, rc = 0;
75 spin_lock(&server->req_lock);
76 val = server->ops->get_credits_field(server, optype);
77 *val += add;
141891f4
SF
78 if (*val > 65000) {
79 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
80 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
81 }
28ea5290 82 server->in_flight--;
ec2e4523 83 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
28ea5290 84 rc = change_conf(server);
983c88a4
PS
85 /*
86 * Sometimes server returns 0 credits on oplock break ack - we need to
87 * rebalance credits in this case.
88 */
89 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
90 server->oplocks) {
91 if (server->credits > 1) {
92 server->credits--;
93 server->oplock_credits++;
94 }
95 }
28ea5290
PS
96 spin_unlock(&server->req_lock);
97 wake_up(&server->request_q);
98 if (rc)
99 cifs_reconnect(server);
100}
101
102static void
103smb2_set_credits(struct TCP_Server_Info *server, const int val)
104{
105 spin_lock(&server->req_lock);
106 server->credits = val;
107 spin_unlock(&server->req_lock);
108}
109
110static int *
111smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
112{
113 switch (optype) {
114 case CIFS_ECHO_OP:
115 return &server->echo_credits;
116 case CIFS_OBREAK_OP:
117 return &server->oplock_credits;
118 default:
119 return &server->credits;
120 }
121}
122
123static unsigned int
124smb2_get_credits(struct mid_q_entry *mid)
125{
49f466bd 126 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf;
31473fc4
PS
127
128 return le16_to_cpu(shdr->CreditRequest);
28ea5290 129}
2dc7e1c0 130
cb7e9eab
PS
131static int
132smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
133 unsigned int *num, unsigned int *credits)
134{
135 int rc = 0;
136 unsigned int scredits;
137
138 spin_lock(&server->req_lock);
139 while (1) {
140 if (server->credits <= 0) {
141 spin_unlock(&server->req_lock);
142 cifs_num_waiters_inc(server);
143 rc = wait_event_killable(server->request_q,
144 has_credits(server, &server->credits));
145 cifs_num_waiters_dec(server);
146 if (rc)
147 return rc;
148 spin_lock(&server->req_lock);
149 } else {
150 if (server->tcpStatus == CifsExiting) {
151 spin_unlock(&server->req_lock);
152 return -ENOENT;
153 }
154
155 scredits = server->credits;
156 /* can deadlock with reopen */
157 if (scredits == 1) {
158 *num = SMB2_MAX_BUFFER_SIZE;
159 *credits = 0;
160 break;
161 }
162
163 /* leave one credit for a possible reopen */
164 scredits--;
165 *num = min_t(unsigned int, size,
166 scredits * SMB2_MAX_BUFFER_SIZE);
167
168 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
169 server->credits -= *credits;
170 server->in_flight++;
171 break;
172 }
173 }
174 spin_unlock(&server->req_lock);
175 return rc;
176}
177
2dc7e1c0
PS
178static __u64
179smb2_get_next_mid(struct TCP_Server_Info *server)
180{
181 __u64 mid;
182 /* for SMB2 we need the current value */
183 spin_lock(&GlobalMid_Lock);
184 mid = server->CurrentMid++;
185 spin_unlock(&GlobalMid_Lock);
186 return mid;
187}
1080ef75 188
093b2bda
PS
189static struct mid_q_entry *
190smb2_find_mid(struct TCP_Server_Info *server, char *buf)
191{
192 struct mid_q_entry *mid;
49f466bd 193 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
31473fc4 194 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
093b2bda 195
31473fc4 196 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
373512ec
SF
197 cifs_dbg(VFS, "encrypted frame parsing not supported yet");
198 return NULL;
199 }
200
093b2bda
PS
201 spin_lock(&GlobalMid_Lock);
202 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
9235d098 203 if ((mid->mid == wire_mid) &&
093b2bda 204 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
31473fc4 205 (mid->command == shdr->Command)) {
696e420b 206 kref_get(&mid->refcount);
093b2bda
PS
207 spin_unlock(&GlobalMid_Lock);
208 return mid;
209 }
210 }
211 spin_unlock(&GlobalMid_Lock);
212 return NULL;
213}
214
215static void
14547f7d 216smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
093b2bda
PS
217{
218#ifdef CONFIG_CIFS_DEBUG2
49f466bd 219 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
093b2bda 220
f96637be 221 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
31473fc4
PS
222 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
223 shdr->ProcessId);
14547f7d 224 cifs_dbg(VFS, "smb buf %p len %u\n", buf,
71992e62 225 server->ops->calc_smb_size(buf, server));
093b2bda
PS
226#endif
227}
228
ec2e4523
PS
229static bool
230smb2_need_neg(struct TCP_Server_Info *server)
231{
232 return server->max_read == 0;
233}
234
235static int
236smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
237{
238 int rc;
239 ses->server->CurrentMid = 0;
240 rc = SMB2_negotiate(xid, ses);
241 /* BB we probably don't need to retry with modern servers */
242 if (rc == -EAGAIN)
243 rc = -EHOSTDOWN;
244 return rc;
245}
246
3a3bab50
PS
247static unsigned int
248smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
249{
250 struct TCP_Server_Info *server = tcon->ses->server;
251 unsigned int wsize;
252
253 /* start with specified wsize, or default */
254 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
255 wsize = min_t(unsigned int, wsize, server->max_write);
09902f8d 256#ifdef CONFIG_CIFS_SMB_DIRECT
bb4c0419
LL
257 if (server->rdma) {
258 if (server->sign)
259 wsize = min_t(unsigned int,
260 wsize, server->smbd_conn->max_fragmented_send_size);
261 else
262 wsize = min_t(unsigned int,
09902f8d 263 wsize, server->smbd_conn->max_readwrite_size);
bb4c0419 264 }
09902f8d 265#endif
cb7e9eab
PS
266 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
267 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
3a3bab50 268
3a3bab50
PS
269 return wsize;
270}
271
272static unsigned int
273smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
274{
275 struct TCP_Server_Info *server = tcon->ses->server;
276 unsigned int rsize;
277
278 /* start with specified rsize, or default */
279 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
280 rsize = min_t(unsigned int, rsize, server->max_read);
09902f8d 281#ifdef CONFIG_CIFS_SMB_DIRECT
bb4c0419
LL
282 if (server->rdma) {
283 if (server->sign)
284 rsize = min_t(unsigned int,
285 rsize, server->smbd_conn->max_fragmented_recv_size);
286 else
287 rsize = min_t(unsigned int,
09902f8d 288 rsize, server->smbd_conn->max_readwrite_size);
bb4c0419 289 }
09902f8d 290#endif
bed9da02
PS
291
292 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
293 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
3a3bab50 294
3a3bab50
PS
295 return rsize;
296}
297
fe856be4
AA
298
299static int
300parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
301 size_t buf_len,
302 struct cifs_server_iface **iface_list,
303 size_t *iface_count)
304{
305 struct network_interface_info_ioctl_rsp *p;
306 struct sockaddr_in *addr4;
307 struct sockaddr_in6 *addr6;
308 struct iface_info_ipv4 *p4;
309 struct iface_info_ipv6 *p6;
310 struct cifs_server_iface *info;
311 ssize_t bytes_left;
312 size_t next = 0;
313 int nb_iface = 0;
314 int rc = 0;
315
316 *iface_list = NULL;
317 *iface_count = 0;
318
319 /*
320 * Fist pass: count and sanity check
321 */
322
323 bytes_left = buf_len;
324 p = buf;
325 while (bytes_left >= sizeof(*p)) {
326 nb_iface++;
327 next = le32_to_cpu(p->Next);
328 if (!next) {
329 bytes_left -= sizeof(*p);
330 break;
331 }
332 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
333 bytes_left -= next;
334 }
335
336 if (!nb_iface) {
337 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
338 rc = -EINVAL;
339 goto out;
340 }
341
342 if (bytes_left || p->Next)
343 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
344
345
346 /*
347 * Second pass: extract info to internal structure
348 */
349
350 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
351 if (!*iface_list) {
352 rc = -ENOMEM;
353 goto out;
354 }
355
356 info = *iface_list;
357 bytes_left = buf_len;
358 p = buf;
359 while (bytes_left >= sizeof(*p)) {
360 info->speed = le64_to_cpu(p->LinkSpeed);
361 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE);
362 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE);
363
364 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
365 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
366 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
367 le32_to_cpu(p->Capability));
368
369 switch (p->Family) {
370 /*
371 * The kernel and wire socket structures have the same
372 * layout and use network byte order but make the
373 * conversion explicit in case either one changes.
374 */
375 case INTERNETWORK:
376 addr4 = (struct sockaddr_in *)&info->sockaddr;
377 p4 = (struct iface_info_ipv4 *)p->Buffer;
378 addr4->sin_family = AF_INET;
379 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
380
381 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
382 addr4->sin_port = cpu_to_be16(CIFS_PORT);
383
384 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
385 &addr4->sin_addr);
386 break;
387 case INTERNETWORKV6:
388 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
389 p6 = (struct iface_info_ipv6 *)p->Buffer;
390 addr6->sin6_family = AF_INET6;
391 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
392
393 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
394 addr6->sin6_flowinfo = 0;
395 addr6->sin6_scope_id = 0;
396 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
397
398 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
399 &addr6->sin6_addr);
400 break;
401 default:
402 cifs_dbg(VFS,
403 "%s: skipping unsupported socket family\n",
404 __func__);
405 goto next_iface;
406 }
407
408 (*iface_count)++;
409 info++;
410next_iface:
411 next = le32_to_cpu(p->Next);
412 if (!next)
413 break;
414 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
415 bytes_left -= next;
416 }
417
418 if (!*iface_count) {
419 rc = -EINVAL;
420 goto out;
421 }
422
423out:
424 if (rc) {
425 kfree(*iface_list);
426 *iface_count = 0;
427 *iface_list = NULL;
428 }
429 return rc;
430}
431
432
c481e9fe
SF
433static int
434SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
435{
436 int rc;
437 unsigned int ret_data_len = 0;
fe856be4
AA
438 struct network_interface_info_ioctl_rsp *out_buf = NULL;
439 struct cifs_server_iface *iface_list;
440 size_t iface_count;
441 struct cifs_ses *ses = tcon->ses;
c481e9fe
SF
442
443 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
444 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
445 NULL /* no data input */, 0 /* no data input */,
446 (char **)&out_buf, &ret_data_len);
c3ed4402
SF
447 if (rc == -EOPNOTSUPP) {
448 cifs_dbg(FYI,
449 "server does not support query network interfaces\n");
450 goto out;
451 } else if (rc != 0) {
9ffc5412 452 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
fe856be4 453 goto out;
9ffc5412 454 }
fe856be4
AA
455
456 rc = parse_server_interfaces(out_buf, ret_data_len,
457 &iface_list, &iface_count);
458 if (rc)
459 goto out;
460
461 spin_lock(&ses->iface_lock);
462 kfree(ses->iface_list);
463 ses->iface_list = iface_list;
464 ses->iface_count = iface_count;
465 ses->iface_last_update = jiffies;
466 spin_unlock(&ses->iface_lock);
467
468out:
24df1483 469 kfree(out_buf);
c481e9fe
SF
470 return rc;
471}
c481e9fe 472
9da6ec77
RS
473static void
474smb2_close_cached_fid(struct kref *ref)
a93864d9 475{
9da6ec77
RS
476 struct cached_fid *cfid = container_of(ref, struct cached_fid,
477 refcount);
478
a93864d9
RS
479 if (cfid->is_valid) {
480 cifs_dbg(FYI, "clear cached root file handle\n");
481 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
482 cfid->fid->volatile_fid);
483 cfid->is_valid = false;
484 }
9da6ec77
RS
485}
486
487void close_shroot(struct cached_fid *cfid)
488{
489 mutex_lock(&cfid->fid_mutex);
490 kref_put(&cfid->refcount, smb2_close_cached_fid);
a93864d9
RS
491 mutex_unlock(&cfid->fid_mutex);
492}
493
9da6ec77
RS
494void
495smb2_cached_lease_break(struct work_struct *work)
496{
497 struct cached_fid *cfid = container_of(work,
498 struct cached_fid, lease_break);
499
500 close_shroot(cfid);
501}
502
3d4ef9a1
SF
503/*
504 * Open the directory at the root of a share
505 */
506int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
507{
508 struct cifs_open_parms oparams;
509 int rc;
510 __le16 srch_path = 0; /* Null - since an open of top of share */
a93864d9 511 u8 oplock = SMB2_OPLOCK_LEVEL_II;
3d4ef9a1 512
a93864d9
RS
513 mutex_lock(&tcon->crfid.fid_mutex);
514 if (tcon->crfid.is_valid) {
3d4ef9a1 515 cifs_dbg(FYI, "found a cached root file handle\n");
a93864d9 516 memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
9da6ec77 517 kref_get(&tcon->crfid.refcount);
a93864d9 518 mutex_unlock(&tcon->crfid.fid_mutex);
3d4ef9a1
SF
519 return 0;
520 }
521
522 oparams.tcon = tcon;
523 oparams.create_options = 0;
524 oparams.desired_access = FILE_READ_ATTRIBUTES;
525 oparams.disposition = FILE_OPEN;
526 oparams.fid = pfid;
527 oparams.reconnect = false;
528
9d874c36 529 rc = SMB2_open(xid, &oparams, &srch_path, &oplock, NULL, NULL, NULL);
3d4ef9a1 530 if (rc == 0) {
a93864d9
RS
531 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
532 tcon->crfid.tcon = tcon;
533 tcon->crfid.is_valid = true;
9da6ec77
RS
534 kref_init(&tcon->crfid.refcount);
535 kref_get(&tcon->crfid.refcount);
3d4ef9a1 536 }
a93864d9 537 mutex_unlock(&tcon->crfid.fid_mutex);
3d4ef9a1
SF
538 return rc;
539}
540
af6a12ea
SF
541static void
542smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
543{
544 int rc;
545 __le16 srch_path = 0; /* Null - open root of share */
546 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
547 struct cifs_open_parms oparms;
548 struct cifs_fid fid;
3d4ef9a1 549 bool no_cached_open = tcon->nohandlecache;
af6a12ea
SF
550
551 oparms.tcon = tcon;
552 oparms.desired_access = FILE_READ_ATTRIBUTES;
553 oparms.disposition = FILE_OPEN;
554 oparms.create_options = 0;
555 oparms.fid = &fid;
556 oparms.reconnect = false;
557
3d4ef9a1 558 if (no_cached_open)
9d874c36
RS
559 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
560 NULL);
3d4ef9a1
SF
561 else
562 rc = open_shroot(xid, tcon, &fid);
563
af6a12ea
SF
564 if (rc)
565 return;
566
c481e9fe 567 SMB3_request_interfaces(xid, tcon);
c481e9fe 568
af6a12ea
SF
569 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
570 FS_ATTRIBUTE_INFORMATION);
571 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
572 FS_DEVICE_INFORMATION);
21ba3845
SF
573 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
574 FS_VOLUME_INFORMATION);
af6a12ea
SF
575 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
576 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
3d4ef9a1
SF
577 if (no_cached_open)
578 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
9da6ec77
RS
579 else
580 close_shroot(&tcon->crfid);
581
af6a12ea
SF
582 return;
583}
584
34f62640
SF
585static void
586smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
587{
588 int rc;
589 __le16 srch_path = 0; /* Null - open root of share */
590 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
591 struct cifs_open_parms oparms;
592 struct cifs_fid fid;
593
594 oparms.tcon = tcon;
595 oparms.desired_access = FILE_READ_ATTRIBUTES;
596 oparms.disposition = FILE_OPEN;
597 oparms.create_options = 0;
598 oparms.fid = &fid;
599 oparms.reconnect = false;
600
9d874c36 601 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
34f62640
SF
602 if (rc)
603 return;
604
2167114c
SF
605 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
606 FS_ATTRIBUTE_INFORMATION);
607 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
608 FS_DEVICE_INFORMATION);
34f62640
SF
609 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
610 return;
611}
612
2503a0db
PS
613static int
614smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
615 struct cifs_sb_info *cifs_sb, const char *full_path)
616{
617 int rc;
2503a0db 618 __le16 *utf16_path;
2e44b288 619 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
064f6047
PS
620 struct cifs_open_parms oparms;
621 struct cifs_fid fid;
2503a0db 622
a93864d9 623 if ((*full_path == 0) && tcon->crfid.is_valid)
3d4ef9a1
SF
624 return 0;
625
2503a0db
PS
626 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
627 if (!utf16_path)
628 return -ENOMEM;
629
064f6047
PS
630 oparms.tcon = tcon;
631 oparms.desired_access = FILE_READ_ATTRIBUTES;
632 oparms.disposition = FILE_OPEN;
633 oparms.create_options = 0;
634 oparms.fid = &fid;
9cbc0b73 635 oparms.reconnect = false;
064f6047 636
9d874c36 637 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2503a0db
PS
638 if (rc) {
639 kfree(utf16_path);
640 return rc;
641 }
642
064f6047 643 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2503a0db
PS
644 kfree(utf16_path);
645 return rc;
646}
647
be4cb9e3
PS
648static int
649smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
650 struct cifs_sb_info *cifs_sb, const char *full_path,
651 u64 *uniqueid, FILE_ALL_INFO *data)
652{
653 *uniqueid = le64_to_cpu(data->IndexNumber);
654 return 0;
655}
656
b7546bc5
PS
657static int
658smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
659 struct cifs_fid *fid, FILE_ALL_INFO *data)
660{
661 int rc;
662 struct smb2_file_all_info *smb2_data;
663
1bbe4997 664 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
b7546bc5
PS
665 GFP_KERNEL);
666 if (smb2_data == NULL)
667 return -ENOMEM;
668
669 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
670 smb2_data);
671 if (!rc)
672 move_smb2_info_to_cifs(data, smb2_data);
673 kfree(smb2_data);
674 return rc;
675}
676
1368f155 677#ifdef CONFIG_CIFS_XATTR
95907fea
RS
678static ssize_t
679move_smb2_ea_to_cifs(char *dst, size_t dst_size,
680 struct smb2_file_full_ea_info *src, size_t src_size,
681 const unsigned char *ea_name)
682{
683 int rc = 0;
684 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
685 char *name, *value;
686 size_t name_len, value_len, user_name_len;
687
688 while (src_size > 0) {
689 name = &src->ea_data[0];
690 name_len = (size_t)src->ea_name_length;
691 value = &src->ea_data[src->ea_name_length + 1];
692 value_len = (size_t)le16_to_cpu(src->ea_value_length);
693
694 if (name_len == 0) {
695 break;
696 }
697
698 if (src_size < 8 + name_len + 1 + value_len) {
699 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
700 rc = -EIO;
701 goto out;
702 }
703
704 if (ea_name) {
705 if (ea_name_len == name_len &&
706 memcmp(ea_name, name, name_len) == 0) {
707 rc = value_len;
708 if (dst_size == 0)
709 goto out;
710 if (dst_size < value_len) {
711 rc = -ERANGE;
712 goto out;
713 }
714 memcpy(dst, value, value_len);
715 goto out;
716 }
717 } else {
718 /* 'user.' plus a terminating null */
719 user_name_len = 5 + 1 + name_len;
720
721 rc += user_name_len;
722
723 if (dst_size >= user_name_len) {
724 dst_size -= user_name_len;
725 memcpy(dst, "user.", 5);
726 dst += 5;
727 memcpy(dst, src->ea_data, name_len);
728 dst += name_len;
729 *dst = 0;
730 ++dst;
731 } else if (dst_size == 0) {
732 /* skip copy - calc size only */
733 } else {
734 /* stop before overrun buffer */
735 rc = -ERANGE;
736 break;
737 }
738 }
739
740 if (!src->next_entry_offset)
741 break;
742
743 if (src_size < le32_to_cpu(src->next_entry_offset)) {
744 /* stop before overrun buffer */
745 rc = -ERANGE;
746 break;
747 }
748 src_size -= le32_to_cpu(src->next_entry_offset);
749 src = (void *)((char *)src +
750 le32_to_cpu(src->next_entry_offset));
751 }
752
753 /* didn't find the named attribute */
754 if (ea_name)
755 rc = -ENODATA;
756
757out:
758 return (ssize_t)rc;
759}
760
761static ssize_t
762smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
763 const unsigned char *path, const unsigned char *ea_name,
764 char *ea_data, size_t buf_size,
765 struct cifs_sb_info *cifs_sb)
766{
767 int rc;
768 __le16 *utf16_path;
769 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
770 struct cifs_open_parms oparms;
771 struct cifs_fid fid;
772 struct smb2_file_full_ea_info *smb2_data;
7cb3def4 773 int ea_buf_size = SMB2_MIN_EA_BUF;
95907fea
RS
774
775 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
776 if (!utf16_path)
777 return -ENOMEM;
778
779 oparms.tcon = tcon;
780 oparms.desired_access = FILE_READ_EA;
781 oparms.disposition = FILE_OPEN;
782 oparms.create_options = 0;
783 oparms.fid = &fid;
784 oparms.reconnect = false;
785
9d874c36 786 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
95907fea
RS
787 kfree(utf16_path);
788 if (rc) {
789 cifs_dbg(FYI, "open failed rc=%d\n", rc);
790 return rc;
791 }
792
7cb3def4
RS
793 while (1) {
794 smb2_data = kzalloc(ea_buf_size, GFP_KERNEL);
795 if (smb2_data == NULL) {
796 SMB2_close(xid, tcon, fid.persistent_fid,
797 fid.volatile_fid);
798 return -ENOMEM;
799 }
800
801 rc = SMB2_query_eas(xid, tcon, fid.persistent_fid,
802 fid.volatile_fid,
803 ea_buf_size, smb2_data);
804
805 if (rc != -E2BIG)
806 break;
807
808 kfree(smb2_data);
809 ea_buf_size <<= 1;
810
811 if (ea_buf_size > SMB2_MAX_EA_BUF) {
812 cifs_dbg(VFS, "EA size is too large\n");
813 SMB2_close(xid, tcon, fid.persistent_fid,
814 fid.volatile_fid);
815 return -ENOMEM;
816 }
95907fea
RS
817 }
818
95907fea
RS
819 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
820
ae2cd7fb
PA
821 /*
822 * If ea_name is NULL (listxattr) and there are no EAs, return 0 as it's
823 * not an error. Otherwise, the specified ea_name was not found.
824 */
95907fea
RS
825 if (!rc)
826 rc = move_smb2_ea_to_cifs(ea_data, buf_size, smb2_data,
827 SMB2_MAX_EA_BUF, ea_name);
ae2cd7fb
PA
828 else if (!ea_name && rc == -ENODATA)
829 rc = 0;
95907fea
RS
830
831 kfree(smb2_data);
832 return rc;
833}
834
5517554e
RS
835
836static int
837smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
838 const char *path, const char *ea_name, const void *ea_value,
839 const __u16 ea_value_len, const struct nls_table *nls_codepage,
840 struct cifs_sb_info *cifs_sb)
841{
842 int rc;
843 __le16 *utf16_path;
844 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
845 struct cifs_open_parms oparms;
846 struct cifs_fid fid;
847 struct smb2_file_full_ea_info *ea;
848 int ea_name_len = strlen(ea_name);
849 int len;
850
851 if (ea_name_len > 255)
852 return -EINVAL;
853
854 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
855 if (!utf16_path)
856 return -ENOMEM;
857
858 oparms.tcon = tcon;
859 oparms.desired_access = FILE_WRITE_EA;
860 oparms.disposition = FILE_OPEN;
861 oparms.create_options = 0;
862 oparms.fid = &fid;
863 oparms.reconnect = false;
864
9d874c36 865 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
5517554e
RS
866 kfree(utf16_path);
867 if (rc) {
868 cifs_dbg(FYI, "open failed rc=%d\n", rc);
869 return rc;
870 }
871
872 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
873 ea = kzalloc(len, GFP_KERNEL);
874 if (ea == NULL) {
875 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
876 return -ENOMEM;
877 }
878
879 ea->ea_name_length = ea_name_len;
880 ea->ea_value_length = cpu_to_le16(ea_value_len);
881 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
882 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
883
884 rc = SMB2_set_ea(xid, tcon, fid.persistent_fid, fid.volatile_fid, ea,
885 len);
6aa0c114
PA
886 kfree(ea);
887
5517554e
RS
888 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
889
890 return rc;
891}
1368f155 892#endif
5517554e 893
9094fad1
PS
894static bool
895smb2_can_echo(struct TCP_Server_Info *server)
896{
897 return server->echoes;
898}
899
d60622eb
PS
900static void
901smb2_clear_stats(struct cifs_tcon *tcon)
902{
d60622eb
PS
903 int i;
904 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
905 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
906 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
907 }
d60622eb
PS
908}
909
769ee6a4
SF
910static void
911smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
912{
913 seq_puts(m, "\n\tShare Capabilities:");
914 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
915 seq_puts(m, " DFS,");
916 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
917 seq_puts(m, " CONTINUOUS AVAILABILITY,");
918 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
919 seq_puts(m, " SCALEOUT,");
920 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
921 seq_puts(m, " CLUSTER,");
922 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
923 seq_puts(m, " ASYMMETRIC,");
924 if (tcon->capabilities == 0)
925 seq_puts(m, " None");
af6a12ea
SF
926 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
927 seq_puts(m, " Aligned,");
928 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
929 seq_puts(m, " Partition Aligned,");
930 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
931 seq_puts(m, " SSD,");
932 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
933 seq_puts(m, " TRIM-support,");
934
769ee6a4 935 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
e0386e44 936 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
af6a12ea
SF
937 if (tcon->perf_sector_size)
938 seq_printf(m, "\tOptimal sector size: 0x%x",
939 tcon->perf_sector_size);
e0386e44 940 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
769ee6a4
SF
941}
942
d60622eb
PS
943static void
944smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
945{
d60622eb
PS
946 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
947 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1995d28f
SF
948
949 /*
950 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
951 * totals (requests sent) since those SMBs are per-session not per tcon
952 */
52ce1ac4
SF
953 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
954 (long long)(tcon->bytes_read),
955 (long long)(tcon->bytes_written));
1995d28f 956 seq_printf(m, "\nTreeConnects: %d total %d failed",
d60622eb
PS
957 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
958 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1995d28f 959 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
d60622eb
PS
960 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
961 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1995d28f 962 seq_printf(m, "\nCreates: %d total %d failed",
d60622eb
PS
963 atomic_read(&sent[SMB2_CREATE_HE]),
964 atomic_read(&failed[SMB2_CREATE_HE]));
1995d28f 965 seq_printf(m, "\nCloses: %d total %d failed",
d60622eb
PS
966 atomic_read(&sent[SMB2_CLOSE_HE]),
967 atomic_read(&failed[SMB2_CLOSE_HE]));
1995d28f 968 seq_printf(m, "\nFlushes: %d total %d failed",
d60622eb
PS
969 atomic_read(&sent[SMB2_FLUSH_HE]),
970 atomic_read(&failed[SMB2_FLUSH_HE]));
1995d28f 971 seq_printf(m, "\nReads: %d total %d failed",
d60622eb
PS
972 atomic_read(&sent[SMB2_READ_HE]),
973 atomic_read(&failed[SMB2_READ_HE]));
1995d28f 974 seq_printf(m, "\nWrites: %d total %d failed",
d60622eb
PS
975 atomic_read(&sent[SMB2_WRITE_HE]),
976 atomic_read(&failed[SMB2_WRITE_HE]));
1995d28f 977 seq_printf(m, "\nLocks: %d total %d failed",
d60622eb
PS
978 atomic_read(&sent[SMB2_LOCK_HE]),
979 atomic_read(&failed[SMB2_LOCK_HE]));
1995d28f 980 seq_printf(m, "\nIOCTLs: %d total %d failed",
d60622eb
PS
981 atomic_read(&sent[SMB2_IOCTL_HE]),
982 atomic_read(&failed[SMB2_IOCTL_HE]));
1995d28f 983 seq_printf(m, "\nQueryDirectories: %d total %d failed",
d60622eb
PS
984 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
985 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1995d28f 986 seq_printf(m, "\nChangeNotifies: %d total %d failed",
d60622eb
PS
987 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
988 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1995d28f 989 seq_printf(m, "\nQueryInfos: %d total %d failed",
d60622eb
PS
990 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
991 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1995d28f 992 seq_printf(m, "\nSetInfos: %d total %d failed",
d60622eb
PS
993 atomic_read(&sent[SMB2_SET_INFO_HE]),
994 atomic_read(&failed[SMB2_SET_INFO_HE]));
995 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
996 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
997 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
d60622eb
PS
998}
999
f0df737e
PS
1000static void
1001smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1002{
2b0143b5 1003 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
53ef1016
PS
1004 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1005
f0df737e
PS
1006 cfile->fid.persistent_fid = fid->persistent_fid;
1007 cfile->fid.volatile_fid = fid->volatile_fid;
42873b0a
PS
1008 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1009 &fid->purge_cache);
18cceb6a 1010 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
94f87371 1011 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
f0df737e
PS
1012}
1013
760ad0ca 1014static void
f0df737e
PS
1015smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1016 struct cifs_fid *fid)
1017{
760ad0ca 1018 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
f0df737e
PS
1019}
1020
41c1358e
SF
1021static int
1022SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1023 u64 persistent_fid, u64 volatile_fid,
1024 struct copychunk_ioctl *pcchunk)
1025{
1026 int rc;
1027 unsigned int ret_data_len;
1028 struct resume_key_req *res_key;
1029
1030 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1031 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1032 NULL, 0 /* no input */,
1033 (char **)&res_key, &ret_data_len);
1034
1035 if (rc) {
1036 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1037 goto req_res_key_exit;
1038 }
1039 if (ret_data_len < sizeof(struct resume_key_req)) {
1040 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
1041 rc = -EINVAL;
1042 goto req_res_key_exit;
1043 }
1044 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1045
1046req_res_key_exit:
1047 kfree(res_key);
1048 return rc;
1049}
1050
620d8745 1051static ssize_t
312bbc59 1052smb2_copychunk_range(const unsigned int xid,
41c1358e
SF
1053 struct cifsFileInfo *srcfile,
1054 struct cifsFileInfo *trgtfile, u64 src_off,
1055 u64 len, u64 dest_off)
1056{
1057 int rc;
1058 unsigned int ret_data_len;
1059 struct copychunk_ioctl *pcchunk;
9bf0c9cd
SF
1060 struct copychunk_ioctl_rsp *retbuf = NULL;
1061 struct cifs_tcon *tcon;
1062 int chunks_copied = 0;
1063 bool chunk_sizes_updated = false;
620d8745 1064 ssize_t bytes_written, total_bytes_written = 0;
41c1358e
SF
1065
1066 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1067
1068 if (pcchunk == NULL)
1069 return -ENOMEM;
1070
312bbc59 1071 cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
41c1358e
SF
1072 /* Request a key from the server to identify the source of the copy */
1073 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1074 srcfile->fid.persistent_fid,
1075 srcfile->fid.volatile_fid, pcchunk);
1076
1077 /* Note: request_res_key sets res_key null only if rc !=0 */
1078 if (rc)
9bf0c9cd 1079 goto cchunk_out;
41c1358e
SF
1080
1081 /* For now array only one chunk long, will make more flexible later */
bc09d141 1082 pcchunk->ChunkCount = cpu_to_le32(1);
41c1358e 1083 pcchunk->Reserved = 0;
41c1358e
SF
1084 pcchunk->Reserved2 = 0;
1085
9bf0c9cd 1086 tcon = tlink_tcon(trgtfile->tlink);
41c1358e 1087
9bf0c9cd
SF
1088 while (len > 0) {
1089 pcchunk->SourceOffset = cpu_to_le64(src_off);
1090 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1091 pcchunk->Length =
1092 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
41c1358e 1093
9bf0c9cd
SF
1094 /* Request server copy to target from src identified by key */
1095 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1096 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
63a83b86 1097 true /* is_fsctl */, (char *)pcchunk,
9bf0c9cd
SF
1098 sizeof(struct copychunk_ioctl), (char **)&retbuf,
1099 &ret_data_len);
1100 if (rc == 0) {
1101 if (ret_data_len !=
1102 sizeof(struct copychunk_ioctl_rsp)) {
1103 cifs_dbg(VFS, "invalid cchunk response size\n");
1104 rc = -EIO;
1105 goto cchunk_out;
1106 }
1107 if (retbuf->TotalBytesWritten == 0) {
1108 cifs_dbg(FYI, "no bytes copied\n");
1109 rc = -EIO;
1110 goto cchunk_out;
1111 }
1112 /*
1113 * Check if server claimed to write more than we asked
1114 */
1115 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1116 le32_to_cpu(pcchunk->Length)) {
1117 cifs_dbg(VFS, "invalid copy chunk response\n");
1118 rc = -EIO;
1119 goto cchunk_out;
1120 }
1121 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1122 cifs_dbg(VFS, "invalid num chunks written\n");
1123 rc = -EIO;
1124 goto cchunk_out;
1125 }
1126 chunks_copied++;
1127
620d8745
SP
1128 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1129 src_off += bytes_written;
1130 dest_off += bytes_written;
1131 len -= bytes_written;
1132 total_bytes_written += bytes_written;
9bf0c9cd 1133
620d8745 1134 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
9bf0c9cd
SF
1135 le32_to_cpu(retbuf->ChunksWritten),
1136 le32_to_cpu(retbuf->ChunkBytesWritten),
620d8745 1137 bytes_written);
9bf0c9cd
SF
1138 } else if (rc == -EINVAL) {
1139 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1140 goto cchunk_out;
1141
1142 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1143 le32_to_cpu(retbuf->ChunksWritten),
1144 le32_to_cpu(retbuf->ChunkBytesWritten),
1145 le32_to_cpu(retbuf->TotalBytesWritten));
1146
1147 /*
1148 * Check if this is the first request using these sizes,
1149 * (ie check if copy succeed once with original sizes
1150 * and check if the server gave us different sizes after
1151 * we already updated max sizes on previous request).
1152 * if not then why is the server returning an error now
1153 */
1154 if ((chunks_copied != 0) || chunk_sizes_updated)
1155 goto cchunk_out;
1156
1157 /* Check that server is not asking us to grow size */
1158 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1159 tcon->max_bytes_chunk)
1160 tcon->max_bytes_chunk =
1161 le32_to_cpu(retbuf->ChunkBytesWritten);
1162 else
1163 goto cchunk_out; /* server gave us bogus size */
1164
1165 /* No need to change MaxChunks since already set to 1 */
1166 chunk_sizes_updated = true;
2477bc58
SP
1167 } else
1168 goto cchunk_out;
9bf0c9cd 1169 }
41c1358e 1170
9bf0c9cd 1171cchunk_out:
41c1358e 1172 kfree(pcchunk);
24df1483 1173 kfree(retbuf);
620d8745
SP
1174 if (rc)
1175 return rc;
1176 else
1177 return total_bytes_written;
41c1358e
SF
1178}
1179
7a5cfb19
PS
1180static int
1181smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1182 struct cifs_fid *fid)
1183{
1184 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1185}
1186
09a4707e
PS
1187static unsigned int
1188smb2_read_data_offset(char *buf)
1189{
1190 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1191 return rsp->DataOffset;
1192}
1193
1194static unsigned int
74dcf418 1195smb2_read_data_length(char *buf, bool in_remaining)
09a4707e
PS
1196{
1197 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
74dcf418
LL
1198
1199 if (in_remaining)
1200 return le32_to_cpu(rsp->DataRemaining);
1201
09a4707e
PS
1202 return le32_to_cpu(rsp->DataLength);
1203}
1204
d8e05039
PS
1205
1206static int
db8b631d 1207smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
d8e05039
PS
1208 struct cifs_io_parms *parms, unsigned int *bytes_read,
1209 char **buf, int *buf_type)
1210{
db8b631d
SF
1211 parms->persistent_fid = pfid->persistent_fid;
1212 parms->volatile_fid = pfid->volatile_fid;
d8e05039
PS
1213 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1214}
1215
009d3443 1216static int
db8b631d 1217smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
009d3443
PS
1218 struct cifs_io_parms *parms, unsigned int *written,
1219 struct kvec *iov, unsigned long nr_segs)
1220{
1221
db8b631d
SF
1222 parms->persistent_fid = pfid->persistent_fid;
1223 parms->volatile_fid = pfid->volatile_fid;
009d3443
PS
1224 return SMB2_write(xid, parms, written, iov, nr_segs);
1225}
1226
d43cc793
SF
1227/* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1228static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1229 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1230{
1231 struct cifsInodeInfo *cifsi;
1232 int rc;
1233
1234 cifsi = CIFS_I(inode);
1235
1236 /* if file already sparse don't bother setting sparse again */
1237 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1238 return true; /* already sparse */
1239
1240 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1241 return true; /* already not sparse */
1242
1243 /*
1244 * Can't check for sparse support on share the usual way via the
1245 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1246 * since Samba server doesn't set the flag on the share, yet
1247 * supports the set sparse FSCTL and returns sparse correctly
1248 * in the file attributes. If we fail setting sparse though we
1249 * mark that server does not support sparse files for this share
1250 * to avoid repeatedly sending the unsupported fsctl to server
1251 * if the file is repeatedly extended.
1252 */
1253 if (tcon->broken_sparse_sup)
1254 return false;
1255
1256 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1257 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
63a83b86 1258 true /* is_fctl */,
51146625 1259 &setsparse, 1, NULL, NULL);
d43cc793
SF
1260 if (rc) {
1261 tcon->broken_sparse_sup = true;
1262 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1263 return false;
1264 }
1265
1266 if (setsparse)
1267 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1268 else
1269 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1270
1271 return true;
1272}
1273
c839ff24
PS
1274static int
1275smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1276 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1277{
1278 __le64 eof = cpu_to_le64(size);
3d1a3745
SF
1279 struct inode *inode;
1280
1281 /*
1282 * If extending file more than one page make sparse. Many Linux fs
1283 * make files sparse by default when extending via ftruncate
1284 */
2b0143b5 1285 inode = d_inode(cfile->dentry);
3d1a3745
SF
1286
1287 if (!set_alloc && (size > inode->i_size + 8192)) {
3d1a3745 1288 __u8 set_sparse = 1;
d43cc793
SF
1289
1290 /* whether set sparse succeeds or not, extend the file */
1291 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
3d1a3745
SF
1292 }
1293
c839ff24 1294 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
f29ebb47 1295 cfile->fid.volatile_fid, cfile->pid, &eof, false);
c839ff24
PS
1296}
1297
02b16665
SF
1298static int
1299smb2_duplicate_extents(const unsigned int xid,
1300 struct cifsFileInfo *srcfile,
1301 struct cifsFileInfo *trgtfile, u64 src_off,
1302 u64 len, u64 dest_off)
1303{
1304 int rc;
1305 unsigned int ret_data_len;
02b16665
SF
1306 struct duplicate_extents_to_file dup_ext_buf;
1307 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1308
1309 /* server fileays advertise duplicate extent support with this flag */
1310 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1311 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1312 return -EOPNOTSUPP;
1313
1314 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1315 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1316 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1317 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1318 dup_ext_buf.ByteCount = cpu_to_le64(len);
1319 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
1320 src_off, dest_off, len);
1321
1322 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1323 if (rc)
1324 goto duplicate_extents_out;
1325
1326 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1327 trgtfile->fid.volatile_fid,
1328 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
63a83b86 1329 true /* is_fsctl */,
51146625 1330 (char *)&dup_ext_buf,
02b16665 1331 sizeof(struct duplicate_extents_to_file),
24df1483 1332 NULL,
02b16665
SF
1333 &ret_data_len);
1334
1335 if (ret_data_len > 0)
1336 cifs_dbg(FYI, "non-zero response length in duplicate extents");
1337
1338duplicate_extents_out:
1339 return rc;
1340}
02b16665 1341
64a5cfa6
SF
1342static int
1343smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1344 struct cifsFileInfo *cfile)
1345{
1346 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1347 cfile->fid.volatile_fid);
1348}
1349
b3152e2c
SF
1350static int
1351smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1352 struct cifsFileInfo *cfile)
1353{
1354 struct fsctl_set_integrity_information_req integr_info;
b3152e2c
SF
1355 unsigned int ret_data_len;
1356
1357 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1358 integr_info.Flags = 0;
1359 integr_info.Reserved = 0;
1360
1361 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1362 cfile->fid.volatile_fid,
1363 FSCTL_SET_INTEGRITY_INFORMATION,
63a83b86 1364 true /* is_fsctl */,
51146625 1365 (char *)&integr_info,
b3152e2c 1366 sizeof(struct fsctl_set_integrity_information_req),
24df1483 1367 NULL,
b3152e2c
SF
1368 &ret_data_len);
1369
1370}
1371
834170c8
SF
1372static int
1373smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1374 struct cifsFileInfo *cfile, void __user *ioc_buf)
1375{
1376 char *retbuf = NULL;
1377 unsigned int ret_data_len = 0;
1378 int rc;
1379 struct smb_snapshot_array snapshot_in;
1380
1381 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1382 cfile->fid.volatile_fid,
1383 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
63a83b86 1384 true /* is_fsctl */,
51146625 1385 NULL, 0 /* no input data */,
834170c8
SF
1386 (char **)&retbuf,
1387 &ret_data_len);
1388 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1389 rc, ret_data_len);
1390 if (rc)
1391 return rc;
1392
1393 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1394 /* Fixup buffer */
1395 if (copy_from_user(&snapshot_in, ioc_buf,
1396 sizeof(struct smb_snapshot_array))) {
1397 rc = -EFAULT;
1398 kfree(retbuf);
1399 return rc;
1400 }
1401 if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) {
1402 rc = -ERANGE;
0e5c7955 1403 kfree(retbuf);
834170c8
SF
1404 return rc;
1405 }
1406
1407 if (ret_data_len > snapshot_in.snapshot_array_size)
1408 ret_data_len = snapshot_in.snapshot_array_size;
1409
1410 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
1411 rc = -EFAULT;
1412 }
1413
1414 kfree(retbuf);
1415 return rc;
1416}
1417
d324f08d
PS
1418static int
1419smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1420 const char *path, struct cifs_sb_info *cifs_sb,
1421 struct cifs_fid *fid, __u16 search_flags,
1422 struct cifs_search_info *srch_inf)
1423{
1424 __le16 *utf16_path;
1425 int rc;
2e44b288 1426 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
064f6047 1427 struct cifs_open_parms oparms;
d324f08d
PS
1428
1429 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1430 if (!utf16_path)
1431 return -ENOMEM;
1432
064f6047
PS
1433 oparms.tcon = tcon;
1434 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
1435 oparms.disposition = FILE_OPEN;
1436 oparms.create_options = 0;
1437 oparms.fid = fid;
9cbc0b73 1438 oparms.reconnect = false;
064f6047 1439
9d874c36 1440 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
d324f08d
PS
1441 kfree(utf16_path);
1442 if (rc) {
dcd87838 1443 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
d324f08d
PS
1444 return rc;
1445 }
1446
1447 srch_inf->entries_in_buffer = 0;
1448 srch_inf->index_of_last_entry = 0;
d324f08d 1449
064f6047
PS
1450 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
1451 fid->volatile_fid, 0, srch_inf);
d324f08d 1452 if (rc) {
dcd87838 1453 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
064f6047 1454 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
d324f08d
PS
1455 }
1456 return rc;
1457}
1458
1459static int
1460smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
1461 struct cifs_fid *fid, __u16 search_flags,
1462 struct cifs_search_info *srch_inf)
1463{
1464 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
1465 fid->volatile_fid, 0, srch_inf);
1466}
1467
1468static int
1469smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1470 struct cifs_fid *fid)
1471{
1472 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1473}
1474
2e44b288
PS
1475/*
1476* If we negotiate SMB2 protocol and get STATUS_PENDING - update
1477* the number of credits and return true. Otherwise - return false.
1478*/
1479static bool
1480smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
1481{
49f466bd 1482 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2e44b288 1483
31473fc4 1484 if (shdr->Status != STATUS_PENDING)
2e44b288
PS
1485 return false;
1486
1487 if (!length) {
1488 spin_lock(&server->req_lock);
31473fc4 1489 server->credits += le16_to_cpu(shdr->CreditRequest);
2e44b288
PS
1490 spin_unlock(&server->req_lock);
1491 wake_up(&server->request_q);
1492 }
1493
1494 return true;
1495}
1496
511c54a2
PS
1497static bool
1498smb2_is_session_expired(char *buf)
1499{
49f466bd 1500 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
511c54a2 1501
d81243c6
MS
1502 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
1503 shdr->Status != STATUS_USER_SESSION_DELETED)
511c54a2
PS
1504 return false;
1505
e68a932b
SF
1506 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
1507 le16_to_cpu(shdr->Command),
1508 le64_to_cpu(shdr->MessageId));
d81243c6 1509 cifs_dbg(FYI, "Session expired or deleted\n");
e68a932b 1510
511c54a2
PS
1511 return true;
1512}
1513
983c88a4
PS
1514static int
1515smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
1516 struct cifsInodeInfo *cinode)
1517{
0822f514
PS
1518 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
1519 return SMB2_lease_break(0, tcon, cinode->lease_key,
1520 smb2_get_lease_state(cinode));
1521
983c88a4
PS
1522 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
1523 fid->volatile_fid,
18cceb6a 1524 CIFS_CACHE_READ(cinode) ? 1 : 0);
983c88a4
PS
1525}
1526
730928c8
RS
1527static void
1528smb2_set_related(struct smb_rqst *rqst)
1529{
1530 struct smb2_sync_hdr *shdr;
1531
1532 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
1533 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
1534}
1535
1536char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
1537
1538static void
1539smb2_set_next_command(struct TCP_Server_Info *server, struct smb_rqst *rqst)
1540{
1541 struct smb2_sync_hdr *shdr;
1542 unsigned long len = smb_rqst_len(server, rqst);
1543
1544 /* SMB headers in a compound are 8 byte aligned. */
1545 if (len & 7) {
1546 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
1547 rqst->rq_iov[rqst->rq_nvec].iov_len = 8 - (len & 7);
1548 rqst->rq_nvec++;
1549 len = smb_rqst_len(server, rqst);
1550 }
1551
1552 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
1553 shdr->NextCommand = cpu_to_le32(len);
1554}
1555
6fc05c25
PS
1556static int
1557smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1558 struct kstatfs *buf)
1559{
730928c8
RS
1560 struct smb2_query_info_rsp *rsp;
1561 struct smb2_fs_full_size_info *info = NULL;
1562 struct smb_rqst rqst[3];
1563 int resp_buftype[3];
1564 struct kvec rsp_iov[3];
1565 struct kvec open_iov[5]; /* 4 + potential padding. */
1566 struct kvec qi_iov[1];
1567 struct kvec close_iov[1];
1568 struct cifs_ses *ses = tcon->ses;
1569 struct TCP_Server_Info *server = ses->server;
6fc05c25
PS
1570 __le16 srch_path = 0; /* Null - open root of share */
1571 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
064f6047
PS
1572 struct cifs_open_parms oparms;
1573 struct cifs_fid fid;
730928c8
RS
1574 int flags = 0;
1575 int rc;
1576
1577 if (smb3_encryption_required(tcon))
1578 flags |= CIFS_TRANSFORM_REQ;
1579
1580 memset(rqst, 0, sizeof(rqst));
1581 memset(resp_buftype, 0, sizeof(resp_buftype));
1582 memset(rsp_iov, 0, sizeof(rsp_iov));
1583
1584 memset(&open_iov, 0, sizeof(open_iov));
1585 rqst[0].rq_iov = open_iov;
1586 rqst[0].rq_nvec = 4;
064f6047
PS
1587
1588 oparms.tcon = tcon;
1589 oparms.desired_access = FILE_READ_ATTRIBUTES;
1590 oparms.disposition = FILE_OPEN;
1591 oparms.create_options = 0;
1592 oparms.fid = &fid;
9cbc0b73 1593 oparms.reconnect = false;
6fc05c25 1594
730928c8 1595 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, &srch_path);
6fc05c25 1596 if (rc)
730928c8
RS
1597 goto qfs_exit;
1598 smb2_set_next_command(server, &rqst[0]);
1599
1600 memset(&qi_iov, 0, sizeof(qi_iov));
1601 rqst[1].rq_iov = qi_iov;
1602 rqst[1].rq_nvec = 1;
1603
1604 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1605 FS_FULL_SIZE_INFORMATION,
1606 SMB2_O_INFO_FILESYSTEM, 0,
1607 sizeof(struct smb2_fs_full_size_info));
1608 if (rc)
1609 goto qfs_exit;
1610 smb2_set_next_command(server, &rqst[1]);
1611 smb2_set_related(&rqst[1]);
1612
1613 memset(&close_iov, 0, sizeof(close_iov));
1614 rqst[2].rq_iov = close_iov;
1615 rqst[2].rq_nvec = 1;
1616
1617 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1618 if (rc)
1619 goto qfs_exit;
1620 smb2_set_related(&rqst[2]);
1621
1622 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1623 resp_buftype, rsp_iov);
1624 if (rc)
1625 goto qfs_exit;
1626
1627 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
6fc05c25 1628 buf->f_type = SMB2_MAGIC_NUMBER;
730928c8
RS
1629 info = (struct smb2_fs_full_size_info *)(
1630 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1631 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1632 le32_to_cpu(rsp->OutputBufferLength),
1633 &rsp_iov[1],
1634 sizeof(struct smb2_fs_full_size_info));
1635 if (!rc)
1636 smb2_copy_fs_info_to_kstatfs(info, buf);
1637
1638qfs_exit:
1639 SMB2_open_free(&rqst[0]);
1640 SMB2_query_info_free(&rqst[1]);
1641 SMB2_close_free(&rqst[2]);
1642 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1643 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1644 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
6fc05c25
PS
1645 return rc;
1646}
1647
2d304217
SF
1648static int
1649smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1650 struct kstatfs *buf)
1651{
1652 int rc;
1653 __le16 srch_path = 0; /* Null - open root of share */
1654 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1655 struct cifs_open_parms oparms;
1656 struct cifs_fid fid;
1657
1658 if (!tcon->posix_extensions)
1659 return smb2_queryfs(xid, tcon, buf);
1660
1661 oparms.tcon = tcon;
1662 oparms.desired_access = FILE_READ_ATTRIBUTES;
1663 oparms.disposition = FILE_OPEN;
1664 oparms.create_options = 0;
1665 oparms.fid = &fid;
1666 oparms.reconnect = false;
1667
1668 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
1669 if (rc)
1670 return rc;
1671
1672 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
1673 fid.volatile_fid, buf);
1674 buf->f_type = SMB2_MAGIC_NUMBER;
1675 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1676 return rc;
1677}
2d304217 1678
027e8eec
PS
1679static bool
1680smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1681{
1682 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1683 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1684}
1685
f7ba7fe6
PS
1686static int
1687smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1688 __u64 length, __u32 type, int lock, int unlock, bool wait)
1689{
1690 if (unlock && !lock)
1691 type = SMB2_LOCKFLAG_UNLOCK;
1692 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1693 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1694 current->tgid, length, offset, type, wait);
1695}
1696
b8c32dbb
PS
1697static void
1698smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1699{
1700 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1701}
1702
1703static void
1704smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1705{
1706 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1707}
1708
1709static void
1710smb2_new_lease_key(struct cifs_fid *fid)
1711{
fa70b87c 1712 generate_random_uuid(fid->lease_key);
b8c32dbb
PS
1713}
1714
9d49640a
AA
1715static int
1716smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
1717 const char *search_name,
1718 struct dfs_info3_param **target_nodes,
1719 unsigned int *num_of_nodes,
1720 const struct nls_table *nls_codepage, int remap)
1721{
1722 int rc;
1723 __le16 *utf16_path = NULL;
1724 int utf16_path_len = 0;
1725 struct cifs_tcon *tcon;
1726 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
1727 struct get_dfs_referral_rsp *dfs_rsp = NULL;
1728 u32 dfs_req_size = 0, dfs_rsp_size = 0;
1729
1730 cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
1731
1732 /*
63a83b86 1733 * Try to use the IPC tcon, otherwise just use any
9d49640a 1734 */
63a83b86
AA
1735 tcon = ses->tcon_ipc;
1736 if (tcon == NULL) {
1737 spin_lock(&cifs_tcp_ses_lock);
1738 tcon = list_first_entry_or_null(&ses->tcon_list,
1739 struct cifs_tcon,
1740 tcon_list);
1741 if (tcon)
1742 tcon->tc_count++;
1743 spin_unlock(&cifs_tcp_ses_lock);
1744 }
1745
1746 if (tcon == NULL) {
9d49640a
AA
1747 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
1748 ses);
1749 rc = -ENOTCONN;
1750 goto out;
1751 }
1752
1753 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
1754 &utf16_path_len,
1755 nls_codepage, remap);
1756 if (!utf16_path) {
1757 rc = -ENOMEM;
1758 goto out;
1759 }
1760
1761 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
1762 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
1763 if (!dfs_req) {
1764 rc = -ENOMEM;
1765 goto out;
1766 }
1767
1768 /* Highest DFS referral version understood */
1769 dfs_req->MaxReferralLevel = DFS_VERSION;
1770
1771 /* Path to resolve in an UTF-16 null-terminated string */
1772 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
1773
1774 do {
9d49640a
AA
1775 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
1776 FSCTL_DFS_GET_REFERRALS,
63a83b86 1777 true /* is_fsctl */,
9d49640a
AA
1778 (char *)dfs_req, dfs_req_size,
1779 (char **)&dfs_rsp, &dfs_rsp_size);
9d49640a
AA
1780 } while (rc == -EAGAIN);
1781
1782 if (rc) {
2564f2ff 1783 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
5702591f 1784 cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
9d49640a
AA
1785 goto out;
1786 }
1787
1788 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
1789 num_of_nodes, target_nodes,
1790 nls_codepage, remap, search_name,
1791 true /* is_unicode */);
1792 if (rc) {
1793 cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
1794 goto out;
1795 }
1796
1797 out:
63a83b86
AA
1798 if (tcon && !tcon->ipc) {
1799 /* ipc tcons are not refcounted */
9d49640a
AA
1800 spin_lock(&cifs_tcp_ses_lock);
1801 tcon->tc_count--;
1802 spin_unlock(&cifs_tcp_ses_lock);
1803 }
1804 kfree(utf16_path);
1805 kfree(dfs_req);
1806 kfree(dfs_rsp);
1807 return rc;
1808}
7893242e
PS
1809#define SMB2_SYMLINK_STRUCT_SIZE \
1810 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1811
b42bf888
PS
1812static int
1813smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1814 const char *full_path, char **target_path,
1815 struct cifs_sb_info *cifs_sb)
1816{
1817 int rc;
1818 __le16 *utf16_path;
1819 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1820 struct cifs_open_parms oparms;
1821 struct cifs_fid fid;
91cb74f5 1822 struct kvec err_iov = {NULL, 0};
9d874c36
RS
1823 struct smb2_err_rsp *err_buf = NULL;
1824 int resp_buftype;
b42bf888 1825 struct smb2_symlink_err_rsp *symlink;
7893242e
PS
1826 unsigned int sub_len;
1827 unsigned int sub_offset;
1828 unsigned int print_len;
1829 unsigned int print_offset;
b42bf888
PS
1830
1831 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1832
1833 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1834 if (!utf16_path)
1835 return -ENOMEM;
1836
1837 oparms.tcon = tcon;
1838 oparms.desired_access = FILE_READ_ATTRIBUTES;
1839 oparms.disposition = FILE_OPEN;
1840 oparms.create_options = 0;
1841 oparms.fid = &fid;
1842 oparms.reconnect = false;
1843
9d874c36
RS
1844 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_iov,
1845 &resp_buftype);
0d568cd3 1846 if (!rc || !err_iov.iov_base) {
9d874c36 1847 rc = -ENOENT;
ff361fda 1848 goto free_path;
b42bf888 1849 }
7893242e 1850
91cb74f5 1851 err_buf = err_iov.iov_base;
7893242e 1852 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1fc6ad2f 1853 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
9d874c36
RS
1854 rc = -ENOENT;
1855 goto querty_exit;
7893242e
PS
1856 }
1857
b42bf888
PS
1858 /* open must fail on symlink - reset rc */
1859 rc = 0;
1860 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1861 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1862 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
7893242e
PS
1863 print_len = le16_to_cpu(symlink->PrintNameLength);
1864 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1865
1fc6ad2f 1866 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
9d874c36
RS
1867 rc = -ENOENT;
1868 goto querty_exit;
7893242e
PS
1869 }
1870
1fc6ad2f
RS
1871 if (err_iov.iov_len <
1872 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
9d874c36
RS
1873 rc = -ENOENT;
1874 goto querty_exit;
7893242e
PS
1875 }
1876
b42bf888
PS
1877 *target_path = cifs_strndup_from_utf16(
1878 (char *)symlink->PathBuffer + sub_offset,
1879 sub_len, true, cifs_sb->local_nls);
1880 if (!(*target_path)) {
9d874c36
RS
1881 rc = -ENOMEM;
1882 goto querty_exit;
b42bf888
PS
1883 }
1884 convert_delimiter(*target_path, '/');
1885 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
9d874c36
RS
1886
1887 querty_exit:
1888 free_rsp_buf(resp_buftype, err_buf);
ff361fda 1889 free_path:
b42bf888
PS
1890 kfree(utf16_path);
1891 return rc;
1892}
1893
84908426 1894#ifdef CONFIG_CIFS_ACL
2f1afe25
SP
1895static struct cifs_ntsd *
1896get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
1897 const struct cifs_fid *cifsfid, u32 *pacllen)
1898{
1899 struct cifs_ntsd *pntsd = NULL;
1900 unsigned int xid;
1901 int rc = -EOPNOTSUPP;
1902 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1903
1904 if (IS_ERR(tlink))
1905 return ERR_CAST(tlink);
1906
1907 xid = get_xid();
1908 cifs_dbg(FYI, "trying to get acl\n");
1909
1910 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
1911 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
1912 free_xid(xid);
1913
1914 cifs_put_tlink(tlink);
1915
1916 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1917 if (rc)
1918 return ERR_PTR(rc);
1919 return pntsd;
1920
1921}
1922
1923static struct cifs_ntsd *
1924get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
1925 const char *path, u32 *pacllen)
1926{
1927 struct cifs_ntsd *pntsd = NULL;
1928 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1929 unsigned int xid;
1930 int rc;
1931 struct cifs_tcon *tcon;
1932 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1933 struct cifs_fid fid;
1934 struct cifs_open_parms oparms;
1935 __le16 *utf16_path;
1936
1937 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
1938 if (IS_ERR(tlink))
1939 return ERR_CAST(tlink);
1940
1941 tcon = tlink_tcon(tlink);
1942 xid = get_xid();
1943
1944 if (backup_cred(cifs_sb))
709340a0 1945 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2f1afe25
SP
1946 else
1947 oparms.create_options = 0;
1948
1949 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
cfe89091
SF
1950 if (!utf16_path) {
1951 rc = -ENOMEM;
1952 free_xid(xid);
1953 return ERR_PTR(rc);
1954 }
2f1afe25
SP
1955
1956 oparms.tcon = tcon;
1957 oparms.desired_access = READ_CONTROL;
1958 oparms.disposition = FILE_OPEN;
1959 oparms.fid = &fid;
1960 oparms.reconnect = false;
1961
9d874c36 1962 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2f1afe25
SP
1963 kfree(utf16_path);
1964 if (!rc) {
1965 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
1966 fid.volatile_fid, (void **)&pntsd, pacllen);
1967 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1968 }
1969
1970 cifs_put_tlink(tlink);
1971 free_xid(xid);
1972
1973 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1974 if (rc)
1975 return ERR_PTR(rc);
1976 return pntsd;
1977}
1978
366ed846
SP
1979#ifdef CONFIG_CIFS_ACL
1980static int
1981set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
1982 struct inode *inode, const char *path, int aclflag)
1983{
1984 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1985 unsigned int xid;
1986 int rc, access_flags = 0;
1987 struct cifs_tcon *tcon;
1988 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1989 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1990 struct cifs_fid fid;
1991 struct cifs_open_parms oparms;
1992 __le16 *utf16_path;
1993
1994 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
1995 if (IS_ERR(tlink))
1996 return PTR_ERR(tlink);
1997
1998 tcon = tlink_tcon(tlink);
1999 xid = get_xid();
2000
2001 if (backup_cred(cifs_sb))
2002 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2003 else
2004 oparms.create_options = 0;
2005
2006 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
2007 access_flags = WRITE_OWNER;
2008 else
2009 access_flags = WRITE_DAC;
2010
2011 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
cfe89091
SF
2012 if (!utf16_path) {
2013 rc = -ENOMEM;
2014 free_xid(xid);
2015 return rc;
2016 }
366ed846
SP
2017
2018 oparms.tcon = tcon;
2019 oparms.desired_access = access_flags;
2020 oparms.disposition = FILE_OPEN;
2021 oparms.path = path;
2022 oparms.fid = &fid;
2023 oparms.reconnect = false;
2024
9d874c36 2025 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
366ed846
SP
2026 kfree(utf16_path);
2027 if (!rc) {
2028 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2029 fid.volatile_fid, pnntsd, acllen, aclflag);
2030 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2031 }
2032
2033 cifs_put_tlink(tlink);
2034 free_xid(xid);
2035 return rc;
2036}
2037#endif /* CIFS_ACL */
2038
2f1afe25
SP
2039/* Retrieve an ACL from the server */
2040static struct cifs_ntsd *
2041get_smb2_acl(struct cifs_sb_info *cifs_sb,
2042 struct inode *inode, const char *path,
2043 u32 *pacllen)
2044{
2045 struct cifs_ntsd *pntsd = NULL;
2046 struct cifsFileInfo *open_file = NULL;
2047
2048 if (inode)
2049 open_file = find_readable_file(CIFS_I(inode), true);
2050 if (!open_file)
2051 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
2052
2053 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
2054 cifsFileInfo_put(open_file);
2055 return pntsd;
2056}
84908426 2057#endif
2f1afe25 2058
30175628
SF
2059static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
2060 loff_t offset, loff_t len, bool keep_size)
2061{
2062 struct inode *inode;
2063 struct cifsInodeInfo *cifsi;
2064 struct cifsFileInfo *cfile = file->private_data;
2065 struct file_zero_data_information fsctl_buf;
2066 long rc;
2067 unsigned int xid;
2068
2069 xid = get_xid();
2070
2b0143b5 2071 inode = d_inode(cfile->dentry);
30175628
SF
2072 cifsi = CIFS_I(inode);
2073
2074 /* if file not oplocked can't be sure whether asking to extend size */
2075 if (!CIFS_CACHE_READ(cifsi))
cfe89091
SF
2076 if (keep_size == false) {
2077 rc = -EOPNOTSUPP;
2078 free_xid(xid);
2079 return rc;
2080 }
30175628 2081
2bb93d24 2082 /*
30175628
SF
2083 * Must check if file sparse since fallocate -z (zero range) assumes
2084 * non-sparse allocation
2085 */
cfe89091
SF
2086 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
2087 rc = -EOPNOTSUPP;
2088 free_xid(xid);
2089 return rc;
2090 }
30175628
SF
2091
2092 /*
2093 * need to make sure we are not asked to extend the file since the SMB3
2094 * fsctl does not change the file size. In the future we could change
2095 * this to zero the first part of the range then set the file size
2096 * which for a non sparse file would zero the newly extended range
2097 */
2098 if (keep_size == false)
cfe89091
SF
2099 if (i_size_read(inode) < offset + len) {
2100 rc = -EOPNOTSUPP;
2101 free_xid(xid);
2102 return rc;
2103 }
30175628
SF
2104
2105 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2106
2107 fsctl_buf.FileOffset = cpu_to_le64(offset);
2108 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2109
2110 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2111 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
63a83b86 2112 true /* is_fctl */, (char *)&fsctl_buf,
30175628
SF
2113 sizeof(struct file_zero_data_information), NULL, NULL);
2114 free_xid(xid);
2115 return rc;
2116}
2117
31742c5a
SF
2118static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
2119 loff_t offset, loff_t len)
2120{
2121 struct inode *inode;
2122 struct cifsInodeInfo *cifsi;
2123 struct cifsFileInfo *cfile = file->private_data;
2124 struct file_zero_data_information fsctl_buf;
2125 long rc;
2126 unsigned int xid;
2127 __u8 set_sparse = 1;
2128
2129 xid = get_xid();
2130
2b0143b5 2131 inode = d_inode(cfile->dentry);
31742c5a
SF
2132 cifsi = CIFS_I(inode);
2133
2134 /* Need to make file sparse, if not already, before freeing range. */
2135 /* Consider adding equivalent for compressed since it could also work */
cfe89091
SF
2136 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
2137 rc = -EOPNOTSUPP;
2138 free_xid(xid);
2139 return rc;
2140 }
31742c5a
SF
2141
2142 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2143
2144 fsctl_buf.FileOffset = cpu_to_le64(offset);
2145 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2146
2147 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2148 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
63a83b86 2149 true /* is_fctl */, (char *)&fsctl_buf,
31742c5a
SF
2150 sizeof(struct file_zero_data_information), NULL, NULL);
2151 free_xid(xid);
2152 return rc;
2153}
2154
9ccf3216
SF
2155static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
2156 loff_t off, loff_t len, bool keep_size)
2157{
2158 struct inode *inode;
2159 struct cifsInodeInfo *cifsi;
2160 struct cifsFileInfo *cfile = file->private_data;
2161 long rc = -EOPNOTSUPP;
2162 unsigned int xid;
2163
2164 xid = get_xid();
2165
2b0143b5 2166 inode = d_inode(cfile->dentry);
9ccf3216
SF
2167 cifsi = CIFS_I(inode);
2168
2169 /* if file not oplocked can't be sure whether asking to extend size */
2170 if (!CIFS_CACHE_READ(cifsi))
cfe89091
SF
2171 if (keep_size == false) {
2172 free_xid(xid);
2173 return rc;
2174 }
9ccf3216
SF
2175
2176 /*
2177 * Files are non-sparse by default so falloc may be a no-op
2178 * Must check if file sparse. If not sparse, and not extending
2179 * then no need to do anything since file already allocated
2180 */
2181 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
2182 if (keep_size == true)
cfe89091 2183 rc = 0;
9ccf3216
SF
2184 /* check if extending file */
2185 else if (i_size_read(inode) >= off + len)
2186 /* not extending file and already not sparse */
cfe89091 2187 rc = 0;
9ccf3216
SF
2188 /* BB: in future add else clause to extend file */
2189 else
cfe89091
SF
2190 rc = -EOPNOTSUPP;
2191 free_xid(xid);
2192 return rc;
9ccf3216
SF
2193 }
2194
2195 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
2196 /*
2197 * Check if falloc starts within first few pages of file
2198 * and ends within a few pages of the end of file to
2199 * ensure that most of file is being forced to be
2200 * fallocated now. If so then setting whole file sparse
2201 * ie potentially making a few extra pages at the beginning
2202 * or end of the file non-sparse via set_sparse is harmless.
2203 */
cfe89091
SF
2204 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
2205 rc = -EOPNOTSUPP;
2206 free_xid(xid);
2207 return rc;
2208 }
9ccf3216
SF
2209
2210 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
2211 }
2212 /* BB: else ... in future add code to extend file and set sparse */
2213
2214
2215 free_xid(xid);
2216 return rc;
2217}
2218
2219
31742c5a
SF
2220static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
2221 loff_t off, loff_t len)
2222{
2223 /* KEEP_SIZE already checked for by do_fallocate */
2224 if (mode & FALLOC_FL_PUNCH_HOLE)
2225 return smb3_punch_hole(file, tcon, off, len);
30175628
SF
2226 else if (mode & FALLOC_FL_ZERO_RANGE) {
2227 if (mode & FALLOC_FL_KEEP_SIZE)
2228 return smb3_zero_range(file, tcon, off, len, true);
2229 return smb3_zero_range(file, tcon, off, len, false);
9ccf3216
SF
2230 } else if (mode == FALLOC_FL_KEEP_SIZE)
2231 return smb3_simple_falloc(file, tcon, off, len, true);
2232 else if (mode == 0)
2233 return smb3_simple_falloc(file, tcon, off, len, false);
31742c5a
SF
2234
2235 return -EOPNOTSUPP;
2236}
2237
c11f1df5
SP
2238static void
2239smb2_downgrade_oplock(struct TCP_Server_Info *server,
2240 struct cifsInodeInfo *cinode, bool set_level2)
2241{
2242 if (set_level2)
2243 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
2244 0, NULL);
2245 else
2246 server->ops->set_oplock_level(cinode, 0, 0, NULL);
2247}
2248
53ef1016 2249static void
42873b0a
PS
2250smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2251 unsigned int epoch, bool *purge_cache)
53ef1016
PS
2252{
2253 oplock &= 0xFF;
2254 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2255 return;
2256 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
42873b0a 2257 cinode->oplock = CIFS_CACHE_RHW_FLG;
53ef1016
PS
2258 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
2259 &cinode->vfs_inode);
2260 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
42873b0a 2261 cinode->oplock = CIFS_CACHE_RW_FLG;
53ef1016
PS
2262 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
2263 &cinode->vfs_inode);
2264 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
2265 cinode->oplock = CIFS_CACHE_READ_FLG;
2266 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
2267 &cinode->vfs_inode);
2268 } else
2269 cinode->oplock = 0;
2270}
2271
2272static void
42873b0a
PS
2273smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2274 unsigned int epoch, bool *purge_cache)
53ef1016
PS
2275{
2276 char message[5] = {0};
2277
2278 oplock &= 0xFF;
2279 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2280 return;
2281
2282 cinode->oplock = 0;
2283 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
2284 cinode->oplock |= CIFS_CACHE_READ_FLG;
2285 strcat(message, "R");
2286 }
2287 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
2288 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
2289 strcat(message, "H");
2290 }
2291 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
2292 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
2293 strcat(message, "W");
2294 }
2295 if (!cinode->oplock)
2296 strcat(message, "None");
2297 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
2298 &cinode->vfs_inode);
2299}
2300
42873b0a
PS
2301static void
2302smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2303 unsigned int epoch, bool *purge_cache)
2304{
2305 unsigned int old_oplock = cinode->oplock;
2306
2307 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
2308
2309 if (purge_cache) {
2310 *purge_cache = false;
2311 if (old_oplock == CIFS_CACHE_READ_FLG) {
2312 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
2313 (epoch - cinode->epoch > 0))
2314 *purge_cache = true;
2315 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2316 (epoch - cinode->epoch > 1))
2317 *purge_cache = true;
2318 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2319 (epoch - cinode->epoch > 1))
2320 *purge_cache = true;
2321 else if (cinode->oplock == 0 &&
2322 (epoch - cinode->epoch > 0))
2323 *purge_cache = true;
2324 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
2325 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2326 (epoch - cinode->epoch > 0))
2327 *purge_cache = true;
2328 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2329 (epoch - cinode->epoch > 1))
2330 *purge_cache = true;
2331 }
2332 cinode->epoch = epoch;
2333 }
2334}
2335
53ef1016
PS
2336static bool
2337smb2_is_read_op(__u32 oplock)
2338{
2339 return oplock == SMB2_OPLOCK_LEVEL_II;
2340}
2341
2342static bool
2343smb21_is_read_op(__u32 oplock)
2344{
2345 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
2346 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
2347}
2348
f047390a
PS
2349static __le32
2350map_oplock_to_lease(u8 oplock)
2351{
2352 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
2353 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
2354 else if (oplock == SMB2_OPLOCK_LEVEL_II)
2355 return SMB2_LEASE_READ_CACHING;
2356 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
2357 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
2358 SMB2_LEASE_WRITE_CACHING;
2359 return 0;
2360}
2361
a41a28bd
PS
2362static char *
2363smb2_create_lease_buf(u8 *lease_key, u8 oplock)
2364{
2365 struct create_lease *buf;
2366
2367 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
2368 if (!buf)
2369 return NULL;
2370
729c0c9d 2371 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
f047390a 2372 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
a41a28bd
PS
2373
2374 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2375 (struct create_lease, lcontext));
2376 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
2377 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2378 (struct create_lease, Name));
2379 buf->ccontext.NameLength = cpu_to_le16(4);
12197a7f 2380 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
a41a28bd
PS
2381 buf->Name[0] = 'R';
2382 buf->Name[1] = 'q';
2383 buf->Name[2] = 'L';
2384 buf->Name[3] = 's';
2385 return (char *)buf;
2386}
2387
f047390a
PS
2388static char *
2389smb3_create_lease_buf(u8 *lease_key, u8 oplock)
2390{
2391 struct create_lease_v2 *buf;
2392
2393 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
2394 if (!buf)
2395 return NULL;
2396
729c0c9d 2397 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
f047390a
PS
2398 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2399
2400 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2401 (struct create_lease_v2, lcontext));
2402 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
2403 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2404 (struct create_lease_v2, Name));
2405 buf->ccontext.NameLength = cpu_to_le16(4);
12197a7f 2406 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
f047390a
PS
2407 buf->Name[0] = 'R';
2408 buf->Name[1] = 'q';
2409 buf->Name[2] = 'L';
2410 buf->Name[3] = 's';
2411 return (char *)buf;
2412}
2413
b5c7cde3 2414static __u8
96164ab2 2415smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
b5c7cde3
PS
2416{
2417 struct create_lease *lc = (struct create_lease *)buf;
2418
42873b0a 2419 *epoch = 0; /* not used */
b5c7cde3
PS
2420 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2421 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2422 return le32_to_cpu(lc->lcontext.LeaseState);
2423}
2424
f047390a 2425static __u8
96164ab2 2426smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
f047390a
PS
2427{
2428 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
2429
42873b0a 2430 *epoch = le16_to_cpu(lc->lcontext.Epoch);
f047390a
PS
2431 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2432 return SMB2_OPLOCK_LEVEL_NOCHANGE;
96164ab2 2433 if (lease_key)
729c0c9d 2434 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
f047390a
PS
2435 return le32_to_cpu(lc->lcontext.LeaseState);
2436}
2437
7f6c5008
PS
2438static unsigned int
2439smb2_wp_retry_size(struct inode *inode)
2440{
2441 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
2442 SMB2_MAX_BUFFER_SIZE);
2443}
2444
52755808
PS
2445static bool
2446smb2_dir_needs_close(struct cifsFileInfo *cfile)
2447{
2448 return !cfile->invalidHandle;
2449}
2450
026e93dc 2451static void
977b6170
RS
2452fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
2453 struct smb_rqst *old_rq)
026e93dc
PS
2454{
2455 struct smb2_sync_hdr *shdr =
c713c877 2456 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
026e93dc
PS
2457
2458 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
2459 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
2460 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
2461 tr_hdr->Flags = cpu_to_le16(0x01);
2462 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2463 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
026e93dc
PS
2464}
2465
262916bc
RS
2466/* We can not use the normal sg_set_buf() as we will sometimes pass a
2467 * stack object as buf.
2468 */
2469static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
2470 unsigned int buflen)
2471{
2472 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
2473}
2474
b2c96de7
RS
2475/* Assumes the first rqst has a transform header as the first iov.
2476 * I.e.
2477 * rqst[0].rq_iov[0] is transform header
2478 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
2479 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
977b6170 2480 */
026e93dc 2481static struct scatterlist *
b2c96de7 2482init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
026e93dc 2483{
b2c96de7 2484 unsigned int sg_len;
026e93dc
PS
2485 struct scatterlist *sg;
2486 unsigned int i;
2487 unsigned int j;
b2c96de7
RS
2488 unsigned int idx = 0;
2489 int skip;
2490
2491 sg_len = 1;
2492 for (i = 0; i < num_rqst; i++)
2493 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
026e93dc
PS
2494
2495 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
2496 if (!sg)
2497 return NULL;
2498
2499 sg_init_table(sg, sg_len);
b2c96de7
RS
2500 for (i = 0; i < num_rqst; i++) {
2501 for (j = 0; j < rqst[i].rq_nvec; j++) {
2502 /*
2503 * The first rqst has a transform header where the
2504 * first 20 bytes are not part of the encrypted blob
2505 */
2506 skip = (i == 0) && (j == 0) ? 20 : 0;
2507 smb2_sg_set_buf(&sg[idx++],
2508 rqst[i].rq_iov[j].iov_base + skip,
2509 rqst[i].rq_iov[j].iov_len - skip);
2510 }
2511
2512 for (j = 0; j < rqst[i].rq_npages; j++) {
2513 unsigned int len, offset;
d5f07fb3 2514
b2c96de7
RS
2515 rqst_page_get_length(&rqst[i], j, &len, &offset);
2516 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
2517 }
026e93dc 2518 }
b2c96de7 2519 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
026e93dc
PS
2520 return sg;
2521}
2522
61cfac6f
PS
2523static int
2524smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
2525{
2526 struct cifs_ses *ses;
2527 u8 *ses_enc_key;
2528
2529 spin_lock(&cifs_tcp_ses_lock);
2530 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2531 if (ses->Suid != ses_id)
2532 continue;
2533 ses_enc_key = enc ? ses->smb3encryptionkey :
2534 ses->smb3decryptionkey;
2535 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
2536 spin_unlock(&cifs_tcp_ses_lock);
2537 return 0;
2538 }
2539 spin_unlock(&cifs_tcp_ses_lock);
2540
2541 return 1;
2542}
026e93dc 2543/*
c713c877
RS
2544 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
2545 * iov[0] - transform header (associate data),
2546 * iov[1-N] - SMB2 header and pages - data to encrypt.
2547 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
026e93dc
PS
2548 * untouched.
2549 */
2550static int
b2c96de7
RS
2551crypt_message(struct TCP_Server_Info *server, int num_rqst,
2552 struct smb_rqst *rqst, int enc)
026e93dc
PS
2553{
2554 struct smb2_transform_hdr *tr_hdr =
b2c96de7 2555 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
1fc6ad2f 2556 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
026e93dc
PS
2557 int rc = 0;
2558 struct scatterlist *sg;
2559 u8 sign[SMB2_SIGNATURE_SIZE] = {};
61cfac6f 2560 u8 key[SMB3_SIGN_KEY_SIZE];
026e93dc
PS
2561 struct aead_request *req;
2562 char *iv;
2563 unsigned int iv_len;
a5186b85 2564 DECLARE_CRYPTO_WAIT(wait);
026e93dc
PS
2565 struct crypto_aead *tfm;
2566 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2567
61cfac6f
PS
2568 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
2569 if (rc) {
2570 cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
2571 enc ? "en" : "de");
026e93dc
PS
2572 return 0;
2573 }
2574
2575 rc = smb3_crypto_aead_allocate(server);
2576 if (rc) {
2577 cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
2578 return rc;
2579 }
2580
2581 tfm = enc ? server->secmech.ccmaesencrypt :
2582 server->secmech.ccmaesdecrypt;
61cfac6f 2583 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
026e93dc
PS
2584 if (rc) {
2585 cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
2586 return rc;
2587 }
2588
2589 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
2590 if (rc) {
2591 cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
2592 return rc;
2593 }
2594
2595 req = aead_request_alloc(tfm, GFP_KERNEL);
2596 if (!req) {
2597 cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
2598 return -ENOMEM;
2599 }
2600
2601 if (!enc) {
2602 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
2603 crypt_len += SMB2_SIGNATURE_SIZE;
2604 }
2605
b2c96de7 2606 sg = init_sg(num_rqst, rqst, sign);
026e93dc 2607 if (!sg) {
517a6e43
CJ
2608 cifs_dbg(VFS, "%s: Failed to init sg", __func__);
2609 rc = -ENOMEM;
026e93dc
PS
2610 goto free_req;
2611 }
2612
2613 iv_len = crypto_aead_ivsize(tfm);
2614 iv = kzalloc(iv_len, GFP_KERNEL);
2615 if (!iv) {
2616 cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
517a6e43 2617 rc = -ENOMEM;
026e93dc
PS
2618 goto free_sg;
2619 }
2620 iv[0] = 3;
2621 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2622
2623 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
2624 aead_request_set_ad(req, assoc_data_len);
2625
2626 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
a5186b85 2627 crypto_req_done, &wait);
026e93dc 2628
a5186b85
GBY
2629 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
2630 : crypto_aead_decrypt(req), &wait);
026e93dc
PS
2631
2632 if (!rc && enc)
2633 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
2634
2635 kfree(iv);
2636free_sg:
2637 kfree(sg);
2638free_req:
2639 kfree(req);
2640 return rc;
2641}
2642
b2c96de7
RS
2643void
2644smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
2645{
2646 int i, j;
2647
2648 for (i = 0; i < num_rqst; i++) {
2649 if (rqst[i].rq_pages) {
2650 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
2651 put_page(rqst[i].rq_pages[j]);
2652 kfree(rqst[i].rq_pages);
2653 }
2654 }
2655}
2656
2657/*
2658 * This function will initialize new_rq and encrypt the content.
2659 * The first entry, new_rq[0], only contains a single iov which contains
2660 * a smb2_transform_hdr and is pre-allocated by the caller.
2661 * This function then populates new_rq[1+] with the content from olq_rq[0+].
2662 *
2663 * The end result is an array of smb_rqst structures where the first structure
2664 * only contains a single iov for the transform header which we then can pass
2665 * to crypt_message().
2666 *
2667 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
2668 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
2669 */
026e93dc 2670static int
b2c96de7
RS
2671smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
2672 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
026e93dc 2673{
026e93dc 2674 struct page **pages;
b2c96de7
RS
2675 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
2676 unsigned int npages;
2677 unsigned int orig_len = 0;
2678 int i, j;
026e93dc
PS
2679 int rc = -ENOMEM;
2680
b2c96de7
RS
2681 for (i = 1; i < num_rqst; i++) {
2682 npages = old_rq[i - 1].rq_npages;
2683 pages = kmalloc_array(npages, sizeof(struct page *),
2684 GFP_KERNEL);
2685 if (!pages)
2686 goto err_free;
2687
2688 new_rq[i].rq_pages = pages;
2689 new_rq[i].rq_npages = npages;
2690 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
2691 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
2692 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
2693 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
2694 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
2695
2696 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
2697
2698 for (j = 0; j < npages; j++) {
2699 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2700 if (!pages[j])
2701 goto err_free;
2702 }
026e93dc 2703
b2c96de7
RS
2704 /* copy pages form the old */
2705 for (j = 0; j < npages; j++) {
2706 char *dst, *src;
2707 unsigned int offset, len;
977b6170 2708
b2c96de7 2709 rqst_page_get_length(&new_rq[i], j, &len, &offset);
026e93dc 2710
b2c96de7
RS
2711 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
2712 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
026e93dc 2713
b2c96de7
RS
2714 memcpy(dst, src, len);
2715 kunmap(new_rq[i].rq_pages[j]);
2716 kunmap(old_rq[i - 1].rq_pages[j]);
2717 }
2718 }
35e2cc1b 2719
b2c96de7 2720 /* fill the 1st iov with a transform header */
977b6170 2721 fill_transform_hdr(tr_hdr, orig_len, old_rq);
d5f07fb3 2722
b2c96de7 2723 rc = crypt_message(server, num_rqst, new_rq, 1);
026e93dc
PS
2724 cifs_dbg(FYI, "encrypt message returned %d", rc);
2725 if (rc)
b2c96de7 2726 goto err_free;
026e93dc
PS
2727
2728 return rc;
2729
b2c96de7
RS
2730err_free:
2731 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
026e93dc
PS
2732 return rc;
2733}
2734
4326ed2f
PS
2735static int
2736smb3_is_transform_hdr(void *buf)
2737{
2738 struct smb2_transform_hdr *trhdr = buf;
2739
2740 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
2741}
2742
2743static int
2744decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
2745 unsigned int buf_data_size, struct page **pages,
2746 unsigned int npages, unsigned int page_data_size)
2747{
c713c877 2748 struct kvec iov[2];
4326ed2f 2749 struct smb_rqst rqst = {NULL};
4326ed2f
PS
2750 int rc;
2751
c713c877
RS
2752 iov[0].iov_base = buf;
2753 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2754 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
2755 iov[1].iov_len = buf_data_size;
4326ed2f
PS
2756
2757 rqst.rq_iov = iov;
c713c877 2758 rqst.rq_nvec = 2;
4326ed2f
PS
2759 rqst.rq_pages = pages;
2760 rqst.rq_npages = npages;
2761 rqst.rq_pagesz = PAGE_SIZE;
2762 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
2763
b2c96de7 2764 rc = crypt_message(server, 1, &rqst, 0);
4326ed2f
PS
2765 cifs_dbg(FYI, "decrypt message returned %d\n", rc);
2766
2767 if (rc)
2768 return rc;
2769
c713c877 2770 memmove(buf, iov[1].iov_base, buf_data_size);
977b6170
RS
2771
2772 server->total_read = buf_data_size + page_data_size;
4326ed2f
PS
2773
2774 return rc;
2775}
2776
c42a6abe
PS
2777static int
2778read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
2779 unsigned int npages, unsigned int len)
2780{
2781 int i;
2782 int length;
2783
2784 for (i = 0; i < npages; i++) {
2785 struct page *page = pages[i];
2786 size_t n;
2787
2788 n = len;
2789 if (len >= PAGE_SIZE) {
2790 /* enough data to fill the page */
2791 n = PAGE_SIZE;
2792 len -= n;
2793 } else {
2794 zero_user(page, len, PAGE_SIZE - len);
2795 len = 0;
2796 }
1dbe3466 2797 length = cifs_read_page_from_socket(server, page, 0, n);
c42a6abe
PS
2798 if (length < 0)
2799 return length;
2800 server->total_read += length;
2801 }
2802
2803 return 0;
2804}
2805
2806static int
2807init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
2808 unsigned int cur_off, struct bio_vec **page_vec)
2809{
2810 struct bio_vec *bvec;
2811 int i;
2812
2813 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
2814 if (!bvec)
2815 return -ENOMEM;
2816
2817 for (i = 0; i < npages; i++) {
2818 bvec[i].bv_page = pages[i];
2819 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
2820 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
2821 data_size -= bvec[i].bv_len;
2822 }
2823
2824 if (data_size != 0) {
2825 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
2826 kfree(bvec);
2827 return -EIO;
2828 }
2829
2830 *page_vec = bvec;
2831 return 0;
2832}
2833
4326ed2f
PS
2834static int
2835handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
2836 char *buf, unsigned int buf_len, struct page **pages,
2837 unsigned int npages, unsigned int page_data_size)
2838{
2839 unsigned int data_offset;
2840 unsigned int data_len;
c42a6abe
PS
2841 unsigned int cur_off;
2842 unsigned int cur_page_idx;
2843 unsigned int pad_len;
4326ed2f 2844 struct cifs_readdata *rdata = mid->callback_data;
49f466bd 2845 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
4326ed2f
PS
2846 struct bio_vec *bvec = NULL;
2847 struct iov_iter iter;
2848 struct kvec iov;
2849 int length;
74dcf418 2850 bool use_rdma_mr = false;
4326ed2f
PS
2851
2852 if (shdr->Command != SMB2_READ) {
2853 cifs_dbg(VFS, "only big read responses are supported\n");
2854 return -ENOTSUPP;
2855 }
2856
511c54a2
PS
2857 if (server->ops->is_session_expired &&
2858 server->ops->is_session_expired(buf)) {
2859 cifs_reconnect(server);
2860 wake_up(&server->response_q);
2861 return -1;
2862 }
2863
4326ed2f
PS
2864 if (server->ops->is_status_pending &&
2865 server->ops->is_status_pending(buf, server, 0))
2866 return -1;
2867
2868 rdata->result = server->ops->map_error(buf, false);
2869 if (rdata->result != 0) {
2870 cifs_dbg(FYI, "%s: server returned error %d\n",
2871 __func__, rdata->result);
2872 dequeue_mid(mid, rdata->result);
2873 return 0;
2874 }
2875
1fc6ad2f 2876 data_offset = server->ops->read_data_offset(buf);
74dcf418
LL
2877#ifdef CONFIG_CIFS_SMB_DIRECT
2878 use_rdma_mr = rdata->mr;
2879#endif
2880 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4326ed2f
PS
2881
2882 if (data_offset < server->vals->read_rsp_size) {
2883 /*
2884 * win2k8 sometimes sends an offset of 0 when the read
2885 * is beyond the EOF. Treat it as if the data starts just after
2886 * the header.
2887 */
2888 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
2889 __func__, data_offset);
2890 data_offset = server->vals->read_rsp_size;
2891 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
2892 /* data_offset is beyond the end of smallbuf */
2893 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
2894 __func__, data_offset);
2895 rdata->result = -EIO;
2896 dequeue_mid(mid, rdata->result);
2897 return 0;
2898 }
2899
c42a6abe
PS
2900 pad_len = data_offset - server->vals->read_rsp_size;
2901
4326ed2f
PS
2902 if (buf_len <= data_offset) {
2903 /* read response payload is in pages */
c42a6abe
PS
2904 cur_page_idx = pad_len / PAGE_SIZE;
2905 cur_off = pad_len % PAGE_SIZE;
2906
2907 if (cur_page_idx != 0) {
2908 /* data offset is beyond the 1st page of response */
2909 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
2910 __func__, data_offset);
2911 rdata->result = -EIO;
2912 dequeue_mid(mid, rdata->result);
2913 return 0;
2914 }
2915
2916 if (data_len > page_data_size - pad_len) {
2917 /* data_len is corrupt -- discard frame */
2918 rdata->result = -EIO;
2919 dequeue_mid(mid, rdata->result);
2920 return 0;
2921 }
2922
2923 rdata->result = init_read_bvec(pages, npages, page_data_size,
2924 cur_off, &bvec);
2925 if (rdata->result != 0) {
2926 dequeue_mid(mid, rdata->result);
2927 return 0;
2928 }
2929
2930 iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len);
4326ed2f
PS
2931 } else if (buf_len >= data_offset + data_len) {
2932 /* read response payload is in buf */
2933 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
2934 iov.iov_base = buf + data_offset;
2935 iov.iov_len = data_len;
2936 iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len);
2937 } else {
2938 /* read response payload cannot be in both buf and pages */
2939 WARN_ONCE(1, "buf can not contain only a part of read data");
2940 rdata->result = -EIO;
2941 dequeue_mid(mid, rdata->result);
2942 return 0;
2943 }
2944
2945 /* set up first iov for signature check */
2946 rdata->iov[0].iov_base = buf;
2947 rdata->iov[0].iov_len = 4;
2948 rdata->iov[1].iov_base = buf + 4;
2949 rdata->iov[1].iov_len = server->vals->read_rsp_size - 4;
2950 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
2951 rdata->iov[0].iov_base, server->vals->read_rsp_size);
2952
2953 length = rdata->copy_into_pages(server, rdata, &iter);
2954
2955 kfree(bvec);
2956
2957 if (length < 0)
2958 return length;
2959
2960 dequeue_mid(mid, false);
2961 return length;
2962}
2963
c42a6abe
PS
2964static int
2965receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2966{
2967 char *buf = server->smallbuf;
2968 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2969 unsigned int npages;
2970 struct page **pages;
2971 unsigned int len;
1fc6ad2f 2972 unsigned int buflen = server->pdu_size;
c42a6abe
PS
2973 int rc;
2974 int i = 0;
2975
1fc6ad2f 2976 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
c42a6abe
PS
2977 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
2978
2979 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
2980 if (rc < 0)
2981 return rc;
2982 server->total_read += rc;
2983
1fc6ad2f 2984 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
93012bf9 2985 server->vals->read_rsp_size;
c42a6abe
PS
2986 npages = DIV_ROUND_UP(len, PAGE_SIZE);
2987
2988 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
2989 if (!pages) {
2990 rc = -ENOMEM;
2991 goto discard_data;
2992 }
2993
2994 for (; i < npages; i++) {
2995 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2996 if (!pages[i]) {
2997 rc = -ENOMEM;
2998 goto discard_data;
2999 }
3000 }
3001
3002 /* read read data into pages */
3003 rc = read_data_into_pages(server, pages, npages, len);
3004 if (rc)
3005 goto free_pages;
3006
350be257 3007 rc = cifs_discard_remaining_data(server);
c42a6abe
PS
3008 if (rc)
3009 goto free_pages;
3010
1fc6ad2f 3011 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
c42a6abe
PS
3012 pages, npages, len);
3013 if (rc)
3014 goto free_pages;
3015
3016 *mid = smb2_find_mid(server, buf);
3017 if (*mid == NULL)
3018 cifs_dbg(FYI, "mid not found\n");
3019 else {
3020 cifs_dbg(FYI, "mid found\n");
3021 (*mid)->decrypted = true;
3022 rc = handle_read_data(server, *mid, buf,
3023 server->vals->read_rsp_size,
3024 pages, npages, len);
3025 }
3026
3027free_pages:
3028 for (i = i - 1; i >= 0; i--)
3029 put_page(pages[i]);
3030 kfree(pages);
3031 return rc;
3032discard_data:
350be257 3033 cifs_discard_remaining_data(server);
c42a6abe
PS
3034 goto free_pages;
3035}
3036
4326ed2f
PS
3037static int
3038receive_encrypted_standard(struct TCP_Server_Info *server,
b24df3e3
RS
3039 struct mid_q_entry **mids, char **bufs,
3040 int *num_mids)
4326ed2f 3041{
b24df3e3 3042 int ret, length;
4326ed2f 3043 char *buf = server->smallbuf;
b24df3e3
RS
3044 char *tmpbuf;
3045 struct smb2_sync_hdr *shdr;
2e96467d 3046 unsigned int pdu_length = server->pdu_size;
4326ed2f
PS
3047 unsigned int buf_size;
3048 struct mid_q_entry *mid_entry;
b24df3e3
RS
3049 int next_is_large;
3050 char *next_buffer = NULL;
3051
3052 *num_mids = 0;
4326ed2f
PS
3053
3054 /* switch to large buffer if too big for a small one */
1fc6ad2f 3055 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4326ed2f
PS
3056 server->large_buf = true;
3057 memcpy(server->bigbuf, buf, server->total_read);
3058 buf = server->bigbuf;
3059 }
3060
3061 /* now read the rest */
3062 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
1fc6ad2f 3063 pdu_length - HEADER_SIZE(server) + 1);
4326ed2f
PS
3064 if (length < 0)
3065 return length;
3066 server->total_read += length;
3067
1fc6ad2f 3068 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4326ed2f
PS
3069 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
3070 if (length)
3071 return length;
3072
b24df3e3
RS
3073 next_is_large = server->large_buf;
3074 one_more:
3075 shdr = (struct smb2_sync_hdr *)buf;
3076 if (shdr->NextCommand) {
3077 if (next_is_large) {
3078 tmpbuf = server->bigbuf;
3079 next_buffer = (char *)cifs_buf_get();
3080 } else {
3081 tmpbuf = server->smallbuf;
3082 next_buffer = (char *)cifs_small_buf_get();
3083 }
3084 memcpy(next_buffer,
3085 tmpbuf + le32_to_cpu(shdr->NextCommand),
3086 pdu_length - le32_to_cpu(shdr->NextCommand));
3087 }
3088
4326ed2f
PS
3089 mid_entry = smb2_find_mid(server, buf);
3090 if (mid_entry == NULL)
3091 cifs_dbg(FYI, "mid not found\n");
3092 else {
3093 cifs_dbg(FYI, "mid found\n");
3094 mid_entry->decrypted = true;
b24df3e3 3095 mid_entry->resp_buf_size = server->pdu_size;
4326ed2f
PS
3096 }
3097
b24df3e3
RS
3098 if (*num_mids >= MAX_COMPOUND) {
3099 cifs_dbg(VFS, "too many PDUs in compound\n");
3100 return -1;
3101 }
3102 bufs[*num_mids] = buf;
3103 mids[(*num_mids)++] = mid_entry;
4326ed2f
PS
3104
3105 if (mid_entry && mid_entry->handle)
b24df3e3
RS
3106 ret = mid_entry->handle(server, mid_entry);
3107 else
3108 ret = cifs_handle_standard(server, mid_entry);
3109
3110 if (ret == 0 && shdr->NextCommand) {
3111 pdu_length -= le32_to_cpu(shdr->NextCommand);
3112 server->large_buf = next_is_large;
3113 if (next_is_large)
3114 server->bigbuf = next_buffer;
3115 else
3116 server->smallbuf = next_buffer;
3117
3118 buf += le32_to_cpu(shdr->NextCommand);
3119 goto one_more;
3120 }
4326ed2f 3121
b24df3e3 3122 return ret;
4326ed2f
PS
3123}
3124
3125static int
b24df3e3
RS
3126smb3_receive_transform(struct TCP_Server_Info *server,
3127 struct mid_q_entry **mids, char **bufs, int *num_mids)
4326ed2f
PS
3128{
3129 char *buf = server->smallbuf;
2e96467d 3130 unsigned int pdu_length = server->pdu_size;
4326ed2f
PS
3131 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
3132 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
3133
1fc6ad2f 3134 if (pdu_length < sizeof(struct smb2_transform_hdr) +
4326ed2f
PS
3135 sizeof(struct smb2_sync_hdr)) {
3136 cifs_dbg(VFS, "Transform message is too small (%u)\n",
3137 pdu_length);
3138 cifs_reconnect(server);
3139 wake_up(&server->response_q);
3140 return -ECONNABORTED;
3141 }
3142
1fc6ad2f 3143 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
4326ed2f
PS
3144 cifs_dbg(VFS, "Transform message is broken\n");
3145 cifs_reconnect(server);
3146 wake_up(&server->response_q);
3147 return -ECONNABORTED;
3148 }
3149
b24df3e3 3150 /* TODO: add support for compounds containing READ. */
1fc6ad2f 3151 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server))
b24df3e3 3152 return receive_encrypted_read(server, &mids[0]);
4326ed2f 3153
b24df3e3 3154 return receive_encrypted_standard(server, mids, bufs, num_mids);
4326ed2f
PS
3155}
3156
3157int
3158smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
3159{
3160 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
3161
1fc6ad2f 3162 return handle_read_data(server, mid, buf, server->pdu_size,
4326ed2f
PS
3163 NULL, 0, 0);
3164}
3165
8ce79ec3
RS
3166static int
3167smb2_next_header(char *buf)
3168{
3169 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
3170 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
3171
3172 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
3173 return sizeof(struct smb2_transform_hdr) +
3174 le32_to_cpu(t_hdr->OriginalMessageSize);
3175
3176 return le32_to_cpu(hdr->NextCommand);
3177}
3178
53ef1016 3179struct smb_version_operations smb20_operations = {
027e8eec 3180 .compare_fids = smb2_compare_fids,
2dc7e1c0 3181 .setup_request = smb2_setup_request,
c95b8eed 3182 .setup_async_request = smb2_setup_async_request,
2dc7e1c0 3183 .check_receive = smb2_check_receive,
28ea5290
PS
3184 .add_credits = smb2_add_credits,
3185 .set_credits = smb2_set_credits,
3186 .get_credits_field = smb2_get_credits_field,
3187 .get_credits = smb2_get_credits,
cb7e9eab 3188 .wait_mtu_credits = cifs_wait_mtu_credits,
2dc7e1c0 3189 .get_next_mid = smb2_get_next_mid,
09a4707e
PS
3190 .read_data_offset = smb2_read_data_offset,
3191 .read_data_length = smb2_read_data_length,
3192 .map_error = map_smb2_to_linux_error,
093b2bda
PS
3193 .find_mid = smb2_find_mid,
3194 .check_message = smb2_check_message,
3195 .dump_detail = smb2_dump_detail,
d60622eb
PS
3196 .clear_stats = smb2_clear_stats,
3197 .print_stats = smb2_print_stats,
983c88a4 3198 .is_oplock_break = smb2_is_valid_oplock_break,
38bd4906 3199 .handle_cancelled_mid = smb2_handle_cancelled_mid,
c11f1df5 3200 .downgrade_oplock = smb2_downgrade_oplock,
ec2e4523
PS
3201 .need_neg = smb2_need_neg,
3202 .negotiate = smb2_negotiate,
3a3bab50
PS
3203 .negotiate_wsize = smb2_negotiate_wsize,
3204 .negotiate_rsize = smb2_negotiate_rsize,
5478f9ba
PS
3205 .sess_setup = SMB2_sess_setup,
3206 .logoff = SMB2_logoff,
faaf946a
PS
3207 .tree_connect = SMB2_tcon,
3208 .tree_disconnect = SMB2_tdis,
34f62640 3209 .qfs_tcon = smb2_qfs_tcon,
2503a0db 3210 .is_path_accessible = smb2_is_path_accessible,
9094fad1
PS
3211 .can_echo = smb2_can_echo,
3212 .echo = SMB2_echo,
be4cb9e3
PS
3213 .query_path_info = smb2_query_path_info,
3214 .get_srv_inum = smb2_get_srv_inum,
b7546bc5 3215 .query_file_info = smb2_query_file_info,
c839ff24
PS
3216 .set_path_size = smb2_set_path_size,
3217 .set_file_size = smb2_set_file_size,
1feeaac7 3218 .set_file_info = smb2_set_file_info,
64a5cfa6 3219 .set_compression = smb2_set_compression,
a0e73183
PS
3220 .mkdir = smb2_mkdir,
3221 .mkdir_setinfo = smb2_mkdir_setinfo,
1a500f01 3222 .rmdir = smb2_rmdir,
cbe6f439 3223 .unlink = smb2_unlink,
35143eb5 3224 .rename = smb2_rename_path,
568798cc 3225 .create_hardlink = smb2_create_hardlink,
b42bf888 3226 .query_symlink = smb2_query_symlink,
5b23c97d
SP
3227 .query_mf_symlink = smb3_query_mf_symlink,
3228 .create_mf_symlink = smb3_create_mf_symlink,
f0df737e
PS
3229 .open = smb2_open_file,
3230 .set_fid = smb2_set_fid,
3231 .close = smb2_close_file,
7a5cfb19 3232 .flush = smb2_flush_file,
09a4707e 3233 .async_readv = smb2_async_readv,
33319141 3234 .async_writev = smb2_async_writev,
d8e05039 3235 .sync_read = smb2_sync_read,
009d3443 3236 .sync_write = smb2_sync_write,
d324f08d
PS
3237 .query_dir_first = smb2_query_dir_first,
3238 .query_dir_next = smb2_query_dir_next,
3239 .close_dir = smb2_close_dir,
3240 .calc_smb_size = smb2_calc_size,
2e44b288 3241 .is_status_pending = smb2_is_status_pending,
511c54a2 3242 .is_session_expired = smb2_is_session_expired,
983c88a4 3243 .oplock_response = smb2_oplock_response,
6fc05c25 3244 .queryfs = smb2_queryfs,
f7ba7fe6
PS
3245 .mand_lock = smb2_mand_lock,
3246 .mand_unlock_range = smb2_unlock_range,
b140799a 3247 .push_mand_locks = smb2_push_mandatory_locks,
b8c32dbb
PS
3248 .get_lease_key = smb2_get_lease_key,
3249 .set_lease_key = smb2_set_lease_key,
3250 .new_lease_key = smb2_new_lease_key,
38107d45 3251 .calc_signature = smb2_calc_signature,
53ef1016
PS
3252 .is_read_op = smb2_is_read_op,
3253 .set_oplock_level = smb2_set_oplock_level,
a41a28bd 3254 .create_lease_buf = smb2_create_lease_buf,
b5c7cde3 3255 .parse_lease_buf = smb2_parse_lease_buf,
312bbc59 3256 .copychunk_range = smb2_copychunk_range,
7f6c5008 3257 .wp_retry_size = smb2_wp_retry_size,
52755808 3258 .dir_needs_close = smb2_dir_needs_close,
9d49640a 3259 .get_dfs_refer = smb2_get_dfs_refer,
ef65aaed 3260 .select_sectype = smb2_select_sectype,
95907fea
RS
3261#ifdef CONFIG_CIFS_XATTR
3262 .query_all_EAs = smb2_query_eas,
5517554e 3263 .set_EA = smb2_set_ea,
95907fea 3264#endif /* CIFS_XATTR */
2f1afe25
SP
3265#ifdef CONFIG_CIFS_ACL
3266 .get_acl = get_smb2_acl,
3267 .get_acl_by_fid = get_smb2_acl_by_fid,
366ed846 3268 .set_acl = set_smb2_acl,
2f1afe25 3269#endif /* CIFS_ACL */
8ce79ec3 3270 .next_header = smb2_next_header,
38107d45
SF
3271};
3272
53ef1016
PS
3273struct smb_version_operations smb21_operations = {
3274 .compare_fids = smb2_compare_fids,
3275 .setup_request = smb2_setup_request,
3276 .setup_async_request = smb2_setup_async_request,
3277 .check_receive = smb2_check_receive,
3278 .add_credits = smb2_add_credits,
3279 .set_credits = smb2_set_credits,
3280 .get_credits_field = smb2_get_credits_field,
3281 .get_credits = smb2_get_credits,
cb7e9eab 3282 .wait_mtu_credits = smb2_wait_mtu_credits,
53ef1016
PS
3283 .get_next_mid = smb2_get_next_mid,
3284 .read_data_offset = smb2_read_data_offset,
3285 .read_data_length = smb2_read_data_length,
3286 .map_error = map_smb2_to_linux_error,
3287 .find_mid = smb2_find_mid,
3288 .check_message = smb2_check_message,
3289 .dump_detail = smb2_dump_detail,
3290 .clear_stats = smb2_clear_stats,
3291 .print_stats = smb2_print_stats,
3292 .is_oplock_break = smb2_is_valid_oplock_break,
38bd4906 3293 .handle_cancelled_mid = smb2_handle_cancelled_mid,
c11f1df5 3294 .downgrade_oplock = smb2_downgrade_oplock,
53ef1016
PS
3295 .need_neg = smb2_need_neg,
3296 .negotiate = smb2_negotiate,
3297 .negotiate_wsize = smb2_negotiate_wsize,
3298 .negotiate_rsize = smb2_negotiate_rsize,
3299 .sess_setup = SMB2_sess_setup,
3300 .logoff = SMB2_logoff,
3301 .tree_connect = SMB2_tcon,
3302 .tree_disconnect = SMB2_tdis,
34f62640 3303 .qfs_tcon = smb2_qfs_tcon,
53ef1016
PS
3304 .is_path_accessible = smb2_is_path_accessible,
3305 .can_echo = smb2_can_echo,
3306 .echo = SMB2_echo,
3307 .query_path_info = smb2_query_path_info,
3308 .get_srv_inum = smb2_get_srv_inum,
3309 .query_file_info = smb2_query_file_info,
3310 .set_path_size = smb2_set_path_size,
3311 .set_file_size = smb2_set_file_size,
3312 .set_file_info = smb2_set_file_info,
64a5cfa6 3313 .set_compression = smb2_set_compression,
53ef1016
PS
3314 .mkdir = smb2_mkdir,
3315 .mkdir_setinfo = smb2_mkdir_setinfo,
3316 .rmdir = smb2_rmdir,
3317 .unlink = smb2_unlink,
3318 .rename = smb2_rename_path,
3319 .create_hardlink = smb2_create_hardlink,
3320 .query_symlink = smb2_query_symlink,
c22870ea 3321 .query_mf_symlink = smb3_query_mf_symlink,
5ab97578 3322 .create_mf_symlink = smb3_create_mf_symlink,
53ef1016
PS
3323 .open = smb2_open_file,
3324 .set_fid = smb2_set_fid,
3325 .close = smb2_close_file,
3326 .flush = smb2_flush_file,
3327 .async_readv = smb2_async_readv,
3328 .async_writev = smb2_async_writev,
3329 .sync_read = smb2_sync_read,
3330 .sync_write = smb2_sync_write,
3331 .query_dir_first = smb2_query_dir_first,
3332 .query_dir_next = smb2_query_dir_next,
3333 .close_dir = smb2_close_dir,
3334 .calc_smb_size = smb2_calc_size,
3335 .is_status_pending = smb2_is_status_pending,
511c54a2 3336 .is_session_expired = smb2_is_session_expired,
53ef1016
PS
3337 .oplock_response = smb2_oplock_response,
3338 .queryfs = smb2_queryfs,
3339 .mand_lock = smb2_mand_lock,
3340 .mand_unlock_range = smb2_unlock_range,
3341 .push_mand_locks = smb2_push_mandatory_locks,
3342 .get_lease_key = smb2_get_lease_key,
3343 .set_lease_key = smb2_set_lease_key,
3344 .new_lease_key = smb2_new_lease_key,
3345 .calc_signature = smb2_calc_signature,
3346 .is_read_op = smb21_is_read_op,
3347 .set_oplock_level = smb21_set_oplock_level,
a41a28bd 3348 .create_lease_buf = smb2_create_lease_buf,
b5c7cde3 3349 .parse_lease_buf = smb2_parse_lease_buf,
312bbc59 3350 .copychunk_range = smb2_copychunk_range,
7f6c5008 3351 .wp_retry_size = smb2_wp_retry_size,
52755808 3352 .dir_needs_close = smb2_dir_needs_close,
834170c8 3353 .enum_snapshots = smb3_enum_snapshots,
9d49640a 3354 .get_dfs_refer = smb2_get_dfs_refer,
ef65aaed 3355 .select_sectype = smb2_select_sectype,
95907fea
RS
3356#ifdef CONFIG_CIFS_XATTR
3357 .query_all_EAs = smb2_query_eas,
5517554e 3358 .set_EA = smb2_set_ea,
95907fea 3359#endif /* CIFS_XATTR */
2f1afe25
SP
3360#ifdef CONFIG_CIFS_ACL
3361 .get_acl = get_smb2_acl,
3362 .get_acl_by_fid = get_smb2_acl_by_fid,
366ed846 3363 .set_acl = set_smb2_acl,
2f1afe25 3364#endif /* CIFS_ACL */
8ce79ec3 3365 .next_header = smb2_next_header,
53ef1016 3366};
38107d45
SF
3367
3368struct smb_version_operations smb30_operations = {
3369 .compare_fids = smb2_compare_fids,
3370 .setup_request = smb2_setup_request,
3371 .setup_async_request = smb2_setup_async_request,
3372 .check_receive = smb2_check_receive,
3373 .add_credits = smb2_add_credits,
3374 .set_credits = smb2_set_credits,
3375 .get_credits_field = smb2_get_credits_field,
3376 .get_credits = smb2_get_credits,
cb7e9eab 3377 .wait_mtu_credits = smb2_wait_mtu_credits,
38107d45
SF
3378 .get_next_mid = smb2_get_next_mid,
3379 .read_data_offset = smb2_read_data_offset,
3380 .read_data_length = smb2_read_data_length,
3381 .map_error = map_smb2_to_linux_error,
3382 .find_mid = smb2_find_mid,
3383 .check_message = smb2_check_message,
3384 .dump_detail = smb2_dump_detail,
3385 .clear_stats = smb2_clear_stats,
3386 .print_stats = smb2_print_stats,
769ee6a4 3387 .dump_share_caps = smb2_dump_share_caps,
38107d45 3388 .is_oplock_break = smb2_is_valid_oplock_break,
38bd4906 3389 .handle_cancelled_mid = smb2_handle_cancelled_mid,
c11f1df5 3390 .downgrade_oplock = smb2_downgrade_oplock,
38107d45
SF
3391 .need_neg = smb2_need_neg,
3392 .negotiate = smb2_negotiate,
3393 .negotiate_wsize = smb2_negotiate_wsize,
3394 .negotiate_rsize = smb2_negotiate_rsize,
3395 .sess_setup = SMB2_sess_setup,
3396 .logoff = SMB2_logoff,
3397 .tree_connect = SMB2_tcon,
3398 .tree_disconnect = SMB2_tdis,
af6a12ea 3399 .qfs_tcon = smb3_qfs_tcon,
38107d45
SF
3400 .is_path_accessible = smb2_is_path_accessible,
3401 .can_echo = smb2_can_echo,
3402 .echo = SMB2_echo,
3403 .query_path_info = smb2_query_path_info,
3404 .get_srv_inum = smb2_get_srv_inum,
3405 .query_file_info = smb2_query_file_info,
3406 .set_path_size = smb2_set_path_size,
3407 .set_file_size = smb2_set_file_size,
3408 .set_file_info = smb2_set_file_info,
64a5cfa6 3409 .set_compression = smb2_set_compression,
38107d45
SF
3410 .mkdir = smb2_mkdir,
3411 .mkdir_setinfo = smb2_mkdir_setinfo,
3412 .rmdir = smb2_rmdir,
3413 .unlink = smb2_unlink,
3414 .rename = smb2_rename_path,
3415 .create_hardlink = smb2_create_hardlink,
b42bf888 3416 .query_symlink = smb2_query_symlink,
c22870ea 3417 .query_mf_symlink = smb3_query_mf_symlink,
5ab97578 3418 .create_mf_symlink = smb3_create_mf_symlink,
38107d45
SF
3419 .open = smb2_open_file,
3420 .set_fid = smb2_set_fid,
3421 .close = smb2_close_file,
3422 .flush = smb2_flush_file,
3423 .async_readv = smb2_async_readv,
3424 .async_writev = smb2_async_writev,
3425 .sync_read = smb2_sync_read,
3426 .sync_write = smb2_sync_write,
3427 .query_dir_first = smb2_query_dir_first,
3428 .query_dir_next = smb2_query_dir_next,
3429 .close_dir = smb2_close_dir,
3430 .calc_smb_size = smb2_calc_size,
3431 .is_status_pending = smb2_is_status_pending,
511c54a2 3432 .is_session_expired = smb2_is_session_expired,
38107d45
SF
3433 .oplock_response = smb2_oplock_response,
3434 .queryfs = smb2_queryfs,
3435 .mand_lock = smb2_mand_lock,
3436 .mand_unlock_range = smb2_unlock_range,
3437 .push_mand_locks = smb2_push_mandatory_locks,
3438 .get_lease_key = smb2_get_lease_key,
3439 .set_lease_key = smb2_set_lease_key,
3440 .new_lease_key = smb2_new_lease_key,
373512ec 3441 .generate_signingkey = generate_smb30signingkey,
38107d45 3442 .calc_signature = smb3_calc_signature,
b3152e2c 3443 .set_integrity = smb3_set_integrity,
53ef1016 3444 .is_read_op = smb21_is_read_op,
42873b0a 3445 .set_oplock_level = smb3_set_oplock_level,
f047390a
PS
3446 .create_lease_buf = smb3_create_lease_buf,
3447 .parse_lease_buf = smb3_parse_lease_buf,
312bbc59 3448 .copychunk_range = smb2_copychunk_range,
ca9e7a1c 3449 .duplicate_extents = smb2_duplicate_extents,
ff1c038a 3450 .validate_negotiate = smb3_validate_negotiate,
7f6c5008 3451 .wp_retry_size = smb2_wp_retry_size,
52755808 3452 .dir_needs_close = smb2_dir_needs_close,
31742c5a 3453 .fallocate = smb3_fallocate,
834170c8 3454 .enum_snapshots = smb3_enum_snapshots,
026e93dc 3455 .init_transform_rq = smb3_init_transform_rq,
4326ed2f
PS
3456 .is_transform_hdr = smb3_is_transform_hdr,
3457 .receive_transform = smb3_receive_transform,
9d49640a 3458 .get_dfs_refer = smb2_get_dfs_refer,
ef65aaed 3459 .select_sectype = smb2_select_sectype,
95907fea
RS
3460#ifdef CONFIG_CIFS_XATTR
3461 .query_all_EAs = smb2_query_eas,
5517554e 3462 .set_EA = smb2_set_ea,
95907fea 3463#endif /* CIFS_XATTR */
2f1afe25
SP
3464#ifdef CONFIG_CIFS_ACL
3465 .get_acl = get_smb2_acl,
3466 .get_acl_by_fid = get_smb2_acl_by_fid,
366ed846 3467 .set_acl = set_smb2_acl,
2f1afe25 3468#endif /* CIFS_ACL */
8ce79ec3 3469 .next_header = smb2_next_header,
1080ef75
SF
3470};
3471
aab1893d
SF
3472struct smb_version_operations smb311_operations = {
3473 .compare_fids = smb2_compare_fids,
3474 .setup_request = smb2_setup_request,
3475 .setup_async_request = smb2_setup_async_request,
3476 .check_receive = smb2_check_receive,
3477 .add_credits = smb2_add_credits,
3478 .set_credits = smb2_set_credits,
3479 .get_credits_field = smb2_get_credits_field,
3480 .get_credits = smb2_get_credits,
3481 .wait_mtu_credits = smb2_wait_mtu_credits,
3482 .get_next_mid = smb2_get_next_mid,
3483 .read_data_offset = smb2_read_data_offset,
3484 .read_data_length = smb2_read_data_length,
3485 .map_error = map_smb2_to_linux_error,
3486 .find_mid = smb2_find_mid,
3487 .check_message = smb2_check_message,
3488 .dump_detail = smb2_dump_detail,
3489 .clear_stats = smb2_clear_stats,
3490 .print_stats = smb2_print_stats,
3491 .dump_share_caps = smb2_dump_share_caps,
3492 .is_oplock_break = smb2_is_valid_oplock_break,
38bd4906 3493 .handle_cancelled_mid = smb2_handle_cancelled_mid,
aab1893d
SF
3494 .downgrade_oplock = smb2_downgrade_oplock,
3495 .need_neg = smb2_need_neg,
3496 .negotiate = smb2_negotiate,
3497 .negotiate_wsize = smb2_negotiate_wsize,
3498 .negotiate_rsize = smb2_negotiate_rsize,
3499 .sess_setup = SMB2_sess_setup,
3500 .logoff = SMB2_logoff,
3501 .tree_connect = SMB2_tcon,
3502 .tree_disconnect = SMB2_tdis,
3503 .qfs_tcon = smb3_qfs_tcon,
3504 .is_path_accessible = smb2_is_path_accessible,
3505 .can_echo = smb2_can_echo,
3506 .echo = SMB2_echo,
3507 .query_path_info = smb2_query_path_info,
3508 .get_srv_inum = smb2_get_srv_inum,
3509 .query_file_info = smb2_query_file_info,
3510 .set_path_size = smb2_set_path_size,
3511 .set_file_size = smb2_set_file_size,
3512 .set_file_info = smb2_set_file_info,
3513 .set_compression = smb2_set_compression,
3514 .mkdir = smb2_mkdir,
3515 .mkdir_setinfo = smb2_mkdir_setinfo,
bea851b8 3516 .posix_mkdir = smb311_posix_mkdir,
aab1893d
SF
3517 .rmdir = smb2_rmdir,
3518 .unlink = smb2_unlink,
3519 .rename = smb2_rename_path,
3520 .create_hardlink = smb2_create_hardlink,
3521 .query_symlink = smb2_query_symlink,
3522 .query_mf_symlink = smb3_query_mf_symlink,
3523 .create_mf_symlink = smb3_create_mf_symlink,
3524 .open = smb2_open_file,
3525 .set_fid = smb2_set_fid,
3526 .close = smb2_close_file,
3527 .flush = smb2_flush_file,
3528 .async_readv = smb2_async_readv,
3529 .async_writev = smb2_async_writev,
3530 .sync_read = smb2_sync_read,
3531 .sync_write = smb2_sync_write,
3532 .query_dir_first = smb2_query_dir_first,
3533 .query_dir_next = smb2_query_dir_next,
3534 .close_dir = smb2_close_dir,
3535 .calc_smb_size = smb2_calc_size,
3536 .is_status_pending = smb2_is_status_pending,
511c54a2 3537 .is_session_expired = smb2_is_session_expired,
aab1893d 3538 .oplock_response = smb2_oplock_response,
2d304217 3539 .queryfs = smb311_queryfs,
aab1893d
SF
3540 .mand_lock = smb2_mand_lock,
3541 .mand_unlock_range = smb2_unlock_range,
3542 .push_mand_locks = smb2_push_mandatory_locks,
3543 .get_lease_key = smb2_get_lease_key,
3544 .set_lease_key = smb2_set_lease_key,
3545 .new_lease_key = smb2_new_lease_key,
373512ec 3546 .generate_signingkey = generate_smb311signingkey,
aab1893d 3547 .calc_signature = smb3_calc_signature,
b3152e2c 3548 .set_integrity = smb3_set_integrity,
aab1893d
SF
3549 .is_read_op = smb21_is_read_op,
3550 .set_oplock_level = smb3_set_oplock_level,
3551 .create_lease_buf = smb3_create_lease_buf,
3552 .parse_lease_buf = smb3_parse_lease_buf,
312bbc59 3553 .copychunk_range = smb2_copychunk_range,
02b16665 3554 .duplicate_extents = smb2_duplicate_extents,
aab1893d
SF
3555/* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3556 .wp_retry_size = smb2_wp_retry_size,
3557 .dir_needs_close = smb2_dir_needs_close,
3558 .fallocate = smb3_fallocate,
834170c8 3559 .enum_snapshots = smb3_enum_snapshots,
026e93dc 3560 .init_transform_rq = smb3_init_transform_rq,
4326ed2f
PS
3561 .is_transform_hdr = smb3_is_transform_hdr,
3562 .receive_transform = smb3_receive_transform,
9d49640a 3563 .get_dfs_refer = smb2_get_dfs_refer,
ef65aaed 3564 .select_sectype = smb2_select_sectype,
95907fea
RS
3565#ifdef CONFIG_CIFS_XATTR
3566 .query_all_EAs = smb2_query_eas,
5517554e 3567 .set_EA = smb2_set_ea,
95907fea 3568#endif /* CIFS_XATTR */
8ce79ec3 3569 .next_header = smb2_next_header,
aab1893d 3570};
aab1893d 3571
dd446b16
SF
3572struct smb_version_values smb20_values = {
3573 .version_string = SMB20_VERSION_STRING,
3574 .protocol_id = SMB20_PROT_ID,
3575 .req_capabilities = 0, /* MBZ */
3576 .large_lock_type = 0,
3577 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3578 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3579 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
977b6170
RS
3580 .header_size = sizeof(struct smb2_sync_hdr),
3581 .header_preamble_size = 0,
dd446b16
SF
3582 .max_header_size = MAX_SMB2_HDR_SIZE,
3583 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3584 .lock_cmd = SMB2_LOCK,
3585 .cap_unix = 0,
3586 .cap_nt_find = SMB2_NT_FIND,
3587 .cap_large_files = SMB2_LARGE_FILES,
50285882
JL
3588 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3589 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
a41a28bd 3590 .create_lease_size = sizeof(struct create_lease),
dd446b16
SF
3591};
3592
1080ef75
SF
3593struct smb_version_values smb21_values = {
3594 .version_string = SMB21_VERSION_STRING,
e4aa25e7
SF
3595 .protocol_id = SMB21_PROT_ID,
3596 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
3597 .large_lock_type = 0,
3598 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3599 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3600 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
977b6170
RS
3601 .header_size = sizeof(struct smb2_sync_hdr),
3602 .header_preamble_size = 0,
e4aa25e7
SF
3603 .max_header_size = MAX_SMB2_HDR_SIZE,
3604 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3605 .lock_cmd = SMB2_LOCK,
3606 .cap_unix = 0,
3607 .cap_nt_find = SMB2_NT_FIND,
3608 .cap_large_files = SMB2_LARGE_FILES,
50285882
JL
3609 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3610 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
a41a28bd 3611 .create_lease_size = sizeof(struct create_lease),
e4aa25e7
SF
3612};
3613
9764c02f
SF
3614struct smb_version_values smb3any_values = {
3615 .version_string = SMB3ANY_VERSION_STRING,
3616 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3617 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3618 .large_lock_type = 0,
3619 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3620 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3621 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
977b6170
RS
3622 .header_size = sizeof(struct smb2_sync_hdr),
3623 .header_preamble_size = 0,
9764c02f
SF
3624 .max_header_size = MAX_SMB2_HDR_SIZE,
3625 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3626 .lock_cmd = SMB2_LOCK,
3627 .cap_unix = 0,
3628 .cap_nt_find = SMB2_NT_FIND,
3629 .cap_large_files = SMB2_LARGE_FILES,
3630 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3631 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3632 .create_lease_size = sizeof(struct create_lease_v2),
3633};
3634
3635struct smb_version_values smbdefault_values = {
3636 .version_string = SMBDEFAULT_VERSION_STRING,
3637 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3638 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3639 .large_lock_type = 0,
3640 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3641 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3642 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
977b6170
RS
3643 .header_size = sizeof(struct smb2_sync_hdr),
3644 .header_preamble_size = 0,
9764c02f
SF
3645 .max_header_size = MAX_SMB2_HDR_SIZE,
3646 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3647 .lock_cmd = SMB2_LOCK,
3648 .cap_unix = 0,
3649 .cap_nt_find = SMB2_NT_FIND,
3650 .cap_large_files = SMB2_LARGE_FILES,
3651 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3652 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3653 .create_lease_size = sizeof(struct create_lease_v2),
3654};
3655
e4aa25e7
SF
3656struct smb_version_values smb30_values = {
3657 .version_string = SMB30_VERSION_STRING,
3658 .protocol_id = SMB30_PROT_ID,
373512ec 3659 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
027e8eec
PS
3660 .large_lock_type = 0,
3661 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3662 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3663 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
977b6170
RS
3664 .header_size = sizeof(struct smb2_sync_hdr),
3665 .header_preamble_size = 0,
093b2bda 3666 .max_header_size = MAX_SMB2_HDR_SIZE,
09a4707e 3667 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2dc7e1c0 3668 .lock_cmd = SMB2_LOCK,
29e20f9c
PS
3669 .cap_unix = 0,
3670 .cap_nt_find = SMB2_NT_FIND,
3671 .cap_large_files = SMB2_LARGE_FILES,
50285882
JL
3672 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3673 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
f047390a 3674 .create_lease_size = sizeof(struct create_lease_v2),
1080ef75 3675};
20b6d8b4
SF
3676
3677struct smb_version_values smb302_values = {
3678 .version_string = SMB302_VERSION_STRING,
3679 .protocol_id = SMB302_PROT_ID,
373512ec 3680 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
20b6d8b4
SF
3681 .large_lock_type = 0,
3682 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3683 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3684 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
977b6170
RS
3685 .header_size = sizeof(struct smb2_sync_hdr),
3686 .header_preamble_size = 0,
20b6d8b4
SF
3687 .max_header_size = MAX_SMB2_HDR_SIZE,
3688 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3689 .lock_cmd = SMB2_LOCK,
3690 .cap_unix = 0,
3691 .cap_nt_find = SMB2_NT_FIND,
3692 .cap_large_files = SMB2_LARGE_FILES,
50285882
JL
3693 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3694 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
f047390a 3695 .create_lease_size = sizeof(struct create_lease_v2),
20b6d8b4 3696};
5f7fbf73 3697
5f7fbf73
SF
3698struct smb_version_values smb311_values = {
3699 .version_string = SMB311_VERSION_STRING,
3700 .protocol_id = SMB311_PROT_ID,
1955880b 3701 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
5f7fbf73
SF
3702 .large_lock_type = 0,
3703 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3704 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3705 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
977b6170
RS
3706 .header_size = sizeof(struct smb2_sync_hdr),
3707 .header_preamble_size = 0,
5f7fbf73
SF
3708 .max_header_size = MAX_SMB2_HDR_SIZE,
3709 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3710 .lock_cmd = SMB2_LOCK,
3711 .cap_unix = 0,
3712 .cap_nt_find = SMB2_NT_FIND,
3713 .cap_large_files = SMB2_LARGE_FILES,
3714 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3715 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3716 .create_lease_size = sizeof(struct create_lease_v2),
3717};