]>
Commit | Line | Data |
---|---|---|
1080ef75 SF |
1 | /* |
2 | * SMB2 version specific operations | |
3 | * | |
4 | * Copyright (c) 2012, Jeff Layton <[email protected]> | |
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 | ||
2503a0db PS |
212 | static int |
213 | smb2_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; | |
2503a0db | 217 | __le16 *utf16_path; |
2e44b288 | 218 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
064f6047 PS |
219 | struct cifs_open_parms oparms; |
220 | struct cifs_fid fid; | |
2503a0db PS |
221 | |
222 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | |
223 | if (!utf16_path) | |
224 | return -ENOMEM; | |
225 | ||
064f6047 PS |
226 | oparms.tcon = tcon; |
227 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
228 | oparms.disposition = FILE_OPEN; | |
229 | oparms.create_options = 0; | |
230 | oparms.fid = &fid; | |
9cbc0b73 | 231 | oparms.reconnect = false; |
064f6047 | 232 | |
b42bf888 | 233 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
2503a0db PS |
234 | if (rc) { |
235 | kfree(utf16_path); | |
236 | return rc; | |
237 | } | |
238 | ||
064f6047 | 239 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
2503a0db PS |
240 | kfree(utf16_path); |
241 | return rc; | |
242 | } | |
243 | ||
be4cb9e3 PS |
244 | static int |
245 | smb2_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 | ||
b7546bc5 PS |
253 | static int |
254 | smb2_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 | ||
9094fad1 PS |
273 | static bool |
274 | smb2_can_echo(struct TCP_Server_Info *server) | |
275 | { | |
276 | return server->echoes; | |
277 | } | |
278 | ||
d60622eb PS |
279 | static void |
280 | smb2_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 | ||
769ee6a4 SF |
291 | static void |
292 | smb2_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 | ||
d60622eb PS |
310 | static void |
311 | smb2_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])); | |
d60622eb PS |
322 | 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 | ||
f0df737e PS |
376 | static void |
377 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) | |
378 | { | |
2e44b288 | 379 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); |
53ef1016 PS |
380 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
381 | ||
f0df737e PS |
382 | cfile->fid.persistent_fid = fid->persistent_fid; |
383 | cfile->fid.volatile_fid = fid->volatile_fid; | |
53ef1016 | 384 | server->ops->set_oplock_level(cinode, oplock); |
18cceb6a | 385 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
f0df737e PS |
386 | } |
387 | ||
760ad0ca | 388 | static void |
f0df737e PS |
389 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
390 | struct cifs_fid *fid) | |
391 | { | |
760ad0ca | 392 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
f0df737e PS |
393 | } |
394 | ||
7a5cfb19 PS |
395 | static int |
396 | smb2_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 | ||
09a4707e PS |
402 | static unsigned int |
403 | smb2_read_data_offset(char *buf) | |
404 | { | |
405 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | |
406 | return rsp->DataOffset; | |
407 | } | |
408 | ||
409 | static unsigned int | |
410 | smb2_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 | ||
d8e05039 PS |
416 | |
417 | static int | |
418 | smb2_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 | ||
009d3443 PS |
427 | static int |
428 | smb2_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 | ||
c839ff24 PS |
438 | static int |
439 | smb2_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 | ||
d324f08d PS |
447 | static int |
448 | smb2_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; | |
2e44b288 | 455 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
064f6047 | 456 | struct cifs_open_parms oparms; |
d324f08d PS |
457 | |
458 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); | |
459 | if (!utf16_path) | |
460 | return -ENOMEM; | |
461 | ||
064f6047 PS |
462 | 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; | |
9cbc0b73 | 467 | oparms.reconnect = false; |
064f6047 | 468 | |
b42bf888 | 469 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
d324f08d PS |
470 | kfree(utf16_path); |
471 | if (rc) { | |
f96637be | 472 | cifs_dbg(VFS, "open dir failed\n"); |
d324f08d PS |
473 | return rc; |
474 | } | |
475 | ||
476 | srch_inf->entries_in_buffer = 0; | |
477 | srch_inf->index_of_last_entry = 0; | |
d324f08d | 478 | |
064f6047 PS |
479 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
480 | fid->volatile_fid, 0, srch_inf); | |
d324f08d | 481 | if (rc) { |
f96637be | 482 | cifs_dbg(VFS, "query directory failed\n"); |
064f6047 | 483 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
d324f08d PS |
484 | } |
485 | return rc; | |
486 | } | |
487 | ||
488 | static int | |
489 | smb2_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 | ||
497 | static int | |
498 | smb2_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 | ||
2e44b288 PS |
504 | /* |
505 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update | |
506 | * the number of credits and return true. Otherwise - return false. | |
507 | */ | |
508 | static bool | |
509 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) | |
510 | { | |
511 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; | |
512 | ||
12e8a208 | 513 | if (hdr->Status != STATUS_PENDING) |
2e44b288 PS |
514 | 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 | ||
983c88a4 PS |
526 | static int |
527 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, | |
528 | struct cifsInodeInfo *cinode) | |
529 | { | |
0822f514 PS |
530 | 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 | ||
983c88a4 PS |
534 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
535 | fid->volatile_fid, | |
18cceb6a | 536 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
983c88a4 PS |
537 | } |
538 | ||
6fc05c25 PS |
539 | static int |
540 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, | |
541 | struct kstatfs *buf) | |
542 | { | |
543 | int rc; | |
6fc05c25 PS |
544 | __le16 srch_path = 0; /* Null - open root of share */ |
545 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
064f6047 PS |
546 | struct cifs_open_parms oparms; |
547 | struct cifs_fid fid; | |
548 | ||
549 | oparms.tcon = tcon; | |
550 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
551 | oparms.disposition = FILE_OPEN; | |
552 | oparms.create_options = 0; | |
553 | oparms.fid = &fid; | |
9cbc0b73 | 554 | oparms.reconnect = false; |
6fc05c25 | 555 | |
b42bf888 | 556 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
6fc05c25 PS |
557 | if (rc) |
558 | return rc; | |
559 | buf->f_type = SMB2_MAGIC_NUMBER; | |
064f6047 PS |
560 | 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); | |
6fc05c25 PS |
563 | return rc; |
564 | } | |
565 | ||
027e8eec PS |
566 | static bool |
567 | smb2_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 | ||
f7ba7fe6 PS |
573 | static int |
574 | smb2_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 | ||
b8c32dbb PS |
584 | static void |
585 | smb2_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 | ||
590 | static void | |
591 | smb2_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 | ||
596 | static void | |
597 | smb2_new_lease_key(struct cifs_fid *fid) | |
598 | { | |
599 | get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE); | |
600 | } | |
601 | ||
b42bf888 PS |
602 | static int |
603 | smb2_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 | ||
53ef1016 PS |
653 | static void |
654 | smb2_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 | ||
676 | static void | |
677 | smb21_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 | ||
704 | static bool | |
705 | smb2_is_read_op(__u32 oplock) | |
706 | { | |
707 | return oplock == SMB2_OPLOCK_LEVEL_II; | |
708 | } | |
709 | ||
710 | static bool | |
711 | smb21_is_read_op(__u32 oplock) | |
712 | { | |
713 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && | |
714 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); | |
715 | } | |
716 | ||
f047390a PS |
717 | static __le32 |
718 | map_oplock_to_lease(u8 oplock) | |
719 | { | |
720 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) | |
721 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; | |
722 | else if (oplock == SMB2_OPLOCK_LEVEL_II) | |
723 | return SMB2_LEASE_READ_CACHING; | |
724 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) | |
725 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | | |
726 | SMB2_LEASE_WRITE_CACHING; | |
727 | return 0; | |
728 | } | |
729 | ||
a41a28bd PS |
730 | static char * |
731 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) | |
732 | { | |
733 | struct create_lease *buf; | |
734 | ||
735 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); | |
736 | if (!buf) | |
737 | return NULL; | |
738 | ||
739 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); | |
740 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); | |
f047390a | 741 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
a41a28bd PS |
742 | |
743 | buf->ccontext.DataOffset = cpu_to_le16(offsetof | |
744 | (struct create_lease, lcontext)); | |
745 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); | |
746 | buf->ccontext.NameOffset = cpu_to_le16(offsetof | |
747 | (struct create_lease, Name)); | |
748 | buf->ccontext.NameLength = cpu_to_le16(4); | |
749 | buf->Name[0] = 'R'; | |
750 | buf->Name[1] = 'q'; | |
751 | buf->Name[2] = 'L'; | |
752 | buf->Name[3] = 's'; | |
753 | return (char *)buf; | |
754 | } | |
755 | ||
f047390a PS |
756 | static char * |
757 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) | |
758 | { | |
759 | struct create_lease_v2 *buf; | |
760 | ||
761 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); | |
762 | if (!buf) | |
763 | return NULL; | |
764 | ||
765 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); | |
766 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); | |
767 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); | |
768 | ||
769 | buf->ccontext.DataOffset = cpu_to_le16(offsetof | |
770 | (struct create_lease_v2, lcontext)); | |
771 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); | |
772 | buf->ccontext.NameOffset = cpu_to_le16(offsetof | |
773 | (struct create_lease_v2, Name)); | |
774 | buf->ccontext.NameLength = cpu_to_le16(4); | |
775 | buf->Name[0] = 'R'; | |
776 | buf->Name[1] = 'q'; | |
777 | buf->Name[2] = 'L'; | |
778 | buf->Name[3] = 's'; | |
779 | return (char *)buf; | |
780 | } | |
781 | ||
b5c7cde3 PS |
782 | static __u8 |
783 | smb2_parse_lease_buf(void *buf) | |
784 | { | |
785 | struct create_lease *lc = (struct create_lease *)buf; | |
786 | ||
787 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) | |
788 | return SMB2_OPLOCK_LEVEL_NOCHANGE; | |
789 | return le32_to_cpu(lc->lcontext.LeaseState); | |
790 | } | |
791 | ||
f047390a PS |
792 | static __u8 |
793 | smb3_parse_lease_buf(void *buf) | |
794 | { | |
795 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; | |
796 | ||
797 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) | |
798 | return SMB2_OPLOCK_LEVEL_NOCHANGE; | |
799 | return le32_to_cpu(lc->lcontext.LeaseState); | |
800 | } | |
801 | ||
53ef1016 | 802 | struct smb_version_operations smb20_operations = { |
027e8eec | 803 | .compare_fids = smb2_compare_fids, |
2dc7e1c0 | 804 | .setup_request = smb2_setup_request, |
c95b8eed | 805 | .setup_async_request = smb2_setup_async_request, |
2dc7e1c0 | 806 | .check_receive = smb2_check_receive, |
28ea5290 PS |
807 | .add_credits = smb2_add_credits, |
808 | .set_credits = smb2_set_credits, | |
809 | .get_credits_field = smb2_get_credits_field, | |
810 | .get_credits = smb2_get_credits, | |
2dc7e1c0 | 811 | .get_next_mid = smb2_get_next_mid, |
09a4707e PS |
812 | .read_data_offset = smb2_read_data_offset, |
813 | .read_data_length = smb2_read_data_length, | |
814 | .map_error = map_smb2_to_linux_error, | |
093b2bda PS |
815 | .find_mid = smb2_find_mid, |
816 | .check_message = smb2_check_message, | |
817 | .dump_detail = smb2_dump_detail, | |
d60622eb PS |
818 | .clear_stats = smb2_clear_stats, |
819 | .print_stats = smb2_print_stats, | |
983c88a4 | 820 | .is_oplock_break = smb2_is_valid_oplock_break, |
ec2e4523 PS |
821 | .need_neg = smb2_need_neg, |
822 | .negotiate = smb2_negotiate, | |
3a3bab50 PS |
823 | .negotiate_wsize = smb2_negotiate_wsize, |
824 | .negotiate_rsize = smb2_negotiate_rsize, | |
5478f9ba PS |
825 | .sess_setup = SMB2_sess_setup, |
826 | .logoff = SMB2_logoff, | |
faaf946a PS |
827 | .tree_connect = SMB2_tcon, |
828 | .tree_disconnect = SMB2_tdis, | |
2503a0db | 829 | .is_path_accessible = smb2_is_path_accessible, |
9094fad1 PS |
830 | .can_echo = smb2_can_echo, |
831 | .echo = SMB2_echo, | |
be4cb9e3 PS |
832 | .query_path_info = smb2_query_path_info, |
833 | .get_srv_inum = smb2_get_srv_inum, | |
b7546bc5 | 834 | .query_file_info = smb2_query_file_info, |
c839ff24 PS |
835 | .set_path_size = smb2_set_path_size, |
836 | .set_file_size = smb2_set_file_size, | |
1feeaac7 | 837 | .set_file_info = smb2_set_file_info, |
a0e73183 PS |
838 | .mkdir = smb2_mkdir, |
839 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
1a500f01 | 840 | .rmdir = smb2_rmdir, |
cbe6f439 | 841 | .unlink = smb2_unlink, |
35143eb5 | 842 | .rename = smb2_rename_path, |
568798cc | 843 | .create_hardlink = smb2_create_hardlink, |
b42bf888 | 844 | .query_symlink = smb2_query_symlink, |
f0df737e PS |
845 | .open = smb2_open_file, |
846 | .set_fid = smb2_set_fid, | |
847 | .close = smb2_close_file, | |
7a5cfb19 | 848 | .flush = smb2_flush_file, |
09a4707e | 849 | .async_readv = smb2_async_readv, |
33319141 | 850 | .async_writev = smb2_async_writev, |
d8e05039 | 851 | .sync_read = smb2_sync_read, |
009d3443 | 852 | .sync_write = smb2_sync_write, |
d324f08d PS |
853 | .query_dir_first = smb2_query_dir_first, |
854 | .query_dir_next = smb2_query_dir_next, | |
855 | .close_dir = smb2_close_dir, | |
856 | .calc_smb_size = smb2_calc_size, | |
2e44b288 | 857 | .is_status_pending = smb2_is_status_pending, |
983c88a4 | 858 | .oplock_response = smb2_oplock_response, |
6fc05c25 | 859 | .queryfs = smb2_queryfs, |
f7ba7fe6 PS |
860 | .mand_lock = smb2_mand_lock, |
861 | .mand_unlock_range = smb2_unlock_range, | |
b140799a | 862 | .push_mand_locks = smb2_push_mandatory_locks, |
b8c32dbb PS |
863 | .get_lease_key = smb2_get_lease_key, |
864 | .set_lease_key = smb2_set_lease_key, | |
865 | .new_lease_key = smb2_new_lease_key, | |
38107d45 | 866 | .calc_signature = smb2_calc_signature, |
53ef1016 PS |
867 | .is_read_op = smb2_is_read_op, |
868 | .set_oplock_level = smb2_set_oplock_level, | |
a41a28bd | 869 | .create_lease_buf = smb2_create_lease_buf, |
b5c7cde3 | 870 | .parse_lease_buf = smb2_parse_lease_buf, |
38107d45 SF |
871 | }; |
872 | ||
53ef1016 PS |
873 | struct smb_version_operations smb21_operations = { |
874 | .compare_fids = smb2_compare_fids, | |
875 | .setup_request = smb2_setup_request, | |
876 | .setup_async_request = smb2_setup_async_request, | |
877 | .check_receive = smb2_check_receive, | |
878 | .add_credits = smb2_add_credits, | |
879 | .set_credits = smb2_set_credits, | |
880 | .get_credits_field = smb2_get_credits_field, | |
881 | .get_credits = smb2_get_credits, | |
882 | .get_next_mid = smb2_get_next_mid, | |
883 | .read_data_offset = smb2_read_data_offset, | |
884 | .read_data_length = smb2_read_data_length, | |
885 | .map_error = map_smb2_to_linux_error, | |
886 | .find_mid = smb2_find_mid, | |
887 | .check_message = smb2_check_message, | |
888 | .dump_detail = smb2_dump_detail, | |
889 | .clear_stats = smb2_clear_stats, | |
890 | .print_stats = smb2_print_stats, | |
891 | .is_oplock_break = smb2_is_valid_oplock_break, | |
892 | .need_neg = smb2_need_neg, | |
893 | .negotiate = smb2_negotiate, | |
894 | .negotiate_wsize = smb2_negotiate_wsize, | |
895 | .negotiate_rsize = smb2_negotiate_rsize, | |
896 | .sess_setup = SMB2_sess_setup, | |
897 | .logoff = SMB2_logoff, | |
898 | .tree_connect = SMB2_tcon, | |
899 | .tree_disconnect = SMB2_tdis, | |
900 | .is_path_accessible = smb2_is_path_accessible, | |
901 | .can_echo = smb2_can_echo, | |
902 | .echo = SMB2_echo, | |
903 | .query_path_info = smb2_query_path_info, | |
904 | .get_srv_inum = smb2_get_srv_inum, | |
905 | .query_file_info = smb2_query_file_info, | |
906 | .set_path_size = smb2_set_path_size, | |
907 | .set_file_size = smb2_set_file_size, | |
908 | .set_file_info = smb2_set_file_info, | |
909 | .mkdir = smb2_mkdir, | |
910 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
911 | .rmdir = smb2_rmdir, | |
912 | .unlink = smb2_unlink, | |
913 | .rename = smb2_rename_path, | |
914 | .create_hardlink = smb2_create_hardlink, | |
915 | .query_symlink = smb2_query_symlink, | |
916 | .open = smb2_open_file, | |
917 | .set_fid = smb2_set_fid, | |
918 | .close = smb2_close_file, | |
919 | .flush = smb2_flush_file, | |
920 | .async_readv = smb2_async_readv, | |
921 | .async_writev = smb2_async_writev, | |
922 | .sync_read = smb2_sync_read, | |
923 | .sync_write = smb2_sync_write, | |
924 | .query_dir_first = smb2_query_dir_first, | |
925 | .query_dir_next = smb2_query_dir_next, | |
926 | .close_dir = smb2_close_dir, | |
927 | .calc_smb_size = smb2_calc_size, | |
928 | .is_status_pending = smb2_is_status_pending, | |
929 | .oplock_response = smb2_oplock_response, | |
930 | .queryfs = smb2_queryfs, | |
931 | .mand_lock = smb2_mand_lock, | |
932 | .mand_unlock_range = smb2_unlock_range, | |
933 | .push_mand_locks = smb2_push_mandatory_locks, | |
934 | .get_lease_key = smb2_get_lease_key, | |
935 | .set_lease_key = smb2_set_lease_key, | |
936 | .new_lease_key = smb2_new_lease_key, | |
937 | .calc_signature = smb2_calc_signature, | |
938 | .is_read_op = smb21_is_read_op, | |
939 | .set_oplock_level = smb21_set_oplock_level, | |
a41a28bd | 940 | .create_lease_buf = smb2_create_lease_buf, |
b5c7cde3 | 941 | .parse_lease_buf = smb2_parse_lease_buf, |
53ef1016 | 942 | }; |
38107d45 SF |
943 | |
944 | struct smb_version_operations smb30_operations = { | |
945 | .compare_fids = smb2_compare_fids, | |
946 | .setup_request = smb2_setup_request, | |
947 | .setup_async_request = smb2_setup_async_request, | |
948 | .check_receive = smb2_check_receive, | |
949 | .add_credits = smb2_add_credits, | |
950 | .set_credits = smb2_set_credits, | |
951 | .get_credits_field = smb2_get_credits_field, | |
952 | .get_credits = smb2_get_credits, | |
953 | .get_next_mid = smb2_get_next_mid, | |
954 | .read_data_offset = smb2_read_data_offset, | |
955 | .read_data_length = smb2_read_data_length, | |
956 | .map_error = map_smb2_to_linux_error, | |
957 | .find_mid = smb2_find_mid, | |
958 | .check_message = smb2_check_message, | |
959 | .dump_detail = smb2_dump_detail, | |
960 | .clear_stats = smb2_clear_stats, | |
961 | .print_stats = smb2_print_stats, | |
769ee6a4 | 962 | .dump_share_caps = smb2_dump_share_caps, |
38107d45 SF |
963 | .is_oplock_break = smb2_is_valid_oplock_break, |
964 | .need_neg = smb2_need_neg, | |
965 | .negotiate = smb2_negotiate, | |
966 | .negotiate_wsize = smb2_negotiate_wsize, | |
967 | .negotiate_rsize = smb2_negotiate_rsize, | |
968 | .sess_setup = SMB2_sess_setup, | |
969 | .logoff = SMB2_logoff, | |
970 | .tree_connect = SMB2_tcon, | |
971 | .tree_disconnect = SMB2_tdis, | |
972 | .is_path_accessible = smb2_is_path_accessible, | |
973 | .can_echo = smb2_can_echo, | |
974 | .echo = SMB2_echo, | |
975 | .query_path_info = smb2_query_path_info, | |
976 | .get_srv_inum = smb2_get_srv_inum, | |
977 | .query_file_info = smb2_query_file_info, | |
978 | .set_path_size = smb2_set_path_size, | |
979 | .set_file_size = smb2_set_file_size, | |
980 | .set_file_info = smb2_set_file_info, | |
981 | .mkdir = smb2_mkdir, | |
982 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
983 | .rmdir = smb2_rmdir, | |
984 | .unlink = smb2_unlink, | |
985 | .rename = smb2_rename_path, | |
986 | .create_hardlink = smb2_create_hardlink, | |
b42bf888 | 987 | .query_symlink = smb2_query_symlink, |
38107d45 SF |
988 | .open = smb2_open_file, |
989 | .set_fid = smb2_set_fid, | |
990 | .close = smb2_close_file, | |
991 | .flush = smb2_flush_file, | |
992 | .async_readv = smb2_async_readv, | |
993 | .async_writev = smb2_async_writev, | |
994 | .sync_read = smb2_sync_read, | |
995 | .sync_write = smb2_sync_write, | |
996 | .query_dir_first = smb2_query_dir_first, | |
997 | .query_dir_next = smb2_query_dir_next, | |
998 | .close_dir = smb2_close_dir, | |
999 | .calc_smb_size = smb2_calc_size, | |
1000 | .is_status_pending = smb2_is_status_pending, | |
1001 | .oplock_response = smb2_oplock_response, | |
1002 | .queryfs = smb2_queryfs, | |
1003 | .mand_lock = smb2_mand_lock, | |
1004 | .mand_unlock_range = smb2_unlock_range, | |
1005 | .push_mand_locks = smb2_push_mandatory_locks, | |
1006 | .get_lease_key = smb2_get_lease_key, | |
1007 | .set_lease_key = smb2_set_lease_key, | |
1008 | .new_lease_key = smb2_new_lease_key, | |
e65a5cb4 | 1009 | .generate_signingkey = generate_smb3signingkey, |
38107d45 | 1010 | .calc_signature = smb3_calc_signature, |
53ef1016 PS |
1011 | .is_read_op = smb21_is_read_op, |
1012 | .set_oplock_level = smb21_set_oplock_level, | |
f047390a PS |
1013 | .create_lease_buf = smb3_create_lease_buf, |
1014 | .parse_lease_buf = smb3_parse_lease_buf, | |
1080ef75 SF |
1015 | }; |
1016 | ||
dd446b16 SF |
1017 | struct smb_version_values smb20_values = { |
1018 | .version_string = SMB20_VERSION_STRING, | |
1019 | .protocol_id = SMB20_PROT_ID, | |
1020 | .req_capabilities = 0, /* MBZ */ | |
1021 | .large_lock_type = 0, | |
1022 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
1023 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
1024 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
1025 | .header_size = sizeof(struct smb2_hdr), | |
1026 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
1027 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
1028 | .lock_cmd = SMB2_LOCK, | |
1029 | .cap_unix = 0, | |
1030 | .cap_nt_find = SMB2_NT_FIND, | |
1031 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
1032 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
1033 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
a41a28bd | 1034 | .create_lease_size = sizeof(struct create_lease), |
dd446b16 SF |
1035 | }; |
1036 | ||
1080ef75 SF |
1037 | struct smb_version_values smb21_values = { |
1038 | .version_string = SMB21_VERSION_STRING, | |
e4aa25e7 SF |
1039 | .protocol_id = SMB21_PROT_ID, |
1040 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ | |
1041 | .large_lock_type = 0, | |
1042 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
1043 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
1044 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
1045 | .header_size = sizeof(struct smb2_hdr), | |
1046 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
1047 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
1048 | .lock_cmd = SMB2_LOCK, | |
1049 | .cap_unix = 0, | |
1050 | .cap_nt_find = SMB2_NT_FIND, | |
1051 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
1052 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
1053 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
a41a28bd | 1054 | .create_lease_size = sizeof(struct create_lease), |
e4aa25e7 SF |
1055 | }; |
1056 | ||
1057 | struct smb_version_values smb30_values = { | |
1058 | .version_string = SMB30_VERSION_STRING, | |
1059 | .protocol_id = SMB30_PROT_ID, | |
1060 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU, | |
027e8eec PS |
1061 | .large_lock_type = 0, |
1062 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
1063 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
1064 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
093b2bda PS |
1065 | .header_size = sizeof(struct smb2_hdr), |
1066 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
09a4707e | 1067 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
2dc7e1c0 | 1068 | .lock_cmd = SMB2_LOCK, |
29e20f9c PS |
1069 | .cap_unix = 0, |
1070 | .cap_nt_find = SMB2_NT_FIND, | |
1071 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
1072 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
1073 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
f047390a | 1074 | .create_lease_size = sizeof(struct create_lease_v2), |
1080ef75 | 1075 | }; |
20b6d8b4 SF |
1076 | |
1077 | struct smb_version_values smb302_values = { | |
1078 | .version_string = SMB302_VERSION_STRING, | |
1079 | .protocol_id = SMB302_PROT_ID, | |
1080 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU, | |
1081 | .large_lock_type = 0, | |
1082 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
1083 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
1084 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
1085 | .header_size = sizeof(struct smb2_hdr), | |
1086 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
1087 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
1088 | .lock_cmd = SMB2_LOCK, | |
1089 | .cap_unix = 0, | |
1090 | .cap_nt_find = SMB2_NT_FIND, | |
1091 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
1092 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
1093 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
f047390a | 1094 | .create_lease_size = sizeof(struct create_lease_v2), |
20b6d8b4 | 1095 | }; |