Merge tag 'v3.10.107' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / cifs / smb2ops.c
CommitLineData
1080ef75
SF
1/*
2 * SMB2 version specific operations
3 *
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
3a3bab50 20#include <linux/pagemap.h>
6fc05c25 21#include <linux/vfs.h>
1080ef75 22#include "cifsglob.h"
2dc7e1c0
PS
23#include "smb2pdu.h"
24#include "smb2proto.h"
28ea5290
PS
25#include "cifsproto.h"
26#include "cifs_debug.h"
2e44b288 27#include "smb2status.h"
6fc05c25 28#include "smb2glob.h"
28ea5290
PS
29
30static int
31change_conf(struct TCP_Server_Info *server)
32{
33 server->credits += server->echo_credits + server->oplock_credits;
34 server->oplock_credits = server->echo_credits = 0;
35 switch (server->credits) {
36 case 0:
37 return -1;
38 case 1:
39 server->echoes = false;
40 server->oplocks = false;
f96637be 41 cifs_dbg(VFS, "disabling echoes and oplocks\n");
28ea5290
PS
42 break;
43 case 2:
44 server->echoes = true;
45 server->oplocks = false;
46 server->echo_credits = 1;
f96637be 47 cifs_dbg(FYI, "disabling oplocks\n");
28ea5290
PS
48 break;
49 default:
50 server->echoes = true;
10ff4a0c
SF
51 if (enable_oplocks) {
52 server->oplocks = true;
53 server->oplock_credits = 1;
54 } else
55 server->oplocks = false;
56
28ea5290 57 server->echo_credits = 1;
28ea5290
PS
58 }
59 server->credits -= server->echo_credits + server->oplock_credits;
60 return 0;
61}
62
63static void
64smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
65 const int optype)
66{
67 int *val, rc = 0;
68 spin_lock(&server->req_lock);
69 val = server->ops->get_credits_field(server, optype);
70 *val += add;
71 server->in_flight--;
ec2e4523 72 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
28ea5290 73 rc = change_conf(server);
983c88a4
PS
74 /*
75 * Sometimes server returns 0 credits on oplock break ack - we need to
76 * rebalance credits in this case.
77 */
78 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
79 server->oplocks) {
80 if (server->credits > 1) {
81 server->credits--;
82 server->oplock_credits++;
83 }
84 }
28ea5290
PS
85 spin_unlock(&server->req_lock);
86 wake_up(&server->request_q);
87 if (rc)
88 cifs_reconnect(server);
89}
90
91static void
92smb2_set_credits(struct TCP_Server_Info *server, const int val)
93{
94 spin_lock(&server->req_lock);
95 server->credits = val;
96 spin_unlock(&server->req_lock);
97}
98
99static int *
100smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
101{
102 switch (optype) {
103 case CIFS_ECHO_OP:
104 return &server->echo_credits;
105 case CIFS_OBREAK_OP:
106 return &server->oplock_credits;
107 default:
108 return &server->credits;
109 }
110}
111
112static unsigned int
113smb2_get_credits(struct mid_q_entry *mid)
114{
115 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
116}
2dc7e1c0
PS
117
118static __u64
119smb2_get_next_mid(struct TCP_Server_Info *server)
120{
121 __u64 mid;
122 /* for SMB2 we need the current value */
123 spin_lock(&GlobalMid_Lock);
124 mid = server->CurrentMid++;
125 spin_unlock(&GlobalMid_Lock);
126 return mid;
127}
1080ef75 128
093b2bda
PS
129static struct mid_q_entry *
130smb2_find_mid(struct TCP_Server_Info *server, char *buf)
131{
132 struct mid_q_entry *mid;
133 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
134
135 spin_lock(&GlobalMid_Lock);
136 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
137 if ((mid->mid == hdr->MessageId) &&
138 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
139 (mid->command == hdr->Command)) {
140 spin_unlock(&GlobalMid_Lock);
141 return mid;
142 }
143 }
144 spin_unlock(&GlobalMid_Lock);
145 return NULL;
146}
147
148static void
149smb2_dump_detail(void *buf)
150{
151#ifdef CONFIG_CIFS_DEBUG2
152 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
153
f96637be
JP
154 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
155 smb->Command, smb->Status, smb->Flags, smb->MessageId,
156 smb->ProcessId);
157 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
093b2bda
PS
158#endif
159}
160
ec2e4523
PS
161static bool
162smb2_need_neg(struct TCP_Server_Info *server)
163{
164 return server->max_read == 0;
165}
166
167static int
168smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
169{
170 int rc;
171 ses->server->CurrentMid = 0;
172 rc = SMB2_negotiate(xid, ses);
173 /* BB we probably don't need to retry with modern servers */
174 if (rc == -EAGAIN)
175 rc = -EHOSTDOWN;
176 return rc;
177}
178
3a3bab50
PS
179static unsigned int
180smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
181{
182 struct TCP_Server_Info *server = tcon->ses->server;
183 unsigned int wsize;
184
185 /* start with specified wsize, or default */
186 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
187 wsize = min_t(unsigned int, wsize, server->max_write);
32c36d88
PS
188 /* set it to the maximum buffer size value we can send with 1 credit */
189 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
3a3bab50 190
3a3bab50
PS
191 return wsize;
192}
193
194static unsigned int
195smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
196{
197 struct TCP_Server_Info *server = tcon->ses->server;
198 unsigned int rsize;
199
200 /* start with specified rsize, or default */
201 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
202 rsize = min_t(unsigned int, rsize, server->max_read);
32c36d88
PS
203 /* set it to the maximum buffer size value we can send with 1 credit */
204 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
3a3bab50 205
3a3bab50
PS
206 return rsize;
207}
208
2503a0db
PS
209static int
210smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
211 struct cifs_sb_info *cifs_sb, const char *full_path)
212{
213 int rc;
214 __u64 persistent_fid, volatile_fid;
215 __le16 *utf16_path;
2e44b288 216 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2503a0db
PS
217
218 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
219 if (!utf16_path)
220 return -ENOMEM;
221
222 rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid,
2e44b288 223 FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL);
2503a0db
PS
224 if (rc) {
225 kfree(utf16_path);
226 return rc;
227 }
228
229 rc = SMB2_close(xid, tcon, persistent_fid, volatile_fid);
230 kfree(utf16_path);
231 return rc;
232}
233
be4cb9e3
PS
234static int
235smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
236 struct cifs_sb_info *cifs_sb, const char *full_path,
237 u64 *uniqueid, FILE_ALL_INFO *data)
238{
239 *uniqueid = le64_to_cpu(data->IndexNumber);
240 return 0;
241}
242
b7546bc5
PS
243static int
244smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
245 struct cifs_fid *fid, FILE_ALL_INFO *data)
246{
247 int rc;
248 struct smb2_file_all_info *smb2_data;
249
0c17ceb6 250 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
b7546bc5
PS
251 GFP_KERNEL);
252 if (smb2_data == NULL)
253 return -ENOMEM;
254
255 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
256 smb2_data);
257 if (!rc)
258 move_smb2_info_to_cifs(data, smb2_data);
259 kfree(smb2_data);
260 return rc;
261}
262
9094fad1
PS
263static bool
264smb2_can_echo(struct TCP_Server_Info *server)
265{
266 return server->echoes;
267}
268
d60622eb
PS
269static void
270smb2_clear_stats(struct cifs_tcon *tcon)
271{
272#ifdef CONFIG_CIFS_STATS
273 int i;
274 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
275 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
276 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
277 }
278#endif
279}
280
281static void
282smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
283{
284#ifdef CONFIG_CIFS_STATS
285 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
286 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
287 seq_printf(m, "\nNegotiates: %d sent %d failed",
288 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
289 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
290 seq_printf(m, "\nSessionSetups: %d sent %d failed",
291 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
292 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
293#define SMB2LOGOFF 0x0002 /* trivial request/resp */
294 seq_printf(m, "\nLogoffs: %d sent %d failed",
295 atomic_read(&sent[SMB2_LOGOFF_HE]),
296 atomic_read(&failed[SMB2_LOGOFF_HE]));
297 seq_printf(m, "\nTreeConnects: %d sent %d failed",
298 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
299 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
300 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
301 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
302 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
303 seq_printf(m, "\nCreates: %d sent %d failed",
304 atomic_read(&sent[SMB2_CREATE_HE]),
305 atomic_read(&failed[SMB2_CREATE_HE]));
306 seq_printf(m, "\nCloses: %d sent %d failed",
307 atomic_read(&sent[SMB2_CLOSE_HE]),
308 atomic_read(&failed[SMB2_CLOSE_HE]));
309 seq_printf(m, "\nFlushes: %d sent %d failed",
310 atomic_read(&sent[SMB2_FLUSH_HE]),
311 atomic_read(&failed[SMB2_FLUSH_HE]));
312 seq_printf(m, "\nReads: %d sent %d failed",
313 atomic_read(&sent[SMB2_READ_HE]),
314 atomic_read(&failed[SMB2_READ_HE]));
315 seq_printf(m, "\nWrites: %d sent %d failed",
316 atomic_read(&sent[SMB2_WRITE_HE]),
317 atomic_read(&failed[SMB2_WRITE_HE]));
318 seq_printf(m, "\nLocks: %d sent %d failed",
319 atomic_read(&sent[SMB2_LOCK_HE]),
320 atomic_read(&failed[SMB2_LOCK_HE]));
321 seq_printf(m, "\nIOCTLs: %d sent %d failed",
322 atomic_read(&sent[SMB2_IOCTL_HE]),
323 atomic_read(&failed[SMB2_IOCTL_HE]));
324 seq_printf(m, "\nCancels: %d sent %d failed",
325 atomic_read(&sent[SMB2_CANCEL_HE]),
326 atomic_read(&failed[SMB2_CANCEL_HE]));
327 seq_printf(m, "\nEchos: %d sent %d failed",
328 atomic_read(&sent[SMB2_ECHO_HE]),
329 atomic_read(&failed[SMB2_ECHO_HE]));
330 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
331 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
332 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
333 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
334 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
335 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
336 seq_printf(m, "\nQueryInfos: %d sent %d failed",
337 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
338 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
339 seq_printf(m, "\nSetInfos: %d sent %d failed",
340 atomic_read(&sent[SMB2_SET_INFO_HE]),
341 atomic_read(&failed[SMB2_SET_INFO_HE]));
342 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
343 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
344 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
345#endif
346}
347
f0df737e
PS
348static void
349smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
350{
2e44b288 351 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
f0df737e
PS
352 cfile->fid.persistent_fid = fid->persistent_fid;
353 cfile->fid.volatile_fid = fid->volatile_fid;
2e44b288 354 smb2_set_oplock_level(cinode, oplock);
b140799a 355 cinode->can_cache_brlcks = cinode->clientCanCacheAll;
f0df737e
PS
356}
357
760ad0ca 358static void
f0df737e
PS
359smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
360 struct cifs_fid *fid)
361{
760ad0ca 362 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
f0df737e
PS
363}
364
7a5cfb19
PS
365static int
366smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
367 struct cifs_fid *fid)
368{
369 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
370}
371
09a4707e
PS
372static unsigned int
373smb2_read_data_offset(char *buf)
374{
375 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
376 return rsp->DataOffset;
377}
378
379static unsigned int
380smb2_read_data_length(char *buf)
381{
382 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
383 return le32_to_cpu(rsp->DataLength);
384}
385
d8e05039
PS
386
387static int
388smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
389 struct cifs_io_parms *parms, unsigned int *bytes_read,
390 char **buf, int *buf_type)
391{
392 parms->persistent_fid = cfile->fid.persistent_fid;
393 parms->volatile_fid = cfile->fid.volatile_fid;
394 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
395}
396
009d3443
PS
397static int
398smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
399 struct cifs_io_parms *parms, unsigned int *written,
400 struct kvec *iov, unsigned long nr_segs)
401{
402
403 parms->persistent_fid = cfile->fid.persistent_fid;
404 parms->volatile_fid = cfile->fid.volatile_fid;
405 return SMB2_write(xid, parms, written, iov, nr_segs);
406}
407
c839ff24
PS
408static int
409smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
410 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
411{
412 __le64 eof = cpu_to_le64(size);
413 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
414 cfile->fid.volatile_fid, cfile->pid, &eof);
415}
416
d324f08d
PS
417static int
418smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
419 const char *path, struct cifs_sb_info *cifs_sb,
420 struct cifs_fid *fid, __u16 search_flags,
421 struct cifs_search_info *srch_inf)
422{
423 __le16 *utf16_path;
424 int rc;
2e44b288 425 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
d324f08d
PS
426 __u64 persistent_fid, volatile_fid;
427
428 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
429 if (!utf16_path)
430 return -ENOMEM;
431
432 rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid,
433 FILE_READ_ATTRIBUTES | FILE_READ_DATA, FILE_OPEN, 0, 0,
2e44b288 434 &oplock, NULL);
d324f08d
PS
435 kfree(utf16_path);
436 if (rc) {
f96637be 437 cifs_dbg(VFS, "open dir failed\n");
d324f08d
PS
438 return rc;
439 }
440
441 srch_inf->entries_in_buffer = 0;
442 srch_inf->index_of_last_entry = 0;
443 fid->persistent_fid = persistent_fid;
444 fid->volatile_fid = volatile_fid;
445
446 rc = SMB2_query_directory(xid, tcon, persistent_fid, volatile_fid, 0,
447 srch_inf);
448 if (rc) {
f96637be 449 cifs_dbg(VFS, "query directory failed\n");
d324f08d
PS
450 SMB2_close(xid, tcon, persistent_fid, volatile_fid);
451 }
452 return rc;
453}
454
455static int
456smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
457 struct cifs_fid *fid, __u16 search_flags,
458 struct cifs_search_info *srch_inf)
459{
460 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
461 fid->volatile_fid, 0, srch_inf);
462}
463
464static int
465smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
466 struct cifs_fid *fid)
467{
468 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
469}
470
2e44b288
PS
471/*
472* If we negotiate SMB2 protocol and get STATUS_PENDING - update
473* the number of credits and return true. Otherwise - return false.
474*/
475static bool
476smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
477{
478 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
479
12e8a208 480 if (hdr->Status != STATUS_PENDING)
2e44b288
PS
481 return false;
482
483 if (!length) {
484 spin_lock(&server->req_lock);
485 server->credits += le16_to_cpu(hdr->CreditRequest);
486 spin_unlock(&server->req_lock);
487 wake_up(&server->request_q);
488 }
489
490 return true;
491}
492
983c88a4
PS
493static int
494smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
495 struct cifsInodeInfo *cinode)
496{
0822f514
PS
497 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
498 return SMB2_lease_break(0, tcon, cinode->lease_key,
499 smb2_get_lease_state(cinode));
500
983c88a4
PS
501 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
502 fid->volatile_fid,
503 cinode->clientCanCacheRead ? 1 : 0);
504}
505
6fc05c25
PS
506static int
507smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
508 struct kstatfs *buf)
509{
510 int rc;
511 u64 persistent_fid, volatile_fid;
512 __le16 srch_path = 0; /* Null - open root of share */
513 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
514
515 rc = SMB2_open(xid, tcon, &srch_path, &persistent_fid, &volatile_fid,
516 FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL);
517 if (rc)
518 return rc;
519 buf->f_type = SMB2_MAGIC_NUMBER;
520 rc = SMB2_QFS_info(xid, tcon, persistent_fid, volatile_fid, buf);
521 SMB2_close(xid, tcon, persistent_fid, volatile_fid);
522 return rc;
523}
524
027e8eec
PS
525static bool
526smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
527{
528 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
529 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
530}
531
f7ba7fe6
PS
532static int
533smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
534 __u64 length, __u32 type, int lock, int unlock, bool wait)
535{
536 if (unlock && !lock)
537 type = SMB2_LOCKFLAG_UNLOCK;
538 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
539 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
540 current->tgid, length, offset, type, wait);
541}
542
b8c32dbb
PS
543static void
544smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
545{
546 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
547}
548
549static void
550smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
551{
552 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
553}
554
555static void
556smb2_new_lease_key(struct cifs_fid *fid)
557{
558 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
559}
560
922798d5
PS
561static bool
562smb2_dir_needs_close(struct cifsFileInfo *cfile)
563{
564 return !cfile->invalidHandle;
565}
566
1080ef75 567struct smb_version_operations smb21_operations = {
027e8eec 568 .compare_fids = smb2_compare_fids,
2dc7e1c0 569 .setup_request = smb2_setup_request,
c95b8eed 570 .setup_async_request = smb2_setup_async_request,
2dc7e1c0 571 .check_receive = smb2_check_receive,
28ea5290
PS
572 .add_credits = smb2_add_credits,
573 .set_credits = smb2_set_credits,
574 .get_credits_field = smb2_get_credits_field,
575 .get_credits = smb2_get_credits,
2dc7e1c0 576 .get_next_mid = smb2_get_next_mid,
09a4707e
PS
577 .read_data_offset = smb2_read_data_offset,
578 .read_data_length = smb2_read_data_length,
579 .map_error = map_smb2_to_linux_error,
093b2bda
PS
580 .find_mid = smb2_find_mid,
581 .check_message = smb2_check_message,
582 .dump_detail = smb2_dump_detail,
d60622eb
PS
583 .clear_stats = smb2_clear_stats,
584 .print_stats = smb2_print_stats,
983c88a4 585 .is_oplock_break = smb2_is_valid_oplock_break,
ec2e4523
PS
586 .need_neg = smb2_need_neg,
587 .negotiate = smb2_negotiate,
3a3bab50
PS
588 .negotiate_wsize = smb2_negotiate_wsize,
589 .negotiate_rsize = smb2_negotiate_rsize,
5478f9ba
PS
590 .sess_setup = SMB2_sess_setup,
591 .logoff = SMB2_logoff,
faaf946a
PS
592 .tree_connect = SMB2_tcon,
593 .tree_disconnect = SMB2_tdis,
2503a0db 594 .is_path_accessible = smb2_is_path_accessible,
9094fad1
PS
595 .can_echo = smb2_can_echo,
596 .echo = SMB2_echo,
be4cb9e3
PS
597 .query_path_info = smb2_query_path_info,
598 .get_srv_inum = smb2_get_srv_inum,
b7546bc5 599 .query_file_info = smb2_query_file_info,
c839ff24
PS
600 .set_path_size = smb2_set_path_size,
601 .set_file_size = smb2_set_file_size,
1feeaac7 602 .set_file_info = smb2_set_file_info,
a0e73183
PS
603 .mkdir = smb2_mkdir,
604 .mkdir_setinfo = smb2_mkdir_setinfo,
1a500f01 605 .rmdir = smb2_rmdir,
cbe6f439 606 .unlink = smb2_unlink,
35143eb5 607 .rename = smb2_rename_path,
568798cc 608 .create_hardlink = smb2_create_hardlink,
f0df737e
PS
609 .open = smb2_open_file,
610 .set_fid = smb2_set_fid,
611 .close = smb2_close_file,
7a5cfb19 612 .flush = smb2_flush_file,
09a4707e 613 .async_readv = smb2_async_readv,
33319141 614 .async_writev = smb2_async_writev,
d8e05039 615 .sync_read = smb2_sync_read,
009d3443 616 .sync_write = smb2_sync_write,
d324f08d
PS
617 .query_dir_first = smb2_query_dir_first,
618 .query_dir_next = smb2_query_dir_next,
619 .close_dir = smb2_close_dir,
620 .calc_smb_size = smb2_calc_size,
2e44b288 621 .is_status_pending = smb2_is_status_pending,
983c88a4 622 .oplock_response = smb2_oplock_response,
6fc05c25 623 .queryfs = smb2_queryfs,
f7ba7fe6
PS
624 .mand_lock = smb2_mand_lock,
625 .mand_unlock_range = smb2_unlock_range,
b140799a 626 .push_mand_locks = smb2_push_mandatory_locks,
b8c32dbb
PS
627 .get_lease_key = smb2_get_lease_key,
628 .set_lease_key = smb2_set_lease_key,
629 .new_lease_key = smb2_new_lease_key,
38107d45 630 .calc_signature = smb2_calc_signature,
922798d5 631 .dir_needs_close = smb2_dir_needs_close,
38107d45
SF
632};
633
634
635struct smb_version_operations smb30_operations = {
636 .compare_fids = smb2_compare_fids,
637 .setup_request = smb2_setup_request,
638 .setup_async_request = smb2_setup_async_request,
639 .check_receive = smb2_check_receive,
640 .add_credits = smb2_add_credits,
641 .set_credits = smb2_set_credits,
642 .get_credits_field = smb2_get_credits_field,
643 .get_credits = smb2_get_credits,
644 .get_next_mid = smb2_get_next_mid,
645 .read_data_offset = smb2_read_data_offset,
646 .read_data_length = smb2_read_data_length,
647 .map_error = map_smb2_to_linux_error,
648 .find_mid = smb2_find_mid,
649 .check_message = smb2_check_message,
650 .dump_detail = smb2_dump_detail,
651 .clear_stats = smb2_clear_stats,
652 .print_stats = smb2_print_stats,
653 .is_oplock_break = smb2_is_valid_oplock_break,
654 .need_neg = smb2_need_neg,
655 .negotiate = smb2_negotiate,
656 .negotiate_wsize = smb2_negotiate_wsize,
657 .negotiate_rsize = smb2_negotiate_rsize,
658 .sess_setup = SMB2_sess_setup,
659 .logoff = SMB2_logoff,
660 .tree_connect = SMB2_tcon,
661 .tree_disconnect = SMB2_tdis,
662 .is_path_accessible = smb2_is_path_accessible,
663 .can_echo = smb2_can_echo,
664 .echo = SMB2_echo,
665 .query_path_info = smb2_query_path_info,
666 .get_srv_inum = smb2_get_srv_inum,
667 .query_file_info = smb2_query_file_info,
668 .set_path_size = smb2_set_path_size,
669 .set_file_size = smb2_set_file_size,
670 .set_file_info = smb2_set_file_info,
671 .mkdir = smb2_mkdir,
672 .mkdir_setinfo = smb2_mkdir_setinfo,
673 .rmdir = smb2_rmdir,
674 .unlink = smb2_unlink,
675 .rename = smb2_rename_path,
676 .create_hardlink = smb2_create_hardlink,
677 .open = smb2_open_file,
678 .set_fid = smb2_set_fid,
679 .close = smb2_close_file,
680 .flush = smb2_flush_file,
681 .async_readv = smb2_async_readv,
682 .async_writev = smb2_async_writev,
683 .sync_read = smb2_sync_read,
684 .sync_write = smb2_sync_write,
685 .query_dir_first = smb2_query_dir_first,
686 .query_dir_next = smb2_query_dir_next,
687 .close_dir = smb2_close_dir,
688 .calc_smb_size = smb2_calc_size,
689 .is_status_pending = smb2_is_status_pending,
690 .oplock_response = smb2_oplock_response,
691 .queryfs = smb2_queryfs,
692 .mand_lock = smb2_mand_lock,
693 .mand_unlock_range = smb2_unlock_range,
694 .push_mand_locks = smb2_push_mandatory_locks,
695 .get_lease_key = smb2_get_lease_key,
696 .set_lease_key = smb2_set_lease_key,
697 .new_lease_key = smb2_new_lease_key,
698 .calc_signature = smb3_calc_signature,
922798d5 699 .dir_needs_close = smb2_dir_needs_close,
1080ef75
SF
700};
701
dd446b16
SF
702struct smb_version_values smb20_values = {
703 .version_string = SMB20_VERSION_STRING,
704 .protocol_id = SMB20_PROT_ID,
705 .req_capabilities = 0, /* MBZ */
706 .large_lock_type = 0,
707 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
708 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
709 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
710 .header_size = sizeof(struct smb2_hdr),
711 .max_header_size = MAX_SMB2_HDR_SIZE,
712 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
713 .lock_cmd = SMB2_LOCK,
714 .cap_unix = 0,
715 .cap_nt_find = SMB2_NT_FIND,
716 .cap_large_files = SMB2_LARGE_FILES,
63b7d3a4 717 .oplock_read = SMB2_OPLOCK_LEVEL_II,
dd446b16
SF
718};
719
1080ef75
SF
720struct smb_version_values smb21_values = {
721 .version_string = SMB21_VERSION_STRING,
e4aa25e7
SF
722 .protocol_id = SMB21_PROT_ID,
723 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
724 .large_lock_type = 0,
725 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
726 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
727 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
728 .header_size = sizeof(struct smb2_hdr),
729 .max_header_size = MAX_SMB2_HDR_SIZE,
730 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
731 .lock_cmd = SMB2_LOCK,
732 .cap_unix = 0,
733 .cap_nt_find = SMB2_NT_FIND,
734 .cap_large_files = SMB2_LARGE_FILES,
63b7d3a4 735 .oplock_read = SMB2_OPLOCK_LEVEL_II,
e4aa25e7
SF
736};
737
738struct smb_version_values smb30_values = {
739 .version_string = SMB30_VERSION_STRING,
740 .protocol_id = SMB30_PROT_ID,
741 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
027e8eec
PS
742 .large_lock_type = 0,
743 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
744 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
745 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
093b2bda
PS
746 .header_size = sizeof(struct smb2_hdr),
747 .max_header_size = MAX_SMB2_HDR_SIZE,
09a4707e 748 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2dc7e1c0 749 .lock_cmd = SMB2_LOCK,
29e20f9c
PS
750 .cap_unix = 0,
751 .cap_nt_find = SMB2_NT_FIND,
752 .cap_large_files = SMB2_LARGE_FILES,
067785c4 753 .oplock_read = SMB2_OPLOCK_LEVEL_II,
1080ef75 754};