blob: 4656656d5c0f7b90d7c3a73aba193c548960249e [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 French1080ef72011-02-24 18:07:19 +000022#include "cifsglob.h"
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040023#include "smb2pdu.h"
24#include "smb2proto.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040025#include "cifsproto.h"
26#include "cifs_debug.h"
Pavel Shilovskyb42bf882013-08-14 19:25:21 +040027#include "cifs_unicode.h"
Pavel Shilovsky2e44b282012-09-18 16:20:33 -070028#include "smb2status.h"
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -070029#include "smb2glob.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040030
31static int
32change_conf(struct TCP_Server_Info *server)
33{
34 server->credits += server->echo_credits + server->oplock_credits;
35 server->oplock_credits = server->echo_credits = 0;
36 switch (server->credits) {
37 case 0:
38 return -1;
39 case 1:
40 server->echoes = false;
41 server->oplocks = false;
Joe Perchesf96637b2013-05-04 22:12:25 -050042 cifs_dbg(VFS, "disabling echoes and oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040043 break;
44 case 2:
45 server->echoes = true;
46 server->oplocks = false;
47 server->echo_credits = 1;
Joe Perchesf96637b2013-05-04 22:12:25 -050048 cifs_dbg(FYI, "disabling oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040049 break;
50 default:
51 server->echoes = true;
52 server->oplocks = true;
53 server->echo_credits = 1;
54 server->oplock_credits = 1;
55 }
56 server->credits -= server->echo_credits + server->oplock_credits;
57 return 0;
58}
59
60static void
61smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
62 const int optype)
63{
64 int *val, rc = 0;
65 spin_lock(&server->req_lock);
66 val = server->ops->get_credits_field(server, optype);
67 *val += add;
68 server->in_flight--;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +040069 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040070 rc = change_conf(server);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -070071 /*
72 * Sometimes server returns 0 credits on oplock break ack - we need to
73 * rebalance credits in this case.
74 */
75 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
76 server->oplocks) {
77 if (server->credits > 1) {
78 server->credits--;
79 server->oplock_credits++;
80 }
81 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040082 spin_unlock(&server->req_lock);
83 wake_up(&server->request_q);
84 if (rc)
85 cifs_reconnect(server);
86}
87
88static void
89smb2_set_credits(struct TCP_Server_Info *server, const int val)
90{
91 spin_lock(&server->req_lock);
92 server->credits = val;
93 spin_unlock(&server->req_lock);
94}
95
96static int *
97smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
98{
99 switch (optype) {
100 case CIFS_ECHO_OP:
101 return &server->echo_credits;
102 case CIFS_OBREAK_OP:
103 return &server->oplock_credits;
104 default:
105 return &server->credits;
106 }
107}
108
109static unsigned int
110smb2_get_credits(struct mid_q_entry *mid)
111{
112 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
113}
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400114
115static __u64
116smb2_get_next_mid(struct TCP_Server_Info *server)
117{
118 __u64 mid;
119 /* for SMB2 we need the current value */
120 spin_lock(&GlobalMid_Lock);
121 mid = server->CurrentMid++;
122 spin_unlock(&GlobalMid_Lock);
123 return mid;
124}
Steve French1080ef72011-02-24 18:07:19 +0000125
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400126static struct mid_q_entry *
127smb2_find_mid(struct TCP_Server_Info *server, char *buf)
128{
129 struct mid_q_entry *mid;
130 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
131
132 spin_lock(&GlobalMid_Lock);
133 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
134 if ((mid->mid == hdr->MessageId) &&
135 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
136 (mid->command == hdr->Command)) {
137 spin_unlock(&GlobalMid_Lock);
138 return mid;
139 }
140 }
141 spin_unlock(&GlobalMid_Lock);
142 return NULL;
143}
144
145static void
146smb2_dump_detail(void *buf)
147{
148#ifdef CONFIG_CIFS_DEBUG2
149 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
150
Joe Perchesf96637b2013-05-04 22:12:25 -0500151 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
152 smb->Command, smb->Status, smb->Flags, smb->MessageId,
153 smb->ProcessId);
154 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400155#endif
156}
157
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400158static bool
159smb2_need_neg(struct TCP_Server_Info *server)
160{
161 return server->max_read == 0;
162}
163
164static int
165smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
166{
167 int rc;
168 ses->server->CurrentMid = 0;
169 rc = SMB2_negotiate(xid, ses);
170 /* BB we probably don't need to retry with modern servers */
171 if (rc == -EAGAIN)
172 rc = -EHOSTDOWN;
173 return rc;
174}
175
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700176static unsigned int
177smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
178{
179 struct TCP_Server_Info *server = tcon->ses->server;
180 unsigned int wsize;
181
182 /* start with specified wsize, or default */
183 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
184 wsize = min_t(unsigned int, wsize, server->max_write);
185 /*
186 * limit write size to 2 ** 16, because we don't support multicredit
187 * requests now.
188 */
189 wsize = min_t(unsigned int, wsize, 2 << 15);
190
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700191 return wsize;
192}
193
194static unsigned int
195smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
196{
197 struct TCP_Server_Info *server = tcon->ses->server;
198 unsigned int rsize;
199
200 /* start with specified rsize, or default */
201 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
202 rsize = min_t(unsigned int, rsize, server->max_read);
203 /*
204 * limit write size to 2 ** 16, because we don't support multicredit
205 * requests now.
206 */
207 rsize = min_t(unsigned int, rsize, 2 << 15);
208
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700209 return rsize;
210}
211
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400212static int
213smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
214 struct cifs_sb_info *cifs_sb, const char *full_path)
215{
216 int rc;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400217 __le16 *utf16_path;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700218 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400219 struct cifs_open_parms oparms;
220 struct cifs_fid fid;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400221
222 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
223 if (!utf16_path)
224 return -ENOMEM;
225
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400226 oparms.tcon = tcon;
227 oparms.desired_access = FILE_READ_ATTRIBUTES;
228 oparms.disposition = FILE_OPEN;
229 oparms.create_options = 0;
230 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400231 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400232
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400233 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400234 if (rc) {
235 kfree(utf16_path);
236 return rc;
237 }
238
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400239 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400240 kfree(utf16_path);
241 return rc;
242}
243
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400244static int
245smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
246 struct cifs_sb_info *cifs_sb, const char *full_path,
247 u64 *uniqueid, FILE_ALL_INFO *data)
248{
249 *uniqueid = le64_to_cpu(data->IndexNumber);
250 return 0;
251}
252
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700253static int
254smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
255 struct cifs_fid *fid, FILE_ALL_INFO *data)
256{
257 int rc;
258 struct smb2_file_all_info *smb2_data;
259
260 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
261 GFP_KERNEL);
262 if (smb2_data == NULL)
263 return -ENOMEM;
264
265 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
266 smb2_data);
267 if (!rc)
268 move_smb2_info_to_cifs(data, smb2_data);
269 kfree(smb2_data);
270 return rc;
271}
272
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400273static bool
274smb2_can_echo(struct TCP_Server_Info *server)
275{
276 return server->echoes;
277}
278
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400279static void
280smb2_clear_stats(struct cifs_tcon *tcon)
281{
282#ifdef CONFIG_CIFS_STATS
283 int i;
284 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
285 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
286 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
287 }
288#endif
289}
290
291static void
Steve French769ee6a2013-06-19 14:15:30 -0500292smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
293{
294 seq_puts(m, "\n\tShare Capabilities:");
295 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
296 seq_puts(m, " DFS,");
297 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
298 seq_puts(m, " CONTINUOUS AVAILABILITY,");
299 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
300 seq_puts(m, " SCALEOUT,");
301 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
302 seq_puts(m, " CLUSTER,");
303 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
304 seq_puts(m, " ASYMMETRIC,");
305 if (tcon->capabilities == 0)
306 seq_puts(m, " None");
307 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
308}
309
310static void
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400311smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
312{
313#ifdef CONFIG_CIFS_STATS
314 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
315 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
316 seq_printf(m, "\nNegotiates: %d sent %d failed",
317 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
318 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
319 seq_printf(m, "\nSessionSetups: %d sent %d failed",
320 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
321 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400322 seq_printf(m, "\nLogoffs: %d sent %d failed",
323 atomic_read(&sent[SMB2_LOGOFF_HE]),
324 atomic_read(&failed[SMB2_LOGOFF_HE]));
325 seq_printf(m, "\nTreeConnects: %d sent %d failed",
326 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
327 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
328 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
329 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
330 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
331 seq_printf(m, "\nCreates: %d sent %d failed",
332 atomic_read(&sent[SMB2_CREATE_HE]),
333 atomic_read(&failed[SMB2_CREATE_HE]));
334 seq_printf(m, "\nCloses: %d sent %d failed",
335 atomic_read(&sent[SMB2_CLOSE_HE]),
336 atomic_read(&failed[SMB2_CLOSE_HE]));
337 seq_printf(m, "\nFlushes: %d sent %d failed",
338 atomic_read(&sent[SMB2_FLUSH_HE]),
339 atomic_read(&failed[SMB2_FLUSH_HE]));
340 seq_printf(m, "\nReads: %d sent %d failed",
341 atomic_read(&sent[SMB2_READ_HE]),
342 atomic_read(&failed[SMB2_READ_HE]));
343 seq_printf(m, "\nWrites: %d sent %d failed",
344 atomic_read(&sent[SMB2_WRITE_HE]),
345 atomic_read(&failed[SMB2_WRITE_HE]));
346 seq_printf(m, "\nLocks: %d sent %d failed",
347 atomic_read(&sent[SMB2_LOCK_HE]),
348 atomic_read(&failed[SMB2_LOCK_HE]));
349 seq_printf(m, "\nIOCTLs: %d sent %d failed",
350 atomic_read(&sent[SMB2_IOCTL_HE]),
351 atomic_read(&failed[SMB2_IOCTL_HE]));
352 seq_printf(m, "\nCancels: %d sent %d failed",
353 atomic_read(&sent[SMB2_CANCEL_HE]),
354 atomic_read(&failed[SMB2_CANCEL_HE]));
355 seq_printf(m, "\nEchos: %d sent %d failed",
356 atomic_read(&sent[SMB2_ECHO_HE]),
357 atomic_read(&failed[SMB2_ECHO_HE]));
358 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
359 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
360 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
361 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
362 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
363 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
364 seq_printf(m, "\nQueryInfos: %d sent %d failed",
365 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
366 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
367 seq_printf(m, "\nSetInfos: %d sent %d failed",
368 atomic_read(&sent[SMB2_SET_INFO_HE]),
369 atomic_read(&failed[SMB2_SET_INFO_HE]));
370 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
371 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
372 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
373#endif
374}
375
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700376static void
377smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
378{
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700379 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400380 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
381
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700382 cfile->fid.persistent_fid = fid->persistent_fid;
383 cfile->fid.volatile_fid = fid->volatile_fid;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400384 server->ops->set_oplock_level(cinode, oplock);
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400385 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700386}
387
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400388static void
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700389smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
390 struct cifs_fid *fid)
391{
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400392 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700393}
394
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700395static int
396smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
397 struct cifs_fid *fid)
398{
399 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
400}
401
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700402static unsigned int
403smb2_read_data_offset(char *buf)
404{
405 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
406 return rsp->DataOffset;
407}
408
409static unsigned int
410smb2_read_data_length(char *buf)
411{
412 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
413 return le32_to_cpu(rsp->DataLength);
414}
415
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700416
417static int
418smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
419 struct cifs_io_parms *parms, unsigned int *bytes_read,
420 char **buf, int *buf_type)
421{
422 parms->persistent_fid = cfile->fid.persistent_fid;
423 parms->volatile_fid = cfile->fid.volatile_fid;
424 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
425}
426
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700427static int
428smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
429 struct cifs_io_parms *parms, unsigned int *written,
430 struct kvec *iov, unsigned long nr_segs)
431{
432
433 parms->persistent_fid = cfile->fid.persistent_fid;
434 parms->volatile_fid = cfile->fid.volatile_fid;
435 return SMB2_write(xid, parms, written, iov, nr_segs);
436}
437
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700438static int
439smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
440 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
441{
442 __le64 eof = cpu_to_le64(size);
443 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
444 cfile->fid.volatile_fid, cfile->pid, &eof);
445}
446
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700447static int
448smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
449 const char *path, struct cifs_sb_info *cifs_sb,
450 struct cifs_fid *fid, __u16 search_flags,
451 struct cifs_search_info *srch_inf)
452{
453 __le16 *utf16_path;
454 int rc;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700455 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400456 struct cifs_open_parms oparms;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700457
458 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
459 if (!utf16_path)
460 return -ENOMEM;
461
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400462 oparms.tcon = tcon;
463 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
464 oparms.disposition = FILE_OPEN;
465 oparms.create_options = 0;
466 oparms.fid = fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400467 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400468
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400469 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700470 kfree(utf16_path);
471 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500472 cifs_dbg(VFS, "open dir failed\n");
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700473 return rc;
474 }
475
476 srch_inf->entries_in_buffer = 0;
477 srch_inf->index_of_last_entry = 0;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700478
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400479 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
480 fid->volatile_fid, 0, srch_inf);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700481 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500482 cifs_dbg(VFS, "query directory failed\n");
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400483 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700484 }
485 return rc;
486}
487
488static int
489smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
490 struct cifs_fid *fid, __u16 search_flags,
491 struct cifs_search_info *srch_inf)
492{
493 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
494 fid->volatile_fid, 0, srch_inf);
495}
496
497static int
498smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
499 struct cifs_fid *fid)
500{
501 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
502}
503
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700504/*
505* If we negotiate SMB2 protocol and get STATUS_PENDING - update
506* the number of credits and return true. Otherwise - return false.
507*/
508static bool
509smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
510{
511 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
512
Steve French12e8a202012-09-19 09:19:39 -0700513 if (hdr->Status != STATUS_PENDING)
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700514 return false;
515
516 if (!length) {
517 spin_lock(&server->req_lock);
518 server->credits += le16_to_cpu(hdr->CreditRequest);
519 spin_unlock(&server->req_lock);
520 wake_up(&server->request_q);
521 }
522
523 return true;
524}
525
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700526static int
527smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
528 struct cifsInodeInfo *cinode)
529{
Pavel Shilovsky0822f512012-09-19 06:22:45 -0700530 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
531 return SMB2_lease_break(0, tcon, cinode->lease_key,
532 smb2_get_lease_state(cinode));
533
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700534 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
535 fid->volatile_fid,
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400536 CIFS_CACHE_READ(cinode) ? 1 : 0);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700537}
538
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700539static int
540smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
541 struct kstatfs *buf)
542{
543 int rc;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700544 __le16 srch_path = 0; /* Null - open root of share */
545 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400546 struct cifs_open_parms oparms;
547 struct cifs_fid fid;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700548
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400549 oparms.tcon = tcon;
550 oparms.desired_access = FILE_READ_ATTRIBUTES;
551 oparms.disposition = FILE_OPEN;
552 oparms.create_options = 0;
553 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400554 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400555
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400556 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700557 if (rc)
558 return rc;
559 buf->f_type = SMB2_MAGIC_NUMBER;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400560 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
561 buf);
562 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700563 return rc;
564}
565
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -0700566static bool
567smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
568{
569 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
570 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
571}
572
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -0700573static int
574smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
575 __u64 length, __u32 type, int lock, int unlock, bool wait)
576{
577 if (unlock && !lock)
578 type = SMB2_LOCKFLAG_UNLOCK;
579 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
580 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
581 current->tgid, length, offset, type, wait);
582}
583
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700584static void
585smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
586{
587 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
588}
589
590static void
591smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
592{
593 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
594}
595
596static void
597smb2_new_lease_key(struct cifs_fid *fid)
598{
599 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
600}
601
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400602static int
603smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
604 const char *full_path, char **target_path,
605 struct cifs_sb_info *cifs_sb)
606{
607 int rc;
608 __le16 *utf16_path;
609 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
610 struct cifs_open_parms oparms;
611 struct cifs_fid fid;
612 struct smb2_err_rsp *err_buf = NULL;
613 struct smb2_symlink_err_rsp *symlink;
614 unsigned int sub_len, sub_offset;
615
616 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
617
618 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
619 if (!utf16_path)
620 return -ENOMEM;
621
622 oparms.tcon = tcon;
623 oparms.desired_access = FILE_READ_ATTRIBUTES;
624 oparms.disposition = FILE_OPEN;
625 oparms.create_options = 0;
626 oparms.fid = &fid;
627 oparms.reconnect = false;
628
629 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
630
631 if (!rc || !err_buf) {
632 kfree(utf16_path);
633 return -ENOENT;
634 }
635 /* open must fail on symlink - reset rc */
636 rc = 0;
637 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
638 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
639 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
640 *target_path = cifs_strndup_from_utf16(
641 (char *)symlink->PathBuffer + sub_offset,
642 sub_len, true, cifs_sb->local_nls);
643 if (!(*target_path)) {
644 kfree(utf16_path);
645 return -ENOMEM;
646 }
647 convert_delimiter(*target_path, '/');
648 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
649 kfree(utf16_path);
650 return rc;
651}
652
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400653static void
654smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock)
655{
656 oplock &= 0xFF;
657 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
658 return;
659 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
660 cinode->oplock = CIFS_CACHE_READ_FLG | CIFS_CACHE_WRITE_FLG |
661 CIFS_CACHE_HANDLE_FLG;
662 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
663 &cinode->vfs_inode);
664 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
665 cinode->oplock = CIFS_CACHE_READ_FLG | CIFS_CACHE_WRITE_FLG;
666 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
667 &cinode->vfs_inode);
668 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
669 cinode->oplock = CIFS_CACHE_READ_FLG;
670 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
671 &cinode->vfs_inode);
672 } else
673 cinode->oplock = 0;
674}
675
676static void
677smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock)
678{
679 char message[5] = {0};
680
681 oplock &= 0xFF;
682 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
683 return;
684
685 cinode->oplock = 0;
686 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
687 cinode->oplock |= CIFS_CACHE_READ_FLG;
688 strcat(message, "R");
689 }
690 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
691 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
692 strcat(message, "H");
693 }
694 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
695 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
696 strcat(message, "W");
697 }
698 if (!cinode->oplock)
699 strcat(message, "None");
700 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
701 &cinode->vfs_inode);
702}
703
704static bool
705smb2_is_read_op(__u32 oplock)
706{
707 return oplock == SMB2_OPLOCK_LEVEL_II;
708}
709
710static bool
711smb21_is_read_op(__u32 oplock)
712{
713 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
714 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
715}
716
717struct smb_version_operations smb20_operations = {
718 .compare_fids = smb2_compare_fids,
719 .setup_request = smb2_setup_request,
720 .setup_async_request = smb2_setup_async_request,
721 .check_receive = smb2_check_receive,
722 .add_credits = smb2_add_credits,
723 .set_credits = smb2_set_credits,
724 .get_credits_field = smb2_get_credits_field,
725 .get_credits = smb2_get_credits,
726 .get_next_mid = smb2_get_next_mid,
727 .read_data_offset = smb2_read_data_offset,
728 .read_data_length = smb2_read_data_length,
729 .map_error = map_smb2_to_linux_error,
730 .find_mid = smb2_find_mid,
731 .check_message = smb2_check_message,
732 .dump_detail = smb2_dump_detail,
733 .clear_stats = smb2_clear_stats,
734 .print_stats = smb2_print_stats,
735 .is_oplock_break = smb2_is_valid_oplock_break,
736 .need_neg = smb2_need_neg,
737 .negotiate = smb2_negotiate,
738 .negotiate_wsize = smb2_negotiate_wsize,
739 .negotiate_rsize = smb2_negotiate_rsize,
740 .sess_setup = SMB2_sess_setup,
741 .logoff = SMB2_logoff,
742 .tree_connect = SMB2_tcon,
743 .tree_disconnect = SMB2_tdis,
744 .is_path_accessible = smb2_is_path_accessible,
745 .can_echo = smb2_can_echo,
746 .echo = SMB2_echo,
747 .query_path_info = smb2_query_path_info,
748 .get_srv_inum = smb2_get_srv_inum,
749 .query_file_info = smb2_query_file_info,
750 .set_path_size = smb2_set_path_size,
751 .set_file_size = smb2_set_file_size,
752 .set_file_info = smb2_set_file_info,
753 .mkdir = smb2_mkdir,
754 .mkdir_setinfo = smb2_mkdir_setinfo,
755 .rmdir = smb2_rmdir,
756 .unlink = smb2_unlink,
757 .rename = smb2_rename_path,
758 .create_hardlink = smb2_create_hardlink,
759 .query_symlink = smb2_query_symlink,
760 .open = smb2_open_file,
761 .set_fid = smb2_set_fid,
762 .close = smb2_close_file,
763 .flush = smb2_flush_file,
764 .async_readv = smb2_async_readv,
765 .async_writev = smb2_async_writev,
766 .sync_read = smb2_sync_read,
767 .sync_write = smb2_sync_write,
768 .query_dir_first = smb2_query_dir_first,
769 .query_dir_next = smb2_query_dir_next,
770 .close_dir = smb2_close_dir,
771 .calc_smb_size = smb2_calc_size,
772 .is_status_pending = smb2_is_status_pending,
773 .oplock_response = smb2_oplock_response,
774 .queryfs = smb2_queryfs,
775 .mand_lock = smb2_mand_lock,
776 .mand_unlock_range = smb2_unlock_range,
777 .push_mand_locks = smb2_push_mandatory_locks,
778 .get_lease_key = smb2_get_lease_key,
779 .set_lease_key = smb2_set_lease_key,
780 .new_lease_key = smb2_new_lease_key,
781 .calc_signature = smb2_calc_signature,
782 .is_read_op = smb2_is_read_op,
783 .set_oplock_level = smb2_set_oplock_level,
784};
785
Steve French1080ef72011-02-24 18:07:19 +0000786struct smb_version_operations smb21_operations = {
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -0700787 .compare_fids = smb2_compare_fids,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400788 .setup_request = smb2_setup_request,
Pavel Shilovskyc95b8ee2012-07-11 14:45:28 +0400789 .setup_async_request = smb2_setup_async_request,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400790 .check_receive = smb2_check_receive,
Pavel Shilovsky28ea5292012-05-23 16:18:00 +0400791 .add_credits = smb2_add_credits,
792 .set_credits = smb2_set_credits,
793 .get_credits_field = smb2_get_credits_field,
794 .get_credits = smb2_get_credits,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400795 .get_next_mid = smb2_get_next_mid,
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700796 .read_data_offset = smb2_read_data_offset,
797 .read_data_length = smb2_read_data_length,
798 .map_error = map_smb2_to_linux_error,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400799 .find_mid = smb2_find_mid,
800 .check_message = smb2_check_message,
801 .dump_detail = smb2_dump_detail,
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400802 .clear_stats = smb2_clear_stats,
803 .print_stats = smb2_print_stats,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700804 .is_oplock_break = smb2_is_valid_oplock_break,
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400805 .need_neg = smb2_need_neg,
806 .negotiate = smb2_negotiate,
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700807 .negotiate_wsize = smb2_negotiate_wsize,
808 .negotiate_rsize = smb2_negotiate_rsize,
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400809 .sess_setup = SMB2_sess_setup,
810 .logoff = SMB2_logoff,
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400811 .tree_connect = SMB2_tcon,
812 .tree_disconnect = SMB2_tdis,
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400813 .is_path_accessible = smb2_is_path_accessible,
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400814 .can_echo = smb2_can_echo,
815 .echo = SMB2_echo,
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400816 .query_path_info = smb2_query_path_info,
817 .get_srv_inum = smb2_get_srv_inum,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700818 .query_file_info = smb2_query_file_info,
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700819 .set_path_size = smb2_set_path_size,
820 .set_file_size = smb2_set_file_size,
Pavel Shilovsky1feeaac2012-09-18 16:20:32 -0700821 .set_file_info = smb2_set_file_info,
Pavel Shilovskya0e73182011-07-19 12:56:37 +0400822 .mkdir = smb2_mkdir,
823 .mkdir_setinfo = smb2_mkdir_setinfo,
Pavel Shilovsky1a500f02012-07-10 16:14:38 +0400824 .rmdir = smb2_rmdir,
Pavel Shilovskycbe6f432012-09-18 16:20:25 -0700825 .unlink = smb2_unlink,
Pavel Shilovsky35143eb2012-09-18 16:20:31 -0700826 .rename = smb2_rename_path,
Pavel Shilovsky568798c2012-09-18 16:20:31 -0700827 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400828 .query_symlink = smb2_query_symlink,
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700829 .open = smb2_open_file,
830 .set_fid = smb2_set_fid,
831 .close = smb2_close_file,
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700832 .flush = smb2_flush_file,
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700833 .async_readv = smb2_async_readv,
Pavel Shilovsky33319142012-09-18 16:20:29 -0700834 .async_writev = smb2_async_writev,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700835 .sync_read = smb2_sync_read,
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700836 .sync_write = smb2_sync_write,
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700837 .query_dir_first = smb2_query_dir_first,
838 .query_dir_next = smb2_query_dir_next,
839 .close_dir = smb2_close_dir,
840 .calc_smb_size = smb2_calc_size,
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700841 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700842 .oplock_response = smb2_oplock_response,
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700843 .queryfs = smb2_queryfs,
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -0700844 .mand_lock = smb2_mand_lock,
845 .mand_unlock_range = smb2_unlock_range,
Pavel Shilovskyb1407992012-09-19 06:22:44 -0700846 .push_mand_locks = smb2_push_mandatory_locks,
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700847 .get_lease_key = smb2_get_lease_key,
848 .set_lease_key = smb2_set_lease_key,
849 .new_lease_key = smb2_new_lease_key,
Steve French38107d42012-12-08 22:08:06 -0600850 .calc_signature = smb2_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400851 .is_read_op = smb21_is_read_op,
852 .set_oplock_level = smb21_set_oplock_level,
Steve French38107d42012-12-08 22:08:06 -0600853};
854
Steve French38107d42012-12-08 22:08:06 -0600855struct smb_version_operations smb30_operations = {
856 .compare_fids = smb2_compare_fids,
857 .setup_request = smb2_setup_request,
858 .setup_async_request = smb2_setup_async_request,
859 .check_receive = smb2_check_receive,
860 .add_credits = smb2_add_credits,
861 .set_credits = smb2_set_credits,
862 .get_credits_field = smb2_get_credits_field,
863 .get_credits = smb2_get_credits,
864 .get_next_mid = smb2_get_next_mid,
865 .read_data_offset = smb2_read_data_offset,
866 .read_data_length = smb2_read_data_length,
867 .map_error = map_smb2_to_linux_error,
868 .find_mid = smb2_find_mid,
869 .check_message = smb2_check_message,
870 .dump_detail = smb2_dump_detail,
871 .clear_stats = smb2_clear_stats,
872 .print_stats = smb2_print_stats,
Steve French769ee6a2013-06-19 14:15:30 -0500873 .dump_share_caps = smb2_dump_share_caps,
Steve French38107d42012-12-08 22:08:06 -0600874 .is_oplock_break = smb2_is_valid_oplock_break,
875 .need_neg = smb2_need_neg,
876 .negotiate = smb2_negotiate,
877 .negotiate_wsize = smb2_negotiate_wsize,
878 .negotiate_rsize = smb2_negotiate_rsize,
879 .sess_setup = SMB2_sess_setup,
880 .logoff = SMB2_logoff,
881 .tree_connect = SMB2_tcon,
882 .tree_disconnect = SMB2_tdis,
883 .is_path_accessible = smb2_is_path_accessible,
884 .can_echo = smb2_can_echo,
885 .echo = SMB2_echo,
886 .query_path_info = smb2_query_path_info,
887 .get_srv_inum = smb2_get_srv_inum,
888 .query_file_info = smb2_query_file_info,
889 .set_path_size = smb2_set_path_size,
890 .set_file_size = smb2_set_file_size,
891 .set_file_info = smb2_set_file_info,
892 .mkdir = smb2_mkdir,
893 .mkdir_setinfo = smb2_mkdir_setinfo,
894 .rmdir = smb2_rmdir,
895 .unlink = smb2_unlink,
896 .rename = smb2_rename_path,
897 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400898 .query_symlink = smb2_query_symlink,
Steve French38107d42012-12-08 22:08:06 -0600899 .open = smb2_open_file,
900 .set_fid = smb2_set_fid,
901 .close = smb2_close_file,
902 .flush = smb2_flush_file,
903 .async_readv = smb2_async_readv,
904 .async_writev = smb2_async_writev,
905 .sync_read = smb2_sync_read,
906 .sync_write = smb2_sync_write,
907 .query_dir_first = smb2_query_dir_first,
908 .query_dir_next = smb2_query_dir_next,
909 .close_dir = smb2_close_dir,
910 .calc_smb_size = smb2_calc_size,
911 .is_status_pending = smb2_is_status_pending,
912 .oplock_response = smb2_oplock_response,
913 .queryfs = smb2_queryfs,
914 .mand_lock = smb2_mand_lock,
915 .mand_unlock_range = smb2_unlock_range,
916 .push_mand_locks = smb2_push_mandatory_locks,
917 .get_lease_key = smb2_get_lease_key,
918 .set_lease_key = smb2_set_lease_key,
919 .new_lease_key = smb2_new_lease_key,
Steve Frenche65a5cb2013-06-27 01:06:50 -0500920 .generate_signingkey = generate_smb3signingkey,
Steve French38107d42012-12-08 22:08:06 -0600921 .calc_signature = smb3_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400922 .is_read_op = smb21_is_read_op,
923 .set_oplock_level = smb21_set_oplock_level,
Steve French1080ef72011-02-24 18:07:19 +0000924};
925
Steve Frenchdd446b12012-11-28 23:21:06 -0600926struct smb_version_values smb20_values = {
927 .version_string = SMB20_VERSION_STRING,
928 .protocol_id = SMB20_PROT_ID,
929 .req_capabilities = 0, /* MBZ */
930 .large_lock_type = 0,
931 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
932 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
933 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
934 .header_size = sizeof(struct smb2_hdr),
935 .max_header_size = MAX_SMB2_HDR_SIZE,
936 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
937 .lock_cmd = SMB2_LOCK,
938 .cap_unix = 0,
939 .cap_nt_find = SMB2_NT_FIND,
940 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -0400941 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
942 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Steve Frenchdd446b12012-11-28 23:21:06 -0600943};
944
Steve French1080ef72011-02-24 18:07:19 +0000945struct smb_version_values smb21_values = {
946 .version_string = SMB21_VERSION_STRING,
Steve Frenche4aa25e2012-10-01 12:26:22 -0500947 .protocol_id = SMB21_PROT_ID,
948 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
949 .large_lock_type = 0,
950 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
951 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
952 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
953 .header_size = sizeof(struct smb2_hdr),
954 .max_header_size = MAX_SMB2_HDR_SIZE,
955 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
956 .lock_cmd = SMB2_LOCK,
957 .cap_unix = 0,
958 .cap_nt_find = SMB2_NT_FIND,
959 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -0400960 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
961 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Steve Frenche4aa25e2012-10-01 12:26:22 -0500962};
963
964struct smb_version_values smb30_values = {
965 .version_string = SMB30_VERSION_STRING,
966 .protocol_id = SMB30_PROT_ID,
967 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -0700968 .large_lock_type = 0,
969 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
970 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
971 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400972 .header_size = sizeof(struct smb2_hdr),
973 .max_header_size = MAX_SMB2_HDR_SIZE,
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700974 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400975 .lock_cmd = SMB2_LOCK,
Pavel Shilovsky29e20f92012-07-13 13:58:14 +0400976 .cap_unix = 0,
977 .cap_nt_find = SMB2_NT_FIND,
978 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -0400979 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
980 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Steve French1080ef72011-02-24 18:07:19 +0000981};
Steve French20b6d8b2013-06-12 22:48:41 -0500982
983struct smb_version_values smb302_values = {
984 .version_string = SMB302_VERSION_STRING,
985 .protocol_id = SMB302_PROT_ID,
986 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
987 .large_lock_type = 0,
988 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
989 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
990 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
991 .header_size = sizeof(struct smb2_hdr),
992 .max_header_size = MAX_SMB2_HDR_SIZE,
993 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
994 .lock_cmd = SMB2_LOCK,
995 .cap_unix = 0,
996 .cap_nt_find = SMB2_NT_FIND,
997 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -0400998 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
999 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Steve French20b6d8b2013-06-12 22:48:41 -05001000};