blob: f1d9c191c4e41b32178aa1bff8d0d5ecf655395b [file] [log] [blame]
Steve French1080ef72011-02-24 18:07:19 +00001/*
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
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -070020#include <linux/pagemap.h>
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -070021#include <linux/vfs.h>
Steve Frenchf29ebb42014-07-19 21:44:58 -050022#include <linux/falloc.h>
Pavel Shilovsky026e93d2016-11-03 16:47:37 -070023#include <linux/scatterlist.h>
Tobias Regnery4fa8e502017-03-30 12:34:14 +020024#include <linux/uuid.h>
Pavel Shilovsky026e93d2016-11-03 16:47:37 -070025#include <crypto/aead.h>
Steve French1080ef72011-02-24 18:07:19 +000026#include "cifsglob.h"
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040027#include "smb2pdu.h"
28#include "smb2proto.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040029#include "cifsproto.h"
30#include "cifs_debug.h"
Pavel Shilovskyb42bf882013-08-14 19:25:21 +040031#include "cifs_unicode.h"
Pavel Shilovsky2e44b282012-09-18 16:20:33 -070032#include "smb2status.h"
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -070033#include "smb2glob.h"
Steve French834170c2016-09-30 21:14:26 -050034#include "cifs_ioctl.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040035
36static int
37change_conf(struct TCP_Server_Info *server)
38{
39 server->credits += server->echo_credits + server->oplock_credits;
40 server->oplock_credits = server->echo_credits = 0;
41 switch (server->credits) {
42 case 0:
43 return -1;
44 case 1:
45 server->echoes = false;
46 server->oplocks = false;
Joe Perchesf96637b2013-05-04 22:12:25 -050047 cifs_dbg(VFS, "disabling echoes and oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040048 break;
49 case 2:
50 server->echoes = true;
51 server->oplocks = false;
52 server->echo_credits = 1;
Joe Perchesf96637b2013-05-04 22:12:25 -050053 cifs_dbg(FYI, "disabling oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040054 break;
55 default:
56 server->echoes = true;
Steve Frenche0ddde92015-09-22 09:29:38 -050057 if (enable_oplocks) {
58 server->oplocks = true;
59 server->oplock_credits = 1;
60 } else
61 server->oplocks = false;
62
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040063 server->echo_credits = 1;
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040064 }
65 server->credits -= server->echo_credits + server->oplock_credits;
66 return 0;
67}
68
69static void
70smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
71 const int optype)
72{
73 int *val, rc = 0;
74 spin_lock(&server->req_lock);
75 val = server->ops->get_credits_field(server, optype);
76 *val += add;
Steve French141891f2016-09-23 00:44:16 -050077 if (*val > 65000) {
78 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
79 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
80 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040081 server->in_flight--;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +040082 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040083 rc = change_conf(server);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -070084 /*
85 * Sometimes server returns 0 credits on oplock break ack - we need to
86 * rebalance credits in this case.
87 */
88 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
89 server->oplocks) {
90 if (server->credits > 1) {
91 server->credits--;
92 server->oplock_credits++;
93 }
94 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040095 spin_unlock(&server->req_lock);
96 wake_up(&server->request_q);
97 if (rc)
98 cifs_reconnect(server);
99}
100
101static void
102smb2_set_credits(struct TCP_Server_Info *server, const int val)
103{
104 spin_lock(&server->req_lock);
105 server->credits = val;
106 spin_unlock(&server->req_lock);
107}
108
109static int *
110smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
111{
112 switch (optype) {
113 case CIFS_ECHO_OP:
114 return &server->echo_credits;
115 case CIFS_OBREAK_OP:
116 return &server->oplock_credits;
117 default:
118 return &server->credits;
119 }
120}
121
122static unsigned int
123smb2_get_credits(struct mid_q_entry *mid)
124{
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700125 struct smb2_sync_hdr *shdr = get_sync_hdr(mid->resp_buf);
126
127 return le16_to_cpu(shdr->CreditRequest);
Pavel Shilovsky28ea5292012-05-23 16:18:00 +0400128}
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400129
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400130static int
131smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
132 unsigned int *num, unsigned int *credits)
133{
134 int rc = 0;
135 unsigned int scredits;
136
137 spin_lock(&server->req_lock);
138 while (1) {
139 if (server->credits <= 0) {
140 spin_unlock(&server->req_lock);
141 cifs_num_waiters_inc(server);
142 rc = wait_event_killable(server->request_q,
143 has_credits(server, &server->credits));
144 cifs_num_waiters_dec(server);
145 if (rc)
146 return rc;
147 spin_lock(&server->req_lock);
148 } else {
149 if (server->tcpStatus == CifsExiting) {
150 spin_unlock(&server->req_lock);
151 return -ENOENT;
152 }
153
154 scredits = server->credits;
155 /* can deadlock with reopen */
156 if (scredits == 1) {
157 *num = SMB2_MAX_BUFFER_SIZE;
158 *credits = 0;
159 break;
160 }
161
162 /* leave one credit for a possible reopen */
163 scredits--;
164 *num = min_t(unsigned int, size,
165 scredits * SMB2_MAX_BUFFER_SIZE);
166
167 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
168 server->credits -= *credits;
169 server->in_flight++;
170 break;
171 }
172 }
173 spin_unlock(&server->req_lock);
174 return rc;
175}
176
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400177static __u64
178smb2_get_next_mid(struct TCP_Server_Info *server)
179{
180 __u64 mid;
181 /* for SMB2 we need the current value */
182 spin_lock(&GlobalMid_Lock);
183 mid = server->CurrentMid++;
184 spin_unlock(&GlobalMid_Lock);
185 return mid;
186}
Steve French1080ef72011-02-24 18:07:19 +0000187
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400188static struct mid_q_entry *
189smb2_find_mid(struct TCP_Server_Info *server, char *buf)
190{
191 struct mid_q_entry *mid;
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700192 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
193 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400194
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700195 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
Steve French373512e2015-12-18 13:05:30 -0600196 cifs_dbg(VFS, "encrypted frame parsing not supported yet");
197 return NULL;
198 }
199
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400200 spin_lock(&GlobalMid_Lock);
201 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
Sachin Prabhu9235d092014-12-09 17:37:00 +0000202 if ((mid->mid == wire_mid) &&
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400203 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700204 (mid->command == shdr->Command)) {
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400205 spin_unlock(&GlobalMid_Lock);
206 return mid;
207 }
208 }
209 spin_unlock(&GlobalMid_Lock);
210 return NULL;
211}
212
213static void
214smb2_dump_detail(void *buf)
215{
216#ifdef CONFIG_CIFS_DEBUG2
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700217 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400218
Joe Perchesf96637b2013-05-04 22:12:25 -0500219 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700220 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
221 shdr->ProcessId);
222 cifs_dbg(VFS, "smb buf %p len %u\n", buf, smb2_calc_size(buf));
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400223#endif
224}
225
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400226static bool
227smb2_need_neg(struct TCP_Server_Info *server)
228{
229 return server->max_read == 0;
230}
231
232static int
233smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
234{
235 int rc;
236 ses->server->CurrentMid = 0;
237 rc = SMB2_negotiate(xid, ses);
238 /* BB we probably don't need to retry with modern servers */
239 if (rc == -EAGAIN)
240 rc = -EHOSTDOWN;
241 return rc;
242}
243
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700244static unsigned int
245smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
246{
247 struct TCP_Server_Info *server = tcon->ses->server;
248 unsigned int wsize;
249
250 /* start with specified wsize, or default */
251 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
252 wsize = min_t(unsigned int, wsize, server->max_write);
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400253
254 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
255 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700256
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700257 return wsize;
258}
259
260static unsigned int
261smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
262{
263 struct TCP_Server_Info *server = tcon->ses->server;
264 unsigned int rsize;
265
266 /* start with specified rsize, or default */
267 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
268 rsize = min_t(unsigned int, rsize, server->max_read);
Pavel Shilovskybed9da02014-06-25 11:28:57 +0400269
270 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
271 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700272
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700273 return rsize;
274}
275
Steve Frenchc481e9f2013-10-14 01:21:53 -0500276#ifdef CONFIG_CIFS_STATS2
277static int
278SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
279{
280 int rc;
281 unsigned int ret_data_len = 0;
282 struct network_interface_info_ioctl_rsp *out_buf;
283
284 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
285 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
Aurelien Aptel51146622017-02-28 15:08:41 +0100286 false /* use_ipc */,
Steve Frenchc481e9f2013-10-14 01:21:53 -0500287 NULL /* no data input */, 0 /* no data input */,
288 (char **)&out_buf, &ret_data_len);
Steve French9ffc5412014-10-16 15:13:14 -0500289 if (rc != 0)
290 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
291 else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
292 cifs_dbg(VFS, "server returned bad net interface info buf\n");
293 rc = -EINVAL;
294 } else {
Steve Frenchc481e9f2013-10-14 01:21:53 -0500295 /* Dump info on first interface */
296 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
297 le32_to_cpu(out_buf->Capability));
298 cifs_dbg(FYI, "Link Speed %lld\n",
299 le64_to_cpu(out_buf->LinkSpeed));
Steve French9ffc5412014-10-16 15:13:14 -0500300 }
Steve French24df1482016-09-29 04:20:23 -0500301 kfree(out_buf);
Steve Frenchc481e9f2013-10-14 01:21:53 -0500302 return rc;
303}
304#endif /* STATS2 */
305
Steve French34f62642013-10-09 02:07:00 -0500306static void
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500307smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
308{
309 int rc;
310 __le16 srch_path = 0; /* Null - open root of share */
311 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
312 struct cifs_open_parms oparms;
313 struct cifs_fid fid;
314
315 oparms.tcon = tcon;
316 oparms.desired_access = FILE_READ_ATTRIBUTES;
317 oparms.disposition = FILE_OPEN;
318 oparms.create_options = 0;
319 oparms.fid = &fid;
320 oparms.reconnect = false;
321
322 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
323 if (rc)
324 return;
325
Steve Frenchc481e9f2013-10-14 01:21:53 -0500326#ifdef CONFIG_CIFS_STATS2
327 SMB3_request_interfaces(xid, tcon);
328#endif /* STATS2 */
329
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500330 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
331 FS_ATTRIBUTE_INFORMATION);
332 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
333 FS_DEVICE_INFORMATION);
334 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
335 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
336 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
337 return;
338}
339
340static void
Steve French34f62642013-10-09 02:07:00 -0500341smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
342{
343 int rc;
344 __le16 srch_path = 0; /* Null - open root of share */
345 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
346 struct cifs_open_parms oparms;
347 struct cifs_fid fid;
348
349 oparms.tcon = tcon;
350 oparms.desired_access = FILE_READ_ATTRIBUTES;
351 oparms.disposition = FILE_OPEN;
352 oparms.create_options = 0;
353 oparms.fid = &fid;
354 oparms.reconnect = false;
355
356 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
357 if (rc)
358 return;
359
Steven French21671142013-10-09 13:36:35 -0500360 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
361 FS_ATTRIBUTE_INFORMATION);
362 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
363 FS_DEVICE_INFORMATION);
Steve French34f62642013-10-09 02:07:00 -0500364 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
365 return;
366}
367
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400368static int
369smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
370 struct cifs_sb_info *cifs_sb, const char *full_path)
371{
372 int rc;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400373 __le16 *utf16_path;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700374 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400375 struct cifs_open_parms oparms;
376 struct cifs_fid fid;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400377
378 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
379 if (!utf16_path)
380 return -ENOMEM;
381
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400382 oparms.tcon = tcon;
383 oparms.desired_access = FILE_READ_ATTRIBUTES;
384 oparms.disposition = FILE_OPEN;
385 oparms.create_options = 0;
386 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400387 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400388
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400389 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400390 if (rc) {
391 kfree(utf16_path);
392 return rc;
393 }
394
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400395 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400396 kfree(utf16_path);
397 return rc;
398}
399
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400400static int
401smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
402 struct cifs_sb_info *cifs_sb, const char *full_path,
403 u64 *uniqueid, FILE_ALL_INFO *data)
404{
405 *uniqueid = le64_to_cpu(data->IndexNumber);
406 return 0;
407}
408
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700409static int
410smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
411 struct cifs_fid *fid, FILE_ALL_INFO *data)
412{
413 int rc;
414 struct smb2_file_all_info *smb2_data;
415
Pavel Shilovsky1bbe4992014-08-22 13:32:11 +0400416 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700417 GFP_KERNEL);
418 if (smb2_data == NULL)
419 return -ENOMEM;
420
421 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
422 smb2_data);
423 if (!rc)
424 move_smb2_info_to_cifs(data, smb2_data);
425 kfree(smb2_data);
426 return rc;
427}
428
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400429static bool
430smb2_can_echo(struct TCP_Server_Info *server)
431{
432 return server->echoes;
433}
434
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400435static void
436smb2_clear_stats(struct cifs_tcon *tcon)
437{
438#ifdef CONFIG_CIFS_STATS
439 int i;
440 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
441 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
442 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
443 }
444#endif
445}
446
447static void
Steve French769ee6a2013-06-19 14:15:30 -0500448smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
449{
450 seq_puts(m, "\n\tShare Capabilities:");
451 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
452 seq_puts(m, " DFS,");
453 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
454 seq_puts(m, " CONTINUOUS AVAILABILITY,");
455 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
456 seq_puts(m, " SCALEOUT,");
457 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
458 seq_puts(m, " CLUSTER,");
459 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
460 seq_puts(m, " ASYMMETRIC,");
461 if (tcon->capabilities == 0)
462 seq_puts(m, " None");
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500463 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
464 seq_puts(m, " Aligned,");
465 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
466 seq_puts(m, " Partition Aligned,");
467 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
468 seq_puts(m, " SSD,");
469 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
470 seq_puts(m, " TRIM-support,");
471
Steve French769ee6a2013-06-19 14:15:30 -0500472 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500473 if (tcon->perf_sector_size)
474 seq_printf(m, "\tOptimal sector size: 0x%x",
475 tcon->perf_sector_size);
Steve French769ee6a2013-06-19 14:15:30 -0500476}
477
478static void
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400479smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
480{
481#ifdef CONFIG_CIFS_STATS
482 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
483 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
484 seq_printf(m, "\nNegotiates: %d sent %d failed",
485 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
486 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
487 seq_printf(m, "\nSessionSetups: %d sent %d failed",
488 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
489 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400490 seq_printf(m, "\nLogoffs: %d sent %d failed",
491 atomic_read(&sent[SMB2_LOGOFF_HE]),
492 atomic_read(&failed[SMB2_LOGOFF_HE]));
493 seq_printf(m, "\nTreeConnects: %d sent %d failed",
494 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
495 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
496 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
497 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
498 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
499 seq_printf(m, "\nCreates: %d sent %d failed",
500 atomic_read(&sent[SMB2_CREATE_HE]),
501 atomic_read(&failed[SMB2_CREATE_HE]));
502 seq_printf(m, "\nCloses: %d sent %d failed",
503 atomic_read(&sent[SMB2_CLOSE_HE]),
504 atomic_read(&failed[SMB2_CLOSE_HE]));
505 seq_printf(m, "\nFlushes: %d sent %d failed",
506 atomic_read(&sent[SMB2_FLUSH_HE]),
507 atomic_read(&failed[SMB2_FLUSH_HE]));
508 seq_printf(m, "\nReads: %d sent %d failed",
509 atomic_read(&sent[SMB2_READ_HE]),
510 atomic_read(&failed[SMB2_READ_HE]));
511 seq_printf(m, "\nWrites: %d sent %d failed",
512 atomic_read(&sent[SMB2_WRITE_HE]),
513 atomic_read(&failed[SMB2_WRITE_HE]));
514 seq_printf(m, "\nLocks: %d sent %d failed",
515 atomic_read(&sent[SMB2_LOCK_HE]),
516 atomic_read(&failed[SMB2_LOCK_HE]));
517 seq_printf(m, "\nIOCTLs: %d sent %d failed",
518 atomic_read(&sent[SMB2_IOCTL_HE]),
519 atomic_read(&failed[SMB2_IOCTL_HE]));
520 seq_printf(m, "\nCancels: %d sent %d failed",
521 atomic_read(&sent[SMB2_CANCEL_HE]),
522 atomic_read(&failed[SMB2_CANCEL_HE]));
523 seq_printf(m, "\nEchos: %d sent %d failed",
524 atomic_read(&sent[SMB2_ECHO_HE]),
525 atomic_read(&failed[SMB2_ECHO_HE]));
526 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
527 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
528 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
529 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
530 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
531 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
532 seq_printf(m, "\nQueryInfos: %d sent %d failed",
533 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
534 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
535 seq_printf(m, "\nSetInfos: %d sent %d failed",
536 atomic_read(&sent[SMB2_SET_INFO_HE]),
537 atomic_read(&failed[SMB2_SET_INFO_HE]));
538 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
539 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
540 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
541#endif
542}
543
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700544static void
545smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
546{
David Howells2b0143b2015-03-17 22:25:59 +0000547 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400548 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
549
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700550 cfile->fid.persistent_fid = fid->persistent_fid;
551 cfile->fid.volatile_fid = fid->volatile_fid;
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400552 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
553 &fid->purge_cache);
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400554 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
Aurelien Aptel94f87372016-09-22 07:38:50 +0200555 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700556}
557
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400558static void
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700559smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
560 struct cifs_fid *fid)
561{
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400562 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700563}
564
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700565static int
Steve French41c13582013-11-14 00:05:36 -0600566SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
567 u64 persistent_fid, u64 volatile_fid,
568 struct copychunk_ioctl *pcchunk)
569{
570 int rc;
571 unsigned int ret_data_len;
572 struct resume_key_req *res_key;
573
574 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
575 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
Aurelien Aptel51146622017-02-28 15:08:41 +0100576 false /* use_ipc */,
Steve French41c13582013-11-14 00:05:36 -0600577 NULL, 0 /* no input */,
578 (char **)&res_key, &ret_data_len);
579
580 if (rc) {
581 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
582 goto req_res_key_exit;
583 }
584 if (ret_data_len < sizeof(struct resume_key_req)) {
585 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
586 rc = -EINVAL;
587 goto req_res_key_exit;
588 }
589 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
590
591req_res_key_exit:
592 kfree(res_key);
593 return rc;
594}
595
Sachin Prabhu620d8742017-02-10 16:03:51 +0530596static ssize_t
Sachin Prabhu312bbc52017-04-04 02:12:04 -0500597smb2_copychunk_range(const unsigned int xid,
Steve French41c13582013-11-14 00:05:36 -0600598 struct cifsFileInfo *srcfile,
599 struct cifsFileInfo *trgtfile, u64 src_off,
600 u64 len, u64 dest_off)
601{
602 int rc;
603 unsigned int ret_data_len;
604 struct copychunk_ioctl *pcchunk;
Steve French9bf0c9c2013-11-16 18:05:28 -0600605 struct copychunk_ioctl_rsp *retbuf = NULL;
606 struct cifs_tcon *tcon;
607 int chunks_copied = 0;
608 bool chunk_sizes_updated = false;
Sachin Prabhu620d8742017-02-10 16:03:51 +0530609 ssize_t bytes_written, total_bytes_written = 0;
Steve French41c13582013-11-14 00:05:36 -0600610
611 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
612
613 if (pcchunk == NULL)
614 return -ENOMEM;
615
Sachin Prabhu312bbc52017-04-04 02:12:04 -0500616 cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
Steve French41c13582013-11-14 00:05:36 -0600617 /* Request a key from the server to identify the source of the copy */
618 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
619 srcfile->fid.persistent_fid,
620 srcfile->fid.volatile_fid, pcchunk);
621
622 /* Note: request_res_key sets res_key null only if rc !=0 */
623 if (rc)
Steve French9bf0c9c2013-11-16 18:05:28 -0600624 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600625
626 /* For now array only one chunk long, will make more flexible later */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800627 pcchunk->ChunkCount = cpu_to_le32(1);
Steve French41c13582013-11-14 00:05:36 -0600628 pcchunk->Reserved = 0;
Steve French41c13582013-11-14 00:05:36 -0600629 pcchunk->Reserved2 = 0;
630
Steve French9bf0c9c2013-11-16 18:05:28 -0600631 tcon = tlink_tcon(trgtfile->tlink);
632
633 while (len > 0) {
634 pcchunk->SourceOffset = cpu_to_le64(src_off);
635 pcchunk->TargetOffset = cpu_to_le64(dest_off);
636 pcchunk->Length =
637 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
638
639 /* Request server copy to target from src identified by key */
640 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
Steve French41c13582013-11-14 00:05:36 -0600641 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
Aurelien Aptel51146622017-02-28 15:08:41 +0100642 true /* is_fsctl */, false /* use_ipc */,
643 (char *)pcchunk,
Steve French9bf0c9c2013-11-16 18:05:28 -0600644 sizeof(struct copychunk_ioctl), (char **)&retbuf,
645 &ret_data_len);
646 if (rc == 0) {
647 if (ret_data_len !=
648 sizeof(struct copychunk_ioctl_rsp)) {
649 cifs_dbg(VFS, "invalid cchunk response size\n");
650 rc = -EIO;
651 goto cchunk_out;
652 }
653 if (retbuf->TotalBytesWritten == 0) {
654 cifs_dbg(FYI, "no bytes copied\n");
655 rc = -EIO;
656 goto cchunk_out;
657 }
658 /*
659 * Check if server claimed to write more than we asked
660 */
661 if (le32_to_cpu(retbuf->TotalBytesWritten) >
662 le32_to_cpu(pcchunk->Length)) {
663 cifs_dbg(VFS, "invalid copy chunk response\n");
664 rc = -EIO;
665 goto cchunk_out;
666 }
667 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
668 cifs_dbg(VFS, "invalid num chunks written\n");
669 rc = -EIO;
670 goto cchunk_out;
671 }
672 chunks_copied++;
Steve French41c13582013-11-14 00:05:36 -0600673
Sachin Prabhu620d8742017-02-10 16:03:51 +0530674 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
675 src_off += bytes_written;
676 dest_off += bytes_written;
677 len -= bytes_written;
678 total_bytes_written += bytes_written;
Steve French41c13582013-11-14 00:05:36 -0600679
Sachin Prabhu620d8742017-02-10 16:03:51 +0530680 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
Steve French9bf0c9c2013-11-16 18:05:28 -0600681 le32_to_cpu(retbuf->ChunksWritten),
682 le32_to_cpu(retbuf->ChunkBytesWritten),
Sachin Prabhu620d8742017-02-10 16:03:51 +0530683 bytes_written);
Steve French9bf0c9c2013-11-16 18:05:28 -0600684 } else if (rc == -EINVAL) {
685 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
686 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600687
Steve French9bf0c9c2013-11-16 18:05:28 -0600688 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
689 le32_to_cpu(retbuf->ChunksWritten),
690 le32_to_cpu(retbuf->ChunkBytesWritten),
691 le32_to_cpu(retbuf->TotalBytesWritten));
692
693 /*
694 * Check if this is the first request using these sizes,
695 * (ie check if copy succeed once with original sizes
696 * and check if the server gave us different sizes after
697 * we already updated max sizes on previous request).
698 * if not then why is the server returning an error now
699 */
700 if ((chunks_copied != 0) || chunk_sizes_updated)
701 goto cchunk_out;
702
703 /* Check that server is not asking us to grow size */
704 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
705 tcon->max_bytes_chunk)
706 tcon->max_bytes_chunk =
707 le32_to_cpu(retbuf->ChunkBytesWritten);
708 else
709 goto cchunk_out; /* server gave us bogus size */
710
711 /* No need to change MaxChunks since already set to 1 */
712 chunk_sizes_updated = true;
Sachin Prabhu2477bc52015-02-04 13:10:26 +0000713 } else
714 goto cchunk_out;
Steve French9bf0c9c2013-11-16 18:05:28 -0600715 }
716
717cchunk_out:
Steve French41c13582013-11-14 00:05:36 -0600718 kfree(pcchunk);
Steve French24df1482016-09-29 04:20:23 -0500719 kfree(retbuf);
Sachin Prabhu620d8742017-02-10 16:03:51 +0530720 if (rc)
721 return rc;
722 else
723 return total_bytes_written;
Steve French41c13582013-11-14 00:05:36 -0600724}
725
726static int
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700727smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
728 struct cifs_fid *fid)
729{
730 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
731}
732
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700733static unsigned int
734smb2_read_data_offset(char *buf)
735{
736 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
737 return rsp->DataOffset;
738}
739
740static unsigned int
741smb2_read_data_length(char *buf)
742{
743 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
744 return le32_to_cpu(rsp->DataLength);
745}
746
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700747
748static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500749smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700750 struct cifs_io_parms *parms, unsigned int *bytes_read,
751 char **buf, int *buf_type)
752{
Steve Frenchdb8b6312014-09-22 05:13:55 -0500753 parms->persistent_fid = pfid->persistent_fid;
754 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700755 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
756}
757
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700758static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500759smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700760 struct cifs_io_parms *parms, unsigned int *written,
761 struct kvec *iov, unsigned long nr_segs)
762{
763
Steve Frenchdb8b6312014-09-22 05:13:55 -0500764 parms->persistent_fid = pfid->persistent_fid;
765 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700766 return SMB2_write(xid, parms, written, iov, nr_segs);
767}
768
Steve Frenchd43cc792014-08-13 17:16:29 -0500769/* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
770static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
771 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
772{
773 struct cifsInodeInfo *cifsi;
774 int rc;
775
776 cifsi = CIFS_I(inode);
777
778 /* if file already sparse don't bother setting sparse again */
779 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
780 return true; /* already sparse */
781
782 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
783 return true; /* already not sparse */
784
785 /*
786 * Can't check for sparse support on share the usual way via the
787 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
788 * since Samba server doesn't set the flag on the share, yet
789 * supports the set sparse FSCTL and returns sparse correctly
790 * in the file attributes. If we fail setting sparse though we
791 * mark that server does not support sparse files for this share
792 * to avoid repeatedly sending the unsupported fsctl to server
793 * if the file is repeatedly extended.
794 */
795 if (tcon->broken_sparse_sup)
796 return false;
797
798 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
799 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
Aurelien Aptel51146622017-02-28 15:08:41 +0100800 true /* is_fctl */, false /* use_ipc */,
801 &setsparse, 1, NULL, NULL);
Steve Frenchd43cc792014-08-13 17:16:29 -0500802 if (rc) {
803 tcon->broken_sparse_sup = true;
804 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
805 return false;
806 }
807
808 if (setsparse)
809 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
810 else
811 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
812
813 return true;
814}
815
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700816static int
817smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
818 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
819{
820 __le64 eof = cpu_to_le64(size);
Steve French3d1a3742014-08-11 21:05:25 -0500821 struct inode *inode;
822
823 /*
824 * If extending file more than one page make sparse. Many Linux fs
825 * make files sparse by default when extending via ftruncate
826 */
David Howells2b0143b2015-03-17 22:25:59 +0000827 inode = d_inode(cfile->dentry);
Steve French3d1a3742014-08-11 21:05:25 -0500828
829 if (!set_alloc && (size > inode->i_size + 8192)) {
Steve French3d1a3742014-08-11 21:05:25 -0500830 __u8 set_sparse = 1;
Steve French3d1a3742014-08-11 21:05:25 -0500831
Steve Frenchd43cc792014-08-13 17:16:29 -0500832 /* whether set sparse succeeds or not, extend the file */
833 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
Steve French3d1a3742014-08-11 21:05:25 -0500834 }
835
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700836 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
Steve Frenchf29ebb42014-07-19 21:44:58 -0500837 cfile->fid.volatile_fid, cfile->pid, &eof, false);
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700838}
839
Steve French02b16662015-06-27 21:18:36 -0700840static int
841smb2_duplicate_extents(const unsigned int xid,
842 struct cifsFileInfo *srcfile,
843 struct cifsFileInfo *trgtfile, u64 src_off,
844 u64 len, u64 dest_off)
845{
846 int rc;
847 unsigned int ret_data_len;
Steve French02b16662015-06-27 21:18:36 -0700848 struct duplicate_extents_to_file dup_ext_buf;
849 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
850
851 /* server fileays advertise duplicate extent support with this flag */
852 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
853 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
854 return -EOPNOTSUPP;
855
856 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
857 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
858 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
859 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
860 dup_ext_buf.ByteCount = cpu_to_le64(len);
861 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
862 src_off, dest_off, len);
863
864 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
865 if (rc)
866 goto duplicate_extents_out;
867
868 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
869 trgtfile->fid.volatile_fid,
870 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
Aurelien Aptel51146622017-02-28 15:08:41 +0100871 true /* is_fsctl */, false /* use_ipc */,
872 (char *)&dup_ext_buf,
Steve French02b16662015-06-27 21:18:36 -0700873 sizeof(struct duplicate_extents_to_file),
Steve French24df1482016-09-29 04:20:23 -0500874 NULL,
Steve French02b16662015-06-27 21:18:36 -0700875 &ret_data_len);
876
877 if (ret_data_len > 0)
878 cifs_dbg(FYI, "non-zero response length in duplicate extents");
879
880duplicate_extents_out:
881 return rc;
882}
Steve French02b16662015-06-27 21:18:36 -0700883
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700884static int
Steve French64a5cfa2013-10-14 15:31:32 -0500885smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
886 struct cifsFileInfo *cfile)
887{
888 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
889 cfile->fid.volatile_fid);
890}
891
892static int
Steve Frenchb3152e22015-06-24 03:17:02 -0500893smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
894 struct cifsFileInfo *cfile)
895{
896 struct fsctl_set_integrity_information_req integr_info;
Steve Frenchb3152e22015-06-24 03:17:02 -0500897 unsigned int ret_data_len;
898
899 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
900 integr_info.Flags = 0;
901 integr_info.Reserved = 0;
902
903 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
904 cfile->fid.volatile_fid,
905 FSCTL_SET_INTEGRITY_INFORMATION,
Aurelien Aptel51146622017-02-28 15:08:41 +0100906 true /* is_fsctl */, false /* use_ipc */,
907 (char *)&integr_info,
Steve Frenchb3152e22015-06-24 03:17:02 -0500908 sizeof(struct fsctl_set_integrity_information_req),
Steve French24df1482016-09-29 04:20:23 -0500909 NULL,
Steve Frenchb3152e22015-06-24 03:17:02 -0500910 &ret_data_len);
911
912}
913
914static int
Steve French834170c2016-09-30 21:14:26 -0500915smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
916 struct cifsFileInfo *cfile, void __user *ioc_buf)
917{
918 char *retbuf = NULL;
919 unsigned int ret_data_len = 0;
920 int rc;
921 struct smb_snapshot_array snapshot_in;
922
923 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
924 cfile->fid.volatile_fid,
925 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
Aurelien Aptel51146622017-02-28 15:08:41 +0100926 true /* is_fsctl */, false /* use_ipc */,
927 NULL, 0 /* no input data */,
Steve French834170c2016-09-30 21:14:26 -0500928 (char **)&retbuf,
929 &ret_data_len);
930 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
931 rc, ret_data_len);
932 if (rc)
933 return rc;
934
935 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
936 /* Fixup buffer */
937 if (copy_from_user(&snapshot_in, ioc_buf,
938 sizeof(struct smb_snapshot_array))) {
939 rc = -EFAULT;
940 kfree(retbuf);
941 return rc;
942 }
943 if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) {
944 rc = -ERANGE;
David Disseldorp0e5c7952017-05-03 17:39:09 +0200945 kfree(retbuf);
Steve French834170c2016-09-30 21:14:26 -0500946 return rc;
947 }
948
949 if (ret_data_len > snapshot_in.snapshot_array_size)
950 ret_data_len = snapshot_in.snapshot_array_size;
951
952 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
953 rc = -EFAULT;
954 }
955
956 kfree(retbuf);
957 return rc;
958}
959
960static int
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700961smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
962 const char *path, struct cifs_sb_info *cifs_sb,
963 struct cifs_fid *fid, __u16 search_flags,
964 struct cifs_search_info *srch_inf)
965{
966 __le16 *utf16_path;
967 int rc;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700968 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400969 struct cifs_open_parms oparms;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700970
971 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
972 if (!utf16_path)
973 return -ENOMEM;
974
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400975 oparms.tcon = tcon;
976 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
977 oparms.disposition = FILE_OPEN;
978 oparms.create_options = 0;
979 oparms.fid = fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400980 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400981
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400982 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700983 kfree(utf16_path);
984 if (rc) {
Pavel Shilovskydcd878382017-06-06 16:58:58 -0700985 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700986 return rc;
987 }
988
989 srch_inf->entries_in_buffer = 0;
990 srch_inf->index_of_last_entry = 0;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700991
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400992 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
993 fid->volatile_fid, 0, srch_inf);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700994 if (rc) {
Pavel Shilovskydcd878382017-06-06 16:58:58 -0700995 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400996 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700997 }
998 return rc;
999}
1000
1001static int
1002smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
1003 struct cifs_fid *fid, __u16 search_flags,
1004 struct cifs_search_info *srch_inf)
1005{
1006 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
1007 fid->volatile_fid, 0, srch_inf);
1008}
1009
1010static int
1011smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1012 struct cifs_fid *fid)
1013{
1014 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1015}
1016
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001017/*
1018* If we negotiate SMB2 protocol and get STATUS_PENDING - update
1019* the number of credits and return true. Otherwise - return false.
1020*/
1021static bool
1022smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
1023{
Pavel Shilovsky31473fc2016-10-24 15:33:04 -07001024 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001025
Pavel Shilovsky31473fc2016-10-24 15:33:04 -07001026 if (shdr->Status != STATUS_PENDING)
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001027 return false;
1028
1029 if (!length) {
1030 spin_lock(&server->req_lock);
Pavel Shilovsky31473fc2016-10-24 15:33:04 -07001031 server->credits += le16_to_cpu(shdr->CreditRequest);
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001032 spin_unlock(&server->req_lock);
1033 wake_up(&server->request_q);
1034 }
1035
1036 return true;
1037}
1038
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001039static int
1040smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
1041 struct cifsInodeInfo *cinode)
1042{
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001043 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
1044 return SMB2_lease_break(0, tcon, cinode->lease_key,
1045 smb2_get_lease_state(cinode));
1046
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001047 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
1048 fid->volatile_fid,
Pavel Shilovsky18cceb62013-09-05 13:01:06 +04001049 CIFS_CACHE_READ(cinode) ? 1 : 0);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001050}
1051
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001052static int
1053smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1054 struct kstatfs *buf)
1055{
1056 int rc;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001057 __le16 srch_path = 0; /* Null - open root of share */
1058 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001059 struct cifs_open_parms oparms;
1060 struct cifs_fid fid;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001061
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001062 oparms.tcon = tcon;
1063 oparms.desired_access = FILE_READ_ATTRIBUTES;
1064 oparms.disposition = FILE_OPEN;
1065 oparms.create_options = 0;
1066 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +04001067 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001068
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001069 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001070 if (rc)
1071 return rc;
1072 buf->f_type = SMB2_MAGIC_NUMBER;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001073 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
1074 buf);
1075 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001076 return rc;
1077}
1078
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001079static bool
1080smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1081{
1082 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1083 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1084}
1085
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001086static int
1087smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1088 __u64 length, __u32 type, int lock, int unlock, bool wait)
1089{
1090 if (unlock && !lock)
1091 type = SMB2_LOCKFLAG_UNLOCK;
1092 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1093 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1094 current->tgid, length, offset, type, wait);
1095}
1096
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001097static void
1098smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1099{
1100 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1101}
1102
1103static void
1104smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1105{
1106 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1107}
1108
1109static void
1110smb2_new_lease_key(struct cifs_fid *fid)
1111{
Steve Frenchfa70b872016-09-22 00:39:34 -05001112 generate_random_uuid(fid->lease_key);
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001113}
1114
Aurelien Aptel9d496402017-02-13 16:16:49 +01001115static int
1116smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
1117 const char *search_name,
1118 struct dfs_info3_param **target_nodes,
1119 unsigned int *num_of_nodes,
1120 const struct nls_table *nls_codepage, int remap)
1121{
1122 int rc;
1123 __le16 *utf16_path = NULL;
1124 int utf16_path_len = 0;
1125 struct cifs_tcon *tcon;
1126 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
1127 struct get_dfs_referral_rsp *dfs_rsp = NULL;
1128 u32 dfs_req_size = 0, dfs_rsp_size = 0;
1129
1130 cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
1131
1132 /*
1133 * Use any tcon from the current session. Here, the first one.
1134 */
1135 spin_lock(&cifs_tcp_ses_lock);
1136 tcon = list_first_entry_or_null(&ses->tcon_list, struct cifs_tcon,
1137 tcon_list);
1138 if (tcon)
1139 tcon->tc_count++;
1140 spin_unlock(&cifs_tcp_ses_lock);
1141
1142 if (!tcon) {
1143 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
1144 ses);
1145 rc = -ENOTCONN;
1146 goto out;
1147 }
1148
1149 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
1150 &utf16_path_len,
1151 nls_codepage, remap);
1152 if (!utf16_path) {
1153 rc = -ENOMEM;
1154 goto out;
1155 }
1156
1157 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
1158 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
1159 if (!dfs_req) {
1160 rc = -ENOMEM;
1161 goto out;
1162 }
1163
1164 /* Highest DFS referral version understood */
1165 dfs_req->MaxReferralLevel = DFS_VERSION;
1166
1167 /* Path to resolve in an UTF-16 null-terminated string */
1168 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
1169
1170 do {
1171 /* try first with IPC */
1172 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
1173 FSCTL_DFS_GET_REFERRALS,
1174 true /* is_fsctl */, true /* use_ipc */,
1175 (char *)dfs_req, dfs_req_size,
1176 (char **)&dfs_rsp, &dfs_rsp_size);
1177 if (rc == -ENOTCONN) {
1178 /* try with normal tcon */
1179 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
1180 FSCTL_DFS_GET_REFERRALS,
1181 true /* is_fsctl */, false /*use_ipc*/,
1182 (char *)dfs_req, dfs_req_size,
1183 (char **)&dfs_rsp, &dfs_rsp_size);
1184 }
1185 } while (rc == -EAGAIN);
1186
1187 if (rc) {
1188 cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
1189 goto out;
1190 }
1191
1192 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
1193 num_of_nodes, target_nodes,
1194 nls_codepage, remap, search_name,
1195 true /* is_unicode */);
1196 if (rc) {
1197 cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
1198 goto out;
1199 }
1200
1201 out:
1202 if (tcon) {
1203 spin_lock(&cifs_tcp_ses_lock);
1204 tcon->tc_count--;
1205 spin_unlock(&cifs_tcp_ses_lock);
1206 }
1207 kfree(utf16_path);
1208 kfree(dfs_req);
1209 kfree(dfs_rsp);
1210 return rc;
1211}
Pavel Shilovsky78932422016-07-24 10:37:38 +03001212#define SMB2_SYMLINK_STRUCT_SIZE \
1213 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1214
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001215static int
1216smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1217 const char *full_path, char **target_path,
1218 struct cifs_sb_info *cifs_sb)
1219{
1220 int rc;
1221 __le16 *utf16_path;
1222 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1223 struct cifs_open_parms oparms;
1224 struct cifs_fid fid;
1225 struct smb2_err_rsp *err_buf = NULL;
1226 struct smb2_symlink_err_rsp *symlink;
Pavel Shilovsky78932422016-07-24 10:37:38 +03001227 unsigned int sub_len;
1228 unsigned int sub_offset;
1229 unsigned int print_len;
1230 unsigned int print_offset;
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001231
1232 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1233
1234 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1235 if (!utf16_path)
1236 return -ENOMEM;
1237
1238 oparms.tcon = tcon;
1239 oparms.desired_access = FILE_READ_ATTRIBUTES;
1240 oparms.disposition = FILE_OPEN;
1241 oparms.create_options = 0;
1242 oparms.fid = &fid;
1243 oparms.reconnect = false;
1244
1245 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
1246
1247 if (!rc || !err_buf) {
1248 kfree(utf16_path);
1249 return -ENOENT;
1250 }
Pavel Shilovsky78932422016-07-24 10:37:38 +03001251
1252 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1253 get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) {
1254 kfree(utf16_path);
1255 return -ENOENT;
1256 }
1257
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001258 /* open must fail on symlink - reset rc */
1259 rc = 0;
1260 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1261 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1262 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
Pavel Shilovsky78932422016-07-24 10:37:38 +03001263 print_len = le16_to_cpu(symlink->PrintNameLength);
1264 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1265
1266 if (get_rfc1002_length(err_buf) + 4 <
1267 SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1268 kfree(utf16_path);
1269 return -ENOENT;
1270 }
1271
1272 if (get_rfc1002_length(err_buf) + 4 <
1273 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1274 kfree(utf16_path);
1275 return -ENOENT;
1276 }
1277
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001278 *target_path = cifs_strndup_from_utf16(
1279 (char *)symlink->PathBuffer + sub_offset,
1280 sub_len, true, cifs_sb->local_nls);
1281 if (!(*target_path)) {
1282 kfree(utf16_path);
1283 return -ENOMEM;
1284 }
1285 convert_delimiter(*target_path, '/');
1286 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1287 kfree(utf16_path);
1288 return rc;
1289}
1290
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05001291static struct cifs_ntsd *
1292get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
1293 const struct cifs_fid *cifsfid, u32 *pacllen)
1294{
1295 struct cifs_ntsd *pntsd = NULL;
1296 unsigned int xid;
1297 int rc = -EOPNOTSUPP;
1298 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1299
1300 if (IS_ERR(tlink))
1301 return ERR_CAST(tlink);
1302
1303 xid = get_xid();
1304 cifs_dbg(FYI, "trying to get acl\n");
1305
1306 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
1307 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
1308 free_xid(xid);
1309
1310 cifs_put_tlink(tlink);
1311
1312 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1313 if (rc)
1314 return ERR_PTR(rc);
1315 return pntsd;
1316
1317}
1318
1319static struct cifs_ntsd *
1320get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
1321 const char *path, u32 *pacllen)
1322{
1323 struct cifs_ntsd *pntsd = NULL;
1324 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1325 unsigned int xid;
1326 int rc;
1327 struct cifs_tcon *tcon;
1328 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1329 struct cifs_fid fid;
1330 struct cifs_open_parms oparms;
1331 __le16 *utf16_path;
1332
1333 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
1334 if (IS_ERR(tlink))
1335 return ERR_CAST(tlink);
1336
1337 tcon = tlink_tcon(tlink);
1338 xid = get_xid();
1339
1340 if (backup_cred(cifs_sb))
1341 oparms.create_options |= CREATE_OPEN_BACKUP_INTENT;
1342 else
1343 oparms.create_options = 0;
1344
1345 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1346 if (!utf16_path)
1347 return ERR_PTR(-ENOMEM);
1348
1349 oparms.tcon = tcon;
1350 oparms.desired_access = READ_CONTROL;
1351 oparms.disposition = FILE_OPEN;
1352 oparms.fid = &fid;
1353 oparms.reconnect = false;
1354
1355 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
1356 kfree(utf16_path);
1357 if (!rc) {
1358 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
1359 fid.volatile_fid, (void **)&pntsd, pacllen);
1360 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1361 }
1362
1363 cifs_put_tlink(tlink);
1364 free_xid(xid);
1365
1366 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1367 if (rc)
1368 return ERR_PTR(rc);
1369 return pntsd;
1370}
1371
1372/* Retrieve an ACL from the server */
1373static struct cifs_ntsd *
1374get_smb2_acl(struct cifs_sb_info *cifs_sb,
1375 struct inode *inode, const char *path,
1376 u32 *pacllen)
1377{
1378 struct cifs_ntsd *pntsd = NULL;
1379 struct cifsFileInfo *open_file = NULL;
1380
1381 if (inode)
1382 open_file = find_readable_file(CIFS_I(inode), true);
1383 if (!open_file)
1384 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
1385
1386 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
1387 cifsFileInfo_put(open_file);
1388 return pntsd;
1389}
1390
1391
Steve French30175622014-08-17 18:16:40 -05001392static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1393 loff_t offset, loff_t len, bool keep_size)
1394{
1395 struct inode *inode;
1396 struct cifsInodeInfo *cifsi;
1397 struct cifsFileInfo *cfile = file->private_data;
1398 struct file_zero_data_information fsctl_buf;
1399 long rc;
1400 unsigned int xid;
1401
1402 xid = get_xid();
1403
David Howells2b0143b2015-03-17 22:25:59 +00001404 inode = d_inode(cfile->dentry);
Steve French30175622014-08-17 18:16:40 -05001405 cifsi = CIFS_I(inode);
1406
1407 /* if file not oplocked can't be sure whether asking to extend size */
1408 if (!CIFS_CACHE_READ(cifsi))
1409 if (keep_size == false)
1410 return -EOPNOTSUPP;
1411
Steve French2bb93d22014-08-20 18:56:29 -05001412 /*
Steve French30175622014-08-17 18:16:40 -05001413 * Must check if file sparse since fallocate -z (zero range) assumes
1414 * non-sparse allocation
1415 */
1416 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
1417 return -EOPNOTSUPP;
1418
1419 /*
1420 * need to make sure we are not asked to extend the file since the SMB3
1421 * fsctl does not change the file size. In the future we could change
1422 * this to zero the first part of the range then set the file size
1423 * which for a non sparse file would zero the newly extended range
1424 */
1425 if (keep_size == false)
1426 if (i_size_read(inode) < offset + len)
1427 return -EOPNOTSUPP;
1428
1429 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1430
1431 fsctl_buf.FileOffset = cpu_to_le64(offset);
1432 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1433
1434 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1435 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
Aurelien Aptel51146622017-02-28 15:08:41 +01001436 true /* is_fctl */, false /* use_ipc */,
1437 (char *)&fsctl_buf,
Steve French30175622014-08-17 18:16:40 -05001438 sizeof(struct file_zero_data_information), NULL, NULL);
1439 free_xid(xid);
1440 return rc;
1441}
1442
Steve French31742c52014-08-17 08:38:47 -05001443static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1444 loff_t offset, loff_t len)
1445{
1446 struct inode *inode;
1447 struct cifsInodeInfo *cifsi;
1448 struct cifsFileInfo *cfile = file->private_data;
1449 struct file_zero_data_information fsctl_buf;
1450 long rc;
1451 unsigned int xid;
1452 __u8 set_sparse = 1;
1453
1454 xid = get_xid();
1455
David Howells2b0143b2015-03-17 22:25:59 +00001456 inode = d_inode(cfile->dentry);
Steve French31742c52014-08-17 08:38:47 -05001457 cifsi = CIFS_I(inode);
1458
1459 /* Need to make file sparse, if not already, before freeing range. */
1460 /* Consider adding equivalent for compressed since it could also work */
1461 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
1462 return -EOPNOTSUPP;
1463
1464 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1465
1466 fsctl_buf.FileOffset = cpu_to_le64(offset);
1467 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1468
1469 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1470 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
Aurelien Aptel51146622017-02-28 15:08:41 +01001471 true /* is_fctl */, false /* use_ipc */,
1472 (char *)&fsctl_buf,
Steve French31742c52014-08-17 08:38:47 -05001473 sizeof(struct file_zero_data_information), NULL, NULL);
1474 free_xid(xid);
1475 return rc;
1476}
1477
Steve French9ccf3212014-10-18 17:01:15 -05001478static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1479 loff_t off, loff_t len, bool keep_size)
1480{
1481 struct inode *inode;
1482 struct cifsInodeInfo *cifsi;
1483 struct cifsFileInfo *cfile = file->private_data;
1484 long rc = -EOPNOTSUPP;
1485 unsigned int xid;
1486
1487 xid = get_xid();
1488
David Howells2b0143b2015-03-17 22:25:59 +00001489 inode = d_inode(cfile->dentry);
Steve French9ccf3212014-10-18 17:01:15 -05001490 cifsi = CIFS_I(inode);
1491
1492 /* if file not oplocked can't be sure whether asking to extend size */
1493 if (!CIFS_CACHE_READ(cifsi))
1494 if (keep_size == false)
1495 return -EOPNOTSUPP;
1496
1497 /*
1498 * Files are non-sparse by default so falloc may be a no-op
1499 * Must check if file sparse. If not sparse, and not extending
1500 * then no need to do anything since file already allocated
1501 */
1502 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
1503 if (keep_size == true)
1504 return 0;
1505 /* check if extending file */
1506 else if (i_size_read(inode) >= off + len)
1507 /* not extending file and already not sparse */
1508 return 0;
1509 /* BB: in future add else clause to extend file */
1510 else
1511 return -EOPNOTSUPP;
1512 }
1513
1514 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
1515 /*
1516 * Check if falloc starts within first few pages of file
1517 * and ends within a few pages of the end of file to
1518 * ensure that most of file is being forced to be
1519 * fallocated now. If so then setting whole file sparse
1520 * ie potentially making a few extra pages at the beginning
1521 * or end of the file non-sparse via set_sparse is harmless.
1522 */
1523 if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
1524 return -EOPNOTSUPP;
1525
1526 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
1527 }
1528 /* BB: else ... in future add code to extend file and set sparse */
1529
1530
1531 free_xid(xid);
1532 return rc;
1533}
1534
1535
Steve French31742c52014-08-17 08:38:47 -05001536static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
1537 loff_t off, loff_t len)
1538{
1539 /* KEEP_SIZE already checked for by do_fallocate */
1540 if (mode & FALLOC_FL_PUNCH_HOLE)
1541 return smb3_punch_hole(file, tcon, off, len);
Steve French30175622014-08-17 18:16:40 -05001542 else if (mode & FALLOC_FL_ZERO_RANGE) {
1543 if (mode & FALLOC_FL_KEEP_SIZE)
1544 return smb3_zero_range(file, tcon, off, len, true);
1545 return smb3_zero_range(file, tcon, off, len, false);
Steve French9ccf3212014-10-18 17:01:15 -05001546 } else if (mode == FALLOC_FL_KEEP_SIZE)
1547 return smb3_simple_falloc(file, tcon, off, len, true);
1548 else if (mode == 0)
1549 return smb3_simple_falloc(file, tcon, off, len, false);
Steve French31742c52014-08-17 08:38:47 -05001550
1551 return -EOPNOTSUPP;
1552}
1553
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001554static void
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001555smb2_downgrade_oplock(struct TCP_Server_Info *server,
1556 struct cifsInodeInfo *cinode, bool set_level2)
1557{
1558 if (set_level2)
1559 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
1560 0, NULL);
1561 else
1562 server->ops->set_oplock_level(cinode, 0, 0, NULL);
1563}
1564
1565static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001566smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1567 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001568{
1569 oplock &= 0xFF;
1570 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1571 return;
1572 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001573 cinode->oplock = CIFS_CACHE_RHW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001574 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
1575 &cinode->vfs_inode);
1576 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001577 cinode->oplock = CIFS_CACHE_RW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001578 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
1579 &cinode->vfs_inode);
1580 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
1581 cinode->oplock = CIFS_CACHE_READ_FLG;
1582 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
1583 &cinode->vfs_inode);
1584 } else
1585 cinode->oplock = 0;
1586}
1587
1588static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001589smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1590 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001591{
1592 char message[5] = {0};
1593
1594 oplock &= 0xFF;
1595 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1596 return;
1597
1598 cinode->oplock = 0;
1599 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
1600 cinode->oplock |= CIFS_CACHE_READ_FLG;
1601 strcat(message, "R");
1602 }
1603 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
1604 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
1605 strcat(message, "H");
1606 }
1607 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
1608 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
1609 strcat(message, "W");
1610 }
1611 if (!cinode->oplock)
1612 strcat(message, "None");
1613 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
1614 &cinode->vfs_inode);
1615}
1616
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001617static void
1618smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1619 unsigned int epoch, bool *purge_cache)
1620{
1621 unsigned int old_oplock = cinode->oplock;
1622
1623 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
1624
1625 if (purge_cache) {
1626 *purge_cache = false;
1627 if (old_oplock == CIFS_CACHE_READ_FLG) {
1628 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
1629 (epoch - cinode->epoch > 0))
1630 *purge_cache = true;
1631 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1632 (epoch - cinode->epoch > 1))
1633 *purge_cache = true;
1634 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1635 (epoch - cinode->epoch > 1))
1636 *purge_cache = true;
1637 else if (cinode->oplock == 0 &&
1638 (epoch - cinode->epoch > 0))
1639 *purge_cache = true;
1640 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
1641 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1642 (epoch - cinode->epoch > 0))
1643 *purge_cache = true;
1644 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1645 (epoch - cinode->epoch > 1))
1646 *purge_cache = true;
1647 }
1648 cinode->epoch = epoch;
1649 }
1650}
1651
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001652static bool
1653smb2_is_read_op(__u32 oplock)
1654{
1655 return oplock == SMB2_OPLOCK_LEVEL_II;
1656}
1657
1658static bool
1659smb21_is_read_op(__u32 oplock)
1660{
1661 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
1662 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
1663}
1664
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001665static __le32
1666map_oplock_to_lease(u8 oplock)
1667{
1668 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1669 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
1670 else if (oplock == SMB2_OPLOCK_LEVEL_II)
1671 return SMB2_LEASE_READ_CACHING;
1672 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
1673 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
1674 SMB2_LEASE_WRITE_CACHING;
1675 return 0;
1676}
1677
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001678static char *
1679smb2_create_lease_buf(u8 *lease_key, u8 oplock)
1680{
1681 struct create_lease *buf;
1682
1683 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
1684 if (!buf)
1685 return NULL;
1686
1687 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1688 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001689 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001690
1691 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1692 (struct create_lease, lcontext));
1693 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
1694 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1695 (struct create_lease, Name));
1696 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001697 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001698 buf->Name[0] = 'R';
1699 buf->Name[1] = 'q';
1700 buf->Name[2] = 'L';
1701 buf->Name[3] = 's';
1702 return (char *)buf;
1703}
1704
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001705static char *
1706smb3_create_lease_buf(u8 *lease_key, u8 oplock)
1707{
1708 struct create_lease_v2 *buf;
1709
1710 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
1711 if (!buf)
1712 return NULL;
1713
1714 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1715 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1716 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1717
1718 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1719 (struct create_lease_v2, lcontext));
1720 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
1721 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1722 (struct create_lease_v2, Name));
1723 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001724 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001725 buf->Name[0] = 'R';
1726 buf->Name[1] = 'q';
1727 buf->Name[2] = 'L';
1728 buf->Name[3] = 's';
1729 return (char *)buf;
1730}
1731
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001732static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001733smb2_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001734{
1735 struct create_lease *lc = (struct create_lease *)buf;
1736
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001737 *epoch = 0; /* not used */
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001738 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1739 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1740 return le32_to_cpu(lc->lcontext.LeaseState);
1741}
1742
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001743static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001744smb3_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001745{
1746 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
1747
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001748 *epoch = le16_to_cpu(lc->lcontext.Epoch);
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001749 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1750 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1751 return le32_to_cpu(lc->lcontext.LeaseState);
1752}
1753
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001754static unsigned int
1755smb2_wp_retry_size(struct inode *inode)
1756{
1757 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
1758 SMB2_MAX_BUFFER_SIZE);
1759}
1760
Pavel Shilovsky52755802014-08-18 20:49:57 +04001761static bool
1762smb2_dir_needs_close(struct cifsFileInfo *cfile)
1763{
1764 return !cfile->invalidHandle;
1765}
1766
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07001767static void
1768fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, struct smb_rqst *old_rq)
1769{
1770 struct smb2_sync_hdr *shdr =
1771 (struct smb2_sync_hdr *)old_rq->rq_iov[1].iov_base;
1772 unsigned int orig_len = get_rfc1002_length(old_rq->rq_iov[0].iov_base);
1773
1774 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
1775 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
1776 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
1777 tr_hdr->Flags = cpu_to_le16(0x01);
1778 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
1779 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
1780 inc_rfc1001_len(tr_hdr, sizeof(struct smb2_transform_hdr) - 4);
1781 inc_rfc1001_len(tr_hdr, orig_len);
1782}
1783
1784static struct scatterlist *
1785init_sg(struct smb_rqst *rqst, u8 *sign)
1786{
1787 unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1;
1788 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24;
1789 struct scatterlist *sg;
1790 unsigned int i;
1791 unsigned int j;
1792
1793 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
1794 if (!sg)
1795 return NULL;
1796
1797 sg_init_table(sg, sg_len);
1798 sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len);
1799 for (i = 1; i < rqst->rq_nvec; i++)
1800 sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base,
1801 rqst->rq_iov[i].iov_len);
1802 for (j = 0; i < sg_len - 1; i++, j++) {
1803 unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz
1804 : rqst->rq_tailsz;
1805 sg_set_page(&sg[i], rqst->rq_pages[j], len, 0);
1806 }
1807 sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE);
1808 return sg;
1809}
1810
1811struct cifs_crypt_result {
1812 int err;
1813 struct completion completion;
1814};
1815
1816static void cifs_crypt_complete(struct crypto_async_request *req, int err)
1817{
1818 struct cifs_crypt_result *res = req->data;
1819
1820 if (err == -EINPROGRESS)
1821 return;
1822
1823 res->err = err;
1824 complete(&res->completion);
1825}
1826
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08001827static int
1828smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
1829{
1830 struct cifs_ses *ses;
1831 u8 *ses_enc_key;
1832
1833 spin_lock(&cifs_tcp_ses_lock);
1834 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
1835 if (ses->Suid != ses_id)
1836 continue;
1837 ses_enc_key = enc ? ses->smb3encryptionkey :
1838 ses->smb3decryptionkey;
1839 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
1840 spin_unlock(&cifs_tcp_ses_lock);
1841 return 0;
1842 }
1843 spin_unlock(&cifs_tcp_ses_lock);
1844
1845 return 1;
1846}
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07001847/*
1848 * Encrypt or decrypt @rqst message. @rqst has the following format:
1849 * iov[0] - transform header (associate data),
1850 * iov[1-N] and pages - data to encrypt.
1851 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
1852 * untouched.
1853 */
1854static int
1855crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc)
1856{
1857 struct smb2_transform_hdr *tr_hdr =
1858 (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base;
1859 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24;
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07001860 int rc = 0;
1861 struct scatterlist *sg;
1862 u8 sign[SMB2_SIGNATURE_SIZE] = {};
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08001863 u8 key[SMB3_SIGN_KEY_SIZE];
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07001864 struct aead_request *req;
1865 char *iv;
1866 unsigned int iv_len;
1867 struct cifs_crypt_result result = {0, };
1868 struct crypto_aead *tfm;
1869 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
1870
1871 init_completion(&result.completion);
1872
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08001873 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
1874 if (rc) {
1875 cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
1876 enc ? "en" : "de");
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07001877 return 0;
1878 }
1879
1880 rc = smb3_crypto_aead_allocate(server);
1881 if (rc) {
1882 cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
1883 return rc;
1884 }
1885
1886 tfm = enc ? server->secmech.ccmaesencrypt :
1887 server->secmech.ccmaesdecrypt;
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08001888 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07001889 if (rc) {
1890 cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
1891 return rc;
1892 }
1893
1894 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
1895 if (rc) {
1896 cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
1897 return rc;
1898 }
1899
1900 req = aead_request_alloc(tfm, GFP_KERNEL);
1901 if (!req) {
1902 cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
1903 return -ENOMEM;
1904 }
1905
1906 if (!enc) {
1907 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
1908 crypt_len += SMB2_SIGNATURE_SIZE;
1909 }
1910
1911 sg = init_sg(rqst, sign);
1912 if (!sg) {
Christophe Jaillet517a6e42017-06-11 09:12:47 +02001913 cifs_dbg(VFS, "%s: Failed to init sg", __func__);
1914 rc = -ENOMEM;
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07001915 goto free_req;
1916 }
1917
1918 iv_len = crypto_aead_ivsize(tfm);
1919 iv = kzalloc(iv_len, GFP_KERNEL);
1920 if (!iv) {
1921 cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
Christophe Jaillet517a6e42017-06-11 09:12:47 +02001922 rc = -ENOMEM;
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07001923 goto free_sg;
1924 }
1925 iv[0] = 3;
1926 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
1927
1928 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
1929 aead_request_set_ad(req, assoc_data_len);
1930
1931 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1932 cifs_crypt_complete, &result);
1933
1934 rc = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
1935
1936 if (rc == -EINPROGRESS || rc == -EBUSY) {
1937 wait_for_completion(&result.completion);
1938 rc = result.err;
1939 }
1940
1941 if (!rc && enc)
1942 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
1943
1944 kfree(iv);
1945free_sg:
1946 kfree(sg);
1947free_req:
1948 kfree(req);
1949 return rc;
1950}
1951
1952static int
1953smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
1954 struct smb_rqst *old_rq)
1955{
1956 struct kvec *iov;
1957 struct page **pages;
1958 struct smb2_transform_hdr *tr_hdr;
1959 unsigned int npages = old_rq->rq_npages;
1960 int i;
1961 int rc = -ENOMEM;
1962
1963 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
1964 if (!pages)
1965 return rc;
1966
1967 new_rq->rq_pages = pages;
1968 new_rq->rq_npages = old_rq->rq_npages;
1969 new_rq->rq_pagesz = old_rq->rq_pagesz;
1970 new_rq->rq_tailsz = old_rq->rq_tailsz;
1971
1972 for (i = 0; i < npages; i++) {
1973 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
1974 if (!pages[i])
1975 goto err_free_pages;
1976 }
1977
1978 iov = kmalloc_array(old_rq->rq_nvec, sizeof(struct kvec), GFP_KERNEL);
1979 if (!iov)
1980 goto err_free_pages;
1981
1982 /* copy all iovs from the old except the 1st one (rfc1002 length) */
1983 memcpy(&iov[1], &old_rq->rq_iov[1],
1984 sizeof(struct kvec) * (old_rq->rq_nvec - 1));
1985 new_rq->rq_iov = iov;
1986 new_rq->rq_nvec = old_rq->rq_nvec;
1987
1988 tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL);
1989 if (!tr_hdr)
1990 goto err_free_iov;
1991
1992 /* fill the 1st iov with a transform header */
1993 fill_transform_hdr(tr_hdr, old_rq);
1994 new_rq->rq_iov[0].iov_base = tr_hdr;
1995 new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr);
1996
1997 /* copy pages form the old */
1998 for (i = 0; i < npages; i++) {
1999 char *dst = kmap(new_rq->rq_pages[i]);
2000 char *src = kmap(old_rq->rq_pages[i]);
2001 unsigned int len = (i < npages - 1) ? new_rq->rq_pagesz :
2002 new_rq->rq_tailsz;
2003 memcpy(dst, src, len);
2004 kunmap(new_rq->rq_pages[i]);
2005 kunmap(old_rq->rq_pages[i]);
2006 }
2007
2008 rc = crypt_message(server, new_rq, 1);
2009 cifs_dbg(FYI, "encrypt message returned %d", rc);
2010 if (rc)
2011 goto err_free_tr_hdr;
2012
2013 return rc;
2014
2015err_free_tr_hdr:
2016 kfree(tr_hdr);
2017err_free_iov:
2018 kfree(iov);
2019err_free_pages:
2020 for (i = i - 1; i >= 0; i--)
2021 put_page(pages[i]);
2022 kfree(pages);
2023 return rc;
2024}
2025
2026static void
2027smb3_free_transform_rq(struct smb_rqst *rqst)
2028{
2029 int i = rqst->rq_npages - 1;
2030
2031 for (; i >= 0; i--)
2032 put_page(rqst->rq_pages[i]);
2033 kfree(rqst->rq_pages);
2034 /* free transform header */
2035 kfree(rqst->rq_iov[0].iov_base);
2036 kfree(rqst->rq_iov);
2037}
2038
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002039static int
2040smb3_is_transform_hdr(void *buf)
2041{
2042 struct smb2_transform_hdr *trhdr = buf;
2043
2044 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
2045}
2046
2047static int
2048decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
2049 unsigned int buf_data_size, struct page **pages,
2050 unsigned int npages, unsigned int page_data_size)
2051{
2052 struct kvec iov[2];
2053 struct smb_rqst rqst = {NULL};
2054 struct smb2_hdr *hdr;
2055 int rc;
2056
2057 iov[0].iov_base = buf;
2058 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2059 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
2060 iov[1].iov_len = buf_data_size;
2061
2062 rqst.rq_iov = iov;
2063 rqst.rq_nvec = 2;
2064 rqst.rq_pages = pages;
2065 rqst.rq_npages = npages;
2066 rqst.rq_pagesz = PAGE_SIZE;
2067 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
2068
2069 rc = crypt_message(server, &rqst, 0);
2070 cifs_dbg(FYI, "decrypt message returned %d\n", rc);
2071
2072 if (rc)
2073 return rc;
2074
2075 memmove(buf + 4, iov[1].iov_base, buf_data_size);
2076 hdr = (struct smb2_hdr *)buf;
2077 hdr->smb2_buf_length = cpu_to_be32(buf_data_size + page_data_size);
2078 server->total_read = buf_data_size + page_data_size + 4;
2079
2080 return rc;
2081}
2082
2083static int
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002084read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
2085 unsigned int npages, unsigned int len)
2086{
2087 int i;
2088 int length;
2089
2090 for (i = 0; i < npages; i++) {
2091 struct page *page = pages[i];
2092 size_t n;
2093
2094 n = len;
2095 if (len >= PAGE_SIZE) {
2096 /* enough data to fill the page */
2097 n = PAGE_SIZE;
2098 len -= n;
2099 } else {
2100 zero_user(page, len, PAGE_SIZE - len);
2101 len = 0;
2102 }
2103 length = cifs_read_page_from_socket(server, page, n);
2104 if (length < 0)
2105 return length;
2106 server->total_read += length;
2107 }
2108
2109 return 0;
2110}
2111
2112static int
2113init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
2114 unsigned int cur_off, struct bio_vec **page_vec)
2115{
2116 struct bio_vec *bvec;
2117 int i;
2118
2119 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
2120 if (!bvec)
2121 return -ENOMEM;
2122
2123 for (i = 0; i < npages; i++) {
2124 bvec[i].bv_page = pages[i];
2125 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
2126 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
2127 data_size -= bvec[i].bv_len;
2128 }
2129
2130 if (data_size != 0) {
2131 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
2132 kfree(bvec);
2133 return -EIO;
2134 }
2135
2136 *page_vec = bvec;
2137 return 0;
2138}
2139
2140static int
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002141handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
2142 char *buf, unsigned int buf_len, struct page **pages,
2143 unsigned int npages, unsigned int page_data_size)
2144{
2145 unsigned int data_offset;
2146 unsigned int data_len;
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002147 unsigned int cur_off;
2148 unsigned int cur_page_idx;
2149 unsigned int pad_len;
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002150 struct cifs_readdata *rdata = mid->callback_data;
2151 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
2152 struct bio_vec *bvec = NULL;
2153 struct iov_iter iter;
2154 struct kvec iov;
2155 int length;
2156
2157 if (shdr->Command != SMB2_READ) {
2158 cifs_dbg(VFS, "only big read responses are supported\n");
2159 return -ENOTSUPP;
2160 }
2161
2162 if (server->ops->is_status_pending &&
2163 server->ops->is_status_pending(buf, server, 0))
2164 return -1;
2165
2166 rdata->result = server->ops->map_error(buf, false);
2167 if (rdata->result != 0) {
2168 cifs_dbg(FYI, "%s: server returned error %d\n",
2169 __func__, rdata->result);
2170 dequeue_mid(mid, rdata->result);
2171 return 0;
2172 }
2173
2174 data_offset = server->ops->read_data_offset(buf) + 4;
2175 data_len = server->ops->read_data_length(buf);
2176
2177 if (data_offset < server->vals->read_rsp_size) {
2178 /*
2179 * win2k8 sometimes sends an offset of 0 when the read
2180 * is beyond the EOF. Treat it as if the data starts just after
2181 * the header.
2182 */
2183 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
2184 __func__, data_offset);
2185 data_offset = server->vals->read_rsp_size;
2186 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
2187 /* data_offset is beyond the end of smallbuf */
2188 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
2189 __func__, data_offset);
2190 rdata->result = -EIO;
2191 dequeue_mid(mid, rdata->result);
2192 return 0;
2193 }
2194
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002195 pad_len = data_offset - server->vals->read_rsp_size;
2196
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002197 if (buf_len <= data_offset) {
2198 /* read response payload is in pages */
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002199 cur_page_idx = pad_len / PAGE_SIZE;
2200 cur_off = pad_len % PAGE_SIZE;
2201
2202 if (cur_page_idx != 0) {
2203 /* data offset is beyond the 1st page of response */
2204 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
2205 __func__, data_offset);
2206 rdata->result = -EIO;
2207 dequeue_mid(mid, rdata->result);
2208 return 0;
2209 }
2210
2211 if (data_len > page_data_size - pad_len) {
2212 /* data_len is corrupt -- discard frame */
2213 rdata->result = -EIO;
2214 dequeue_mid(mid, rdata->result);
2215 return 0;
2216 }
2217
2218 rdata->result = init_read_bvec(pages, npages, page_data_size,
2219 cur_off, &bvec);
2220 if (rdata->result != 0) {
2221 dequeue_mid(mid, rdata->result);
2222 return 0;
2223 }
2224
2225 iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len);
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002226 } else if (buf_len >= data_offset + data_len) {
2227 /* read response payload is in buf */
2228 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
2229 iov.iov_base = buf + data_offset;
2230 iov.iov_len = data_len;
2231 iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len);
2232 } else {
2233 /* read response payload cannot be in both buf and pages */
2234 WARN_ONCE(1, "buf can not contain only a part of read data");
2235 rdata->result = -EIO;
2236 dequeue_mid(mid, rdata->result);
2237 return 0;
2238 }
2239
2240 /* set up first iov for signature check */
2241 rdata->iov[0].iov_base = buf;
2242 rdata->iov[0].iov_len = 4;
2243 rdata->iov[1].iov_base = buf + 4;
2244 rdata->iov[1].iov_len = server->vals->read_rsp_size - 4;
2245 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
2246 rdata->iov[0].iov_base, server->vals->read_rsp_size);
2247
2248 length = rdata->copy_into_pages(server, rdata, &iter);
2249
2250 kfree(bvec);
2251
2252 if (length < 0)
2253 return length;
2254
2255 dequeue_mid(mid, false);
2256 return length;
2257}
2258
2259static int
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002260receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2261{
2262 char *buf = server->smallbuf;
2263 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2264 unsigned int npages;
2265 struct page **pages;
2266 unsigned int len;
2267 unsigned int buflen = get_rfc1002_length(buf) + 4;
2268 int rc;
2269 int i = 0;
2270
2271 len = min_t(unsigned int, buflen, server->vals->read_rsp_size - 4 +
2272 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
2273
2274 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
2275 if (rc < 0)
2276 return rc;
2277 server->total_read += rc;
2278
2279 len = le32_to_cpu(tr_hdr->OriginalMessageSize) + 4 -
2280 server->vals->read_rsp_size;
2281 npages = DIV_ROUND_UP(len, PAGE_SIZE);
2282
2283 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
2284 if (!pages) {
2285 rc = -ENOMEM;
2286 goto discard_data;
2287 }
2288
2289 for (; i < npages; i++) {
2290 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2291 if (!pages[i]) {
2292 rc = -ENOMEM;
2293 goto discard_data;
2294 }
2295 }
2296
2297 /* read read data into pages */
2298 rc = read_data_into_pages(server, pages, npages, len);
2299 if (rc)
2300 goto free_pages;
2301
Pavel Shilovsky350be252017-04-10 10:31:33 -07002302 rc = cifs_discard_remaining_data(server);
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002303 if (rc)
2304 goto free_pages;
2305
2306 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size - 4,
2307 pages, npages, len);
2308 if (rc)
2309 goto free_pages;
2310
2311 *mid = smb2_find_mid(server, buf);
2312 if (*mid == NULL)
2313 cifs_dbg(FYI, "mid not found\n");
2314 else {
2315 cifs_dbg(FYI, "mid found\n");
2316 (*mid)->decrypted = true;
2317 rc = handle_read_data(server, *mid, buf,
2318 server->vals->read_rsp_size,
2319 pages, npages, len);
2320 }
2321
2322free_pages:
2323 for (i = i - 1; i >= 0; i--)
2324 put_page(pages[i]);
2325 kfree(pages);
2326 return rc;
2327discard_data:
Pavel Shilovsky350be252017-04-10 10:31:33 -07002328 cifs_discard_remaining_data(server);
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002329 goto free_pages;
2330}
2331
2332static int
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002333receive_encrypted_standard(struct TCP_Server_Info *server,
2334 struct mid_q_entry **mid)
2335{
2336 int length;
2337 char *buf = server->smallbuf;
2338 unsigned int pdu_length = get_rfc1002_length(buf);
2339 unsigned int buf_size;
2340 struct mid_q_entry *mid_entry;
2341
2342 /* switch to large buffer if too big for a small one */
2343 if (pdu_length + 4 > MAX_CIFS_SMALL_BUFFER_SIZE) {
2344 server->large_buf = true;
2345 memcpy(server->bigbuf, buf, server->total_read);
2346 buf = server->bigbuf;
2347 }
2348
2349 /* now read the rest */
2350 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
2351 pdu_length - HEADER_SIZE(server) + 1 + 4);
2352 if (length < 0)
2353 return length;
2354 server->total_read += length;
2355
2356 buf_size = pdu_length + 4 - sizeof(struct smb2_transform_hdr);
2357 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
2358 if (length)
2359 return length;
2360
2361 mid_entry = smb2_find_mid(server, buf);
2362 if (mid_entry == NULL)
2363 cifs_dbg(FYI, "mid not found\n");
2364 else {
2365 cifs_dbg(FYI, "mid found\n");
2366 mid_entry->decrypted = true;
2367 }
2368
2369 *mid = mid_entry;
2370
2371 if (mid_entry && mid_entry->handle)
2372 return mid_entry->handle(server, mid_entry);
2373
2374 return cifs_handle_standard(server, mid_entry);
2375}
2376
2377static int
2378smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2379{
2380 char *buf = server->smallbuf;
2381 unsigned int pdu_length = get_rfc1002_length(buf);
2382 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2383 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2384
2385 if (pdu_length + 4 < sizeof(struct smb2_transform_hdr) +
2386 sizeof(struct smb2_sync_hdr)) {
2387 cifs_dbg(VFS, "Transform message is too small (%u)\n",
2388 pdu_length);
2389 cifs_reconnect(server);
2390 wake_up(&server->response_q);
2391 return -ECONNABORTED;
2392 }
2393
2394 if (pdu_length + 4 < orig_len + sizeof(struct smb2_transform_hdr)) {
2395 cifs_dbg(VFS, "Transform message is broken\n");
2396 cifs_reconnect(server);
2397 wake_up(&server->response_q);
2398 return -ECONNABORTED;
2399 }
2400
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002401 if (pdu_length + 4 > CIFSMaxBufSize + MAX_HEADER_SIZE(server))
2402 return receive_encrypted_read(server, mid);
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002403
2404 return receive_encrypted_standard(server, mid);
2405}
2406
2407int
2408smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
2409{
2410 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
2411
2412 return handle_read_data(server, mid, buf, get_rfc1002_length(buf) + 4,
2413 NULL, 0, 0);
2414}
2415
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002416struct smb_version_operations smb20_operations = {
2417 .compare_fids = smb2_compare_fids,
2418 .setup_request = smb2_setup_request,
2419 .setup_async_request = smb2_setup_async_request,
2420 .check_receive = smb2_check_receive,
2421 .add_credits = smb2_add_credits,
2422 .set_credits = smb2_set_credits,
2423 .get_credits_field = smb2_get_credits_field,
2424 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04002425 .wait_mtu_credits = cifs_wait_mtu_credits,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002426 .get_next_mid = smb2_get_next_mid,
2427 .read_data_offset = smb2_read_data_offset,
2428 .read_data_length = smb2_read_data_length,
2429 .map_error = map_smb2_to_linux_error,
2430 .find_mid = smb2_find_mid,
2431 .check_message = smb2_check_message,
2432 .dump_detail = smb2_dump_detail,
2433 .clear_stats = smb2_clear_stats,
2434 .print_stats = smb2_print_stats,
2435 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08002436 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00002437 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002438 .need_neg = smb2_need_neg,
2439 .negotiate = smb2_negotiate,
2440 .negotiate_wsize = smb2_negotiate_wsize,
2441 .negotiate_rsize = smb2_negotiate_rsize,
2442 .sess_setup = SMB2_sess_setup,
2443 .logoff = SMB2_logoff,
2444 .tree_connect = SMB2_tcon,
2445 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05002446 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002447 .is_path_accessible = smb2_is_path_accessible,
2448 .can_echo = smb2_can_echo,
2449 .echo = SMB2_echo,
2450 .query_path_info = smb2_query_path_info,
2451 .get_srv_inum = smb2_get_srv_inum,
2452 .query_file_info = smb2_query_file_info,
2453 .set_path_size = smb2_set_path_size,
2454 .set_file_size = smb2_set_file_size,
2455 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05002456 .set_compression = smb2_set_compression,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002457 .mkdir = smb2_mkdir,
2458 .mkdir_setinfo = smb2_mkdir_setinfo,
2459 .rmdir = smb2_rmdir,
2460 .unlink = smb2_unlink,
2461 .rename = smb2_rename_path,
2462 .create_hardlink = smb2_create_hardlink,
2463 .query_symlink = smb2_query_symlink,
Sachin Prabhu5b23c972016-07-11 16:53:20 +01002464 .query_mf_symlink = smb3_query_mf_symlink,
2465 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002466 .open = smb2_open_file,
2467 .set_fid = smb2_set_fid,
2468 .close = smb2_close_file,
2469 .flush = smb2_flush_file,
2470 .async_readv = smb2_async_readv,
2471 .async_writev = smb2_async_writev,
2472 .sync_read = smb2_sync_read,
2473 .sync_write = smb2_sync_write,
2474 .query_dir_first = smb2_query_dir_first,
2475 .query_dir_next = smb2_query_dir_next,
2476 .close_dir = smb2_close_dir,
2477 .calc_smb_size = smb2_calc_size,
2478 .is_status_pending = smb2_is_status_pending,
2479 .oplock_response = smb2_oplock_response,
2480 .queryfs = smb2_queryfs,
2481 .mand_lock = smb2_mand_lock,
2482 .mand_unlock_range = smb2_unlock_range,
2483 .push_mand_locks = smb2_push_mandatory_locks,
2484 .get_lease_key = smb2_get_lease_key,
2485 .set_lease_key = smb2_set_lease_key,
2486 .new_lease_key = smb2_new_lease_key,
2487 .calc_signature = smb2_calc_signature,
2488 .is_read_op = smb2_is_read_op,
2489 .set_oplock_level = smb2_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04002490 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002491 .parse_lease_buf = smb2_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05002492 .copychunk_range = smb2_copychunk_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002493 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04002494 .dir_needs_close = smb2_dir_needs_close,
Aurelien Aptel9d496402017-02-13 16:16:49 +01002495 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05302496 .select_sectype = smb2_select_sectype,
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002497#ifdef CONFIG_CIFS_ACL
2498 .get_acl = get_smb2_acl,
2499 .get_acl_by_fid = get_smb2_acl_by_fid,
2500/* .set_acl = set_smb3_acl, */
2501#endif /* CIFS_ACL */
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002502};
2503
Steve French1080ef72011-02-24 18:07:19 +00002504struct smb_version_operations smb21_operations = {
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07002505 .compare_fids = smb2_compare_fids,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04002506 .setup_request = smb2_setup_request,
Pavel Shilovskyc95b8ee2012-07-11 14:45:28 +04002507 .setup_async_request = smb2_setup_async_request,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04002508 .check_receive = smb2_check_receive,
Pavel Shilovsky28ea5292012-05-23 16:18:00 +04002509 .add_credits = smb2_add_credits,
2510 .set_credits = smb2_set_credits,
2511 .get_credits_field = smb2_get_credits_field,
2512 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04002513 .wait_mtu_credits = smb2_wait_mtu_credits,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04002514 .get_next_mid = smb2_get_next_mid,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07002515 .read_data_offset = smb2_read_data_offset,
2516 .read_data_length = smb2_read_data_length,
2517 .map_error = map_smb2_to_linux_error,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04002518 .find_mid = smb2_find_mid,
2519 .check_message = smb2_check_message,
2520 .dump_detail = smb2_dump_detail,
Pavel Shilovskyd60622e2012-05-28 15:19:39 +04002521 .clear_stats = smb2_clear_stats,
2522 .print_stats = smb2_print_stats,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07002523 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08002524 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00002525 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovskyec2e4522011-12-27 16:12:43 +04002526 .need_neg = smb2_need_neg,
2527 .negotiate = smb2_negotiate,
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -07002528 .negotiate_wsize = smb2_negotiate_wsize,
2529 .negotiate_rsize = smb2_negotiate_rsize,
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +04002530 .sess_setup = SMB2_sess_setup,
2531 .logoff = SMB2_logoff,
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +04002532 .tree_connect = SMB2_tcon,
2533 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05002534 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04002535 .is_path_accessible = smb2_is_path_accessible,
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04002536 .can_echo = smb2_can_echo,
2537 .echo = SMB2_echo,
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04002538 .query_path_info = smb2_query_path_info,
2539 .get_srv_inum = smb2_get_srv_inum,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -07002540 .query_file_info = smb2_query_file_info,
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07002541 .set_path_size = smb2_set_path_size,
2542 .set_file_size = smb2_set_file_size,
Pavel Shilovsky1feeaac2012-09-18 16:20:32 -07002543 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05002544 .set_compression = smb2_set_compression,
Pavel Shilovskya0e73182011-07-19 12:56:37 +04002545 .mkdir = smb2_mkdir,
2546 .mkdir_setinfo = smb2_mkdir_setinfo,
Pavel Shilovsky1a500f02012-07-10 16:14:38 +04002547 .rmdir = smb2_rmdir,
Pavel Shilovskycbe6f432012-09-18 16:20:25 -07002548 .unlink = smb2_unlink,
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07002549 .rename = smb2_rename_path,
Pavel Shilovsky568798c2012-09-18 16:20:31 -07002550 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04002551 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05002552 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05002553 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07002554 .open = smb2_open_file,
2555 .set_fid = smb2_set_fid,
2556 .close = smb2_close_file,
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07002557 .flush = smb2_flush_file,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07002558 .async_readv = smb2_async_readv,
Pavel Shilovsky33319142012-09-18 16:20:29 -07002559 .async_writev = smb2_async_writev,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -07002560 .sync_read = smb2_sync_read,
Pavel Shilovsky009d3442012-09-18 16:20:30 -07002561 .sync_write = smb2_sync_write,
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07002562 .query_dir_first = smb2_query_dir_first,
2563 .query_dir_next = smb2_query_dir_next,
2564 .close_dir = smb2_close_dir,
2565 .calc_smb_size = smb2_calc_size,
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07002566 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07002567 .oplock_response = smb2_oplock_response,
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07002568 .queryfs = smb2_queryfs,
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07002569 .mand_lock = smb2_mand_lock,
2570 .mand_unlock_range = smb2_unlock_range,
Pavel Shilovskyb1407992012-09-19 06:22:44 -07002571 .push_mand_locks = smb2_push_mandatory_locks,
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07002572 .get_lease_key = smb2_get_lease_key,
2573 .set_lease_key = smb2_set_lease_key,
2574 .new_lease_key = smb2_new_lease_key,
Steve French38107d42012-12-08 22:08:06 -06002575 .calc_signature = smb2_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002576 .is_read_op = smb21_is_read_op,
2577 .set_oplock_level = smb21_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04002578 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002579 .parse_lease_buf = smb2_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05002580 .copychunk_range = smb2_copychunk_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002581 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04002582 .dir_needs_close = smb2_dir_needs_close,
Steve French834170c2016-09-30 21:14:26 -05002583 .enum_snapshots = smb3_enum_snapshots,
Aurelien Aptel9d496402017-02-13 16:16:49 +01002584 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05302585 .select_sectype = smb2_select_sectype,
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002586#ifdef CONFIG_CIFS_ACL
2587 .get_acl = get_smb2_acl,
2588 .get_acl_by_fid = get_smb2_acl_by_fid,
2589/* .set_acl = set_smb3_acl, */
2590#endif /* CIFS_ACL */
Steve French38107d42012-12-08 22:08:06 -06002591};
2592
Steve French38107d42012-12-08 22:08:06 -06002593struct smb_version_operations smb30_operations = {
2594 .compare_fids = smb2_compare_fids,
2595 .setup_request = smb2_setup_request,
2596 .setup_async_request = smb2_setup_async_request,
2597 .check_receive = smb2_check_receive,
2598 .add_credits = smb2_add_credits,
2599 .set_credits = smb2_set_credits,
2600 .get_credits_field = smb2_get_credits_field,
2601 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04002602 .wait_mtu_credits = smb2_wait_mtu_credits,
Steve French38107d42012-12-08 22:08:06 -06002603 .get_next_mid = smb2_get_next_mid,
2604 .read_data_offset = smb2_read_data_offset,
2605 .read_data_length = smb2_read_data_length,
2606 .map_error = map_smb2_to_linux_error,
2607 .find_mid = smb2_find_mid,
2608 .check_message = smb2_check_message,
2609 .dump_detail = smb2_dump_detail,
2610 .clear_stats = smb2_clear_stats,
2611 .print_stats = smb2_print_stats,
Steve French769ee6a2013-06-19 14:15:30 -05002612 .dump_share_caps = smb2_dump_share_caps,
Steve French38107d42012-12-08 22:08:06 -06002613 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08002614 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00002615 .downgrade_oplock = smb2_downgrade_oplock,
Steve French38107d42012-12-08 22:08:06 -06002616 .need_neg = smb2_need_neg,
2617 .negotiate = smb2_negotiate,
2618 .negotiate_wsize = smb2_negotiate_wsize,
2619 .negotiate_rsize = smb2_negotiate_rsize,
2620 .sess_setup = SMB2_sess_setup,
2621 .logoff = SMB2_logoff,
2622 .tree_connect = SMB2_tcon,
2623 .tree_disconnect = SMB2_tdis,
Steven Frenchaf6a12e2013-10-09 20:55:53 -05002624 .qfs_tcon = smb3_qfs_tcon,
Steve French38107d42012-12-08 22:08:06 -06002625 .is_path_accessible = smb2_is_path_accessible,
2626 .can_echo = smb2_can_echo,
2627 .echo = SMB2_echo,
2628 .query_path_info = smb2_query_path_info,
2629 .get_srv_inum = smb2_get_srv_inum,
2630 .query_file_info = smb2_query_file_info,
2631 .set_path_size = smb2_set_path_size,
2632 .set_file_size = smb2_set_file_size,
2633 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05002634 .set_compression = smb2_set_compression,
Steve French38107d42012-12-08 22:08:06 -06002635 .mkdir = smb2_mkdir,
2636 .mkdir_setinfo = smb2_mkdir_setinfo,
2637 .rmdir = smb2_rmdir,
2638 .unlink = smb2_unlink,
2639 .rename = smb2_rename_path,
2640 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04002641 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05002642 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05002643 .create_mf_symlink = smb3_create_mf_symlink,
Steve French38107d42012-12-08 22:08:06 -06002644 .open = smb2_open_file,
2645 .set_fid = smb2_set_fid,
2646 .close = smb2_close_file,
2647 .flush = smb2_flush_file,
2648 .async_readv = smb2_async_readv,
2649 .async_writev = smb2_async_writev,
2650 .sync_read = smb2_sync_read,
2651 .sync_write = smb2_sync_write,
2652 .query_dir_first = smb2_query_dir_first,
2653 .query_dir_next = smb2_query_dir_next,
2654 .close_dir = smb2_close_dir,
2655 .calc_smb_size = smb2_calc_size,
2656 .is_status_pending = smb2_is_status_pending,
2657 .oplock_response = smb2_oplock_response,
2658 .queryfs = smb2_queryfs,
2659 .mand_lock = smb2_mand_lock,
2660 .mand_unlock_range = smb2_unlock_range,
2661 .push_mand_locks = smb2_push_mandatory_locks,
2662 .get_lease_key = smb2_get_lease_key,
2663 .set_lease_key = smb2_set_lease_key,
2664 .new_lease_key = smb2_new_lease_key,
Steve French373512e2015-12-18 13:05:30 -06002665 .generate_signingkey = generate_smb30signingkey,
Steve French38107d42012-12-08 22:08:06 -06002666 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05002667 .set_integrity = smb3_set_integrity,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002668 .is_read_op = smb21_is_read_op,
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002669 .set_oplock_level = smb3_set_oplock_level,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002670 .create_lease_buf = smb3_create_lease_buf,
2671 .parse_lease_buf = smb3_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05002672 .copychunk_range = smb2_copychunk_range,
Steve Frenchca9e7a12015-10-01 21:40:10 -05002673 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchff1c0382013-11-19 23:44:46 -06002674 .validate_negotiate = smb3_validate_negotiate,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002675 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04002676 .dir_needs_close = smb2_dir_needs_close,
Steve French31742c52014-08-17 08:38:47 -05002677 .fallocate = smb3_fallocate,
Steve French834170c2016-09-30 21:14:26 -05002678 .enum_snapshots = smb3_enum_snapshots,
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002679 .init_transform_rq = smb3_init_transform_rq,
2680 .free_transform_rq = smb3_free_transform_rq,
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002681 .is_transform_hdr = smb3_is_transform_hdr,
2682 .receive_transform = smb3_receive_transform,
Aurelien Aptel9d496402017-02-13 16:16:49 +01002683 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05302684 .select_sectype = smb2_select_sectype,
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002685#ifdef CONFIG_CIFS_ACL
2686 .get_acl = get_smb2_acl,
2687 .get_acl_by_fid = get_smb2_acl_by_fid,
2688/* .set_acl = set_smb3_acl, */
2689#endif /* CIFS_ACL */
Steve French1080ef72011-02-24 18:07:19 +00002690};
2691
Steve Frenchaab18932015-06-23 23:37:11 -05002692#ifdef CONFIG_CIFS_SMB311
2693struct smb_version_operations smb311_operations = {
2694 .compare_fids = smb2_compare_fids,
2695 .setup_request = smb2_setup_request,
2696 .setup_async_request = smb2_setup_async_request,
2697 .check_receive = smb2_check_receive,
2698 .add_credits = smb2_add_credits,
2699 .set_credits = smb2_set_credits,
2700 .get_credits_field = smb2_get_credits_field,
2701 .get_credits = smb2_get_credits,
2702 .wait_mtu_credits = smb2_wait_mtu_credits,
2703 .get_next_mid = smb2_get_next_mid,
2704 .read_data_offset = smb2_read_data_offset,
2705 .read_data_length = smb2_read_data_length,
2706 .map_error = map_smb2_to_linux_error,
2707 .find_mid = smb2_find_mid,
2708 .check_message = smb2_check_message,
2709 .dump_detail = smb2_dump_detail,
2710 .clear_stats = smb2_clear_stats,
2711 .print_stats = smb2_print_stats,
2712 .dump_share_caps = smb2_dump_share_caps,
2713 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08002714 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Steve Frenchaab18932015-06-23 23:37:11 -05002715 .downgrade_oplock = smb2_downgrade_oplock,
2716 .need_neg = smb2_need_neg,
2717 .negotiate = smb2_negotiate,
2718 .negotiate_wsize = smb2_negotiate_wsize,
2719 .negotiate_rsize = smb2_negotiate_rsize,
2720 .sess_setup = SMB2_sess_setup,
2721 .logoff = SMB2_logoff,
2722 .tree_connect = SMB2_tcon,
2723 .tree_disconnect = SMB2_tdis,
2724 .qfs_tcon = smb3_qfs_tcon,
2725 .is_path_accessible = smb2_is_path_accessible,
2726 .can_echo = smb2_can_echo,
2727 .echo = SMB2_echo,
2728 .query_path_info = smb2_query_path_info,
2729 .get_srv_inum = smb2_get_srv_inum,
2730 .query_file_info = smb2_query_file_info,
2731 .set_path_size = smb2_set_path_size,
2732 .set_file_size = smb2_set_file_size,
2733 .set_file_info = smb2_set_file_info,
2734 .set_compression = smb2_set_compression,
2735 .mkdir = smb2_mkdir,
2736 .mkdir_setinfo = smb2_mkdir_setinfo,
2737 .rmdir = smb2_rmdir,
2738 .unlink = smb2_unlink,
2739 .rename = smb2_rename_path,
2740 .create_hardlink = smb2_create_hardlink,
2741 .query_symlink = smb2_query_symlink,
2742 .query_mf_symlink = smb3_query_mf_symlink,
2743 .create_mf_symlink = smb3_create_mf_symlink,
2744 .open = smb2_open_file,
2745 .set_fid = smb2_set_fid,
2746 .close = smb2_close_file,
2747 .flush = smb2_flush_file,
2748 .async_readv = smb2_async_readv,
2749 .async_writev = smb2_async_writev,
2750 .sync_read = smb2_sync_read,
2751 .sync_write = smb2_sync_write,
2752 .query_dir_first = smb2_query_dir_first,
2753 .query_dir_next = smb2_query_dir_next,
2754 .close_dir = smb2_close_dir,
2755 .calc_smb_size = smb2_calc_size,
2756 .is_status_pending = smb2_is_status_pending,
2757 .oplock_response = smb2_oplock_response,
2758 .queryfs = smb2_queryfs,
2759 .mand_lock = smb2_mand_lock,
2760 .mand_unlock_range = smb2_unlock_range,
2761 .push_mand_locks = smb2_push_mandatory_locks,
2762 .get_lease_key = smb2_get_lease_key,
2763 .set_lease_key = smb2_set_lease_key,
2764 .new_lease_key = smb2_new_lease_key,
Steve French373512e2015-12-18 13:05:30 -06002765 .generate_signingkey = generate_smb311signingkey,
Steve Frenchaab18932015-06-23 23:37:11 -05002766 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05002767 .set_integrity = smb3_set_integrity,
Steve Frenchaab18932015-06-23 23:37:11 -05002768 .is_read_op = smb21_is_read_op,
2769 .set_oplock_level = smb3_set_oplock_level,
2770 .create_lease_buf = smb3_create_lease_buf,
2771 .parse_lease_buf = smb3_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05002772 .copychunk_range = smb2_copychunk_range,
Steve French02b16662015-06-27 21:18:36 -07002773 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchaab18932015-06-23 23:37:11 -05002774/* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
2775 .wp_retry_size = smb2_wp_retry_size,
2776 .dir_needs_close = smb2_dir_needs_close,
2777 .fallocate = smb3_fallocate,
Steve French834170c2016-09-30 21:14:26 -05002778 .enum_snapshots = smb3_enum_snapshots,
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002779 .init_transform_rq = smb3_init_transform_rq,
2780 .free_transform_rq = smb3_free_transform_rq,
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002781 .is_transform_hdr = smb3_is_transform_hdr,
2782 .receive_transform = smb3_receive_transform,
Aurelien Aptel9d496402017-02-13 16:16:49 +01002783 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05302784 .select_sectype = smb2_select_sectype,
Steve Frenchaab18932015-06-23 23:37:11 -05002785};
2786#endif /* CIFS_SMB311 */
2787
Steve Frenchdd446b12012-11-28 23:21:06 -06002788struct smb_version_values smb20_values = {
2789 .version_string = SMB20_VERSION_STRING,
2790 .protocol_id = SMB20_PROT_ID,
2791 .req_capabilities = 0, /* MBZ */
2792 .large_lock_type = 0,
2793 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
2794 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
2795 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
2796 .header_size = sizeof(struct smb2_hdr),
2797 .max_header_size = MAX_SMB2_HDR_SIZE,
2798 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2799 .lock_cmd = SMB2_LOCK,
2800 .cap_unix = 0,
2801 .cap_nt_find = SMB2_NT_FIND,
2802 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton502858822013-06-27 12:45:00 -04002803 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
2804 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04002805 .create_lease_size = sizeof(struct create_lease),
Steve Frenchdd446b12012-11-28 23:21:06 -06002806};
2807
Steve French1080ef72011-02-24 18:07:19 +00002808struct smb_version_values smb21_values = {
2809 .version_string = SMB21_VERSION_STRING,
Steve Frenche4aa25e2012-10-01 12:26:22 -05002810 .protocol_id = SMB21_PROT_ID,
2811 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
2812 .large_lock_type = 0,
2813 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
2814 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
2815 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
2816 .header_size = sizeof(struct smb2_hdr),
2817 .max_header_size = MAX_SMB2_HDR_SIZE,
2818 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2819 .lock_cmd = SMB2_LOCK,
2820 .cap_unix = 0,
2821 .cap_nt_find = SMB2_NT_FIND,
2822 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton502858822013-06-27 12:45:00 -04002823 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
2824 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04002825 .create_lease_size = sizeof(struct create_lease),
Steve Frenche4aa25e2012-10-01 12:26:22 -05002826};
2827
2828struct smb_version_values smb30_values = {
2829 .version_string = SMB30_VERSION_STRING,
2830 .protocol_id = SMB30_PROT_ID,
Steve French373512e2015-12-18 13:05:30 -06002831 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07002832 .large_lock_type = 0,
2833 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
2834 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
2835 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04002836 .header_size = sizeof(struct smb2_hdr),
2837 .max_header_size = MAX_SMB2_HDR_SIZE,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07002838 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04002839 .lock_cmd = SMB2_LOCK,
Pavel Shilovsky29e20f92012-07-13 13:58:14 +04002840 .cap_unix = 0,
2841 .cap_nt_find = SMB2_NT_FIND,
2842 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton502858822013-06-27 12:45:00 -04002843 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
2844 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002845 .create_lease_size = sizeof(struct create_lease_v2),
Steve French1080ef72011-02-24 18:07:19 +00002846};
Steve French20b6d8b2013-06-12 22:48:41 -05002847
2848struct smb_version_values smb302_values = {
2849 .version_string = SMB302_VERSION_STRING,
2850 .protocol_id = SMB302_PROT_ID,
Steve French373512e2015-12-18 13:05:30 -06002851 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
Steve French20b6d8b2013-06-12 22:48:41 -05002852 .large_lock_type = 0,
2853 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
2854 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
2855 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
2856 .header_size = sizeof(struct smb2_hdr),
2857 .max_header_size = MAX_SMB2_HDR_SIZE,
2858 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2859 .lock_cmd = SMB2_LOCK,
2860 .cap_unix = 0,
2861 .cap_nt_find = SMB2_NT_FIND,
2862 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton502858822013-06-27 12:45:00 -04002863 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
2864 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002865 .create_lease_size = sizeof(struct create_lease_v2),
Steve French20b6d8b2013-06-12 22:48:41 -05002866};
Steve French5f7fbf72014-12-17 22:52:58 -06002867
2868#ifdef CONFIG_CIFS_SMB311
2869struct smb_version_values smb311_values = {
2870 .version_string = SMB311_VERSION_STRING,
2871 .protocol_id = SMB311_PROT_ID,
Steve French19558802017-06-21 16:50:20 -05002872 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
Steve French5f7fbf72014-12-17 22:52:58 -06002873 .large_lock_type = 0,
2874 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
2875 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
2876 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
2877 .header_size = sizeof(struct smb2_hdr),
2878 .max_header_size = MAX_SMB2_HDR_SIZE,
2879 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2880 .lock_cmd = SMB2_LOCK,
2881 .cap_unix = 0,
2882 .cap_nt_find = SMB2_NT_FIND,
2883 .cap_large_files = SMB2_LARGE_FILES,
2884 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
2885 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
2886 .create_lease_size = sizeof(struct create_lease_v2),
2887};
2888#endif /* SMB311 */