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