]>
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> |
f29ebb47 | 22 | #include <linux/falloc.h> |
026e93dc PS |
23 | #include <linux/scatterlist.h> |
24 | #include <crypto/aead.h> | |
1080ef75 | 25 | #include "cifsglob.h" |
2dc7e1c0 PS |
26 | #include "smb2pdu.h" |
27 | #include "smb2proto.h" | |
28ea5290 PS |
28 | #include "cifsproto.h" |
29 | #include "cifs_debug.h" | |
b42bf888 | 30 | #include "cifs_unicode.h" |
2e44b288 | 31 | #include "smb2status.h" |
6fc05c25 | 32 | #include "smb2glob.h" |
834170c8 | 33 | #include "cifs_ioctl.h" |
28ea5290 PS |
34 | |
35 | static int | |
36 | change_conf(struct TCP_Server_Info *server) | |
37 | { | |
38 | server->credits += server->echo_credits + server->oplock_credits; | |
39 | server->oplock_credits = server->echo_credits = 0; | |
40 | switch (server->credits) { | |
41 | case 0: | |
42 | return -1; | |
43 | case 1: | |
44 | server->echoes = false; | |
45 | server->oplocks = false; | |
f96637be | 46 | cifs_dbg(VFS, "disabling echoes and oplocks\n"); |
28ea5290 PS |
47 | break; |
48 | case 2: | |
49 | server->echoes = true; | |
50 | server->oplocks = false; | |
51 | server->echo_credits = 1; | |
f96637be | 52 | cifs_dbg(FYI, "disabling oplocks\n"); |
28ea5290 PS |
53 | break; |
54 | default: | |
55 | server->echoes = true; | |
e0ddde9d SF |
56 | if (enable_oplocks) { |
57 | server->oplocks = true; | |
58 | server->oplock_credits = 1; | |
59 | } else | |
60 | server->oplocks = false; | |
61 | ||
28ea5290 | 62 | server->echo_credits = 1; |
28ea5290 PS |
63 | } |
64 | server->credits -= server->echo_credits + server->oplock_credits; | |
65 | return 0; | |
66 | } | |
67 | ||
68 | static void | |
69 | smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, | |
70 | const int optype) | |
71 | { | |
72 | int *val, rc = 0; | |
73 | spin_lock(&server->req_lock); | |
74 | val = server->ops->get_credits_field(server, optype); | |
75 | *val += add; | |
141891f4 SF |
76 | if (*val > 65000) { |
77 | *val = 65000; /* Don't get near 64K credits, avoid srv bugs */ | |
78 | printk_once(KERN_WARNING "server overflowed SMB3 credits\n"); | |
79 | } | |
28ea5290 | 80 | server->in_flight--; |
ec2e4523 | 81 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) |
28ea5290 | 82 | rc = change_conf(server); |
983c88a4 PS |
83 | /* |
84 | * Sometimes server returns 0 credits on oplock break ack - we need to | |
85 | * rebalance credits in this case. | |
86 | */ | |
87 | else if (server->in_flight > 0 && server->oplock_credits == 0 && | |
88 | server->oplocks) { | |
89 | if (server->credits > 1) { | |
90 | server->credits--; | |
91 | server->oplock_credits++; | |
92 | } | |
93 | } | |
28ea5290 PS |
94 | spin_unlock(&server->req_lock); |
95 | wake_up(&server->request_q); | |
96 | if (rc) | |
97 | cifs_reconnect(server); | |
98 | } | |
99 | ||
100 | static void | |
101 | smb2_set_credits(struct TCP_Server_Info *server, const int val) | |
102 | { | |
103 | spin_lock(&server->req_lock); | |
104 | server->credits = val; | |
105 | spin_unlock(&server->req_lock); | |
106 | } | |
107 | ||
108 | static int * | |
109 | smb2_get_credits_field(struct TCP_Server_Info *server, const int optype) | |
110 | { | |
111 | switch (optype) { | |
112 | case CIFS_ECHO_OP: | |
113 | return &server->echo_credits; | |
114 | case CIFS_OBREAK_OP: | |
115 | return &server->oplock_credits; | |
116 | default: | |
117 | return &server->credits; | |
118 | } | |
119 | } | |
120 | ||
121 | static unsigned int | |
122 | smb2_get_credits(struct mid_q_entry *mid) | |
123 | { | |
31473fc4 PS |
124 | struct smb2_sync_hdr *shdr = get_sync_hdr(mid->resp_buf); |
125 | ||
126 | return le16_to_cpu(shdr->CreditRequest); | |
28ea5290 | 127 | } |
2dc7e1c0 | 128 | |
cb7e9eab PS |
129 | static int |
130 | smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, | |
131 | unsigned int *num, unsigned int *credits) | |
132 | { | |
133 | int rc = 0; | |
134 | unsigned int scredits; | |
135 | ||
136 | spin_lock(&server->req_lock); | |
137 | while (1) { | |
138 | if (server->credits <= 0) { | |
139 | spin_unlock(&server->req_lock); | |
140 | cifs_num_waiters_inc(server); | |
141 | rc = wait_event_killable(server->request_q, | |
142 | has_credits(server, &server->credits)); | |
143 | cifs_num_waiters_dec(server); | |
144 | if (rc) | |
145 | return rc; | |
146 | spin_lock(&server->req_lock); | |
147 | } else { | |
148 | if (server->tcpStatus == CifsExiting) { | |
149 | spin_unlock(&server->req_lock); | |
150 | return -ENOENT; | |
151 | } | |
152 | ||
153 | scredits = server->credits; | |
154 | /* can deadlock with reopen */ | |
155 | if (scredits == 1) { | |
156 | *num = SMB2_MAX_BUFFER_SIZE; | |
157 | *credits = 0; | |
158 | break; | |
159 | } | |
160 | ||
161 | /* leave one credit for a possible reopen */ | |
162 | scredits--; | |
163 | *num = min_t(unsigned int, size, | |
164 | scredits * SMB2_MAX_BUFFER_SIZE); | |
165 | ||
166 | *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE); | |
167 | server->credits -= *credits; | |
168 | server->in_flight++; | |
169 | break; | |
170 | } | |
171 | } | |
172 | spin_unlock(&server->req_lock); | |
173 | return rc; | |
174 | } | |
175 | ||
2dc7e1c0 PS |
176 | static __u64 |
177 | smb2_get_next_mid(struct TCP_Server_Info *server) | |
178 | { | |
179 | __u64 mid; | |
180 | /* for SMB2 we need the current value */ | |
181 | spin_lock(&GlobalMid_Lock); | |
182 | mid = server->CurrentMid++; | |
183 | spin_unlock(&GlobalMid_Lock); | |
184 | return mid; | |
185 | } | |
1080ef75 | 186 | |
093b2bda PS |
187 | static struct mid_q_entry * |
188 | smb2_find_mid(struct TCP_Server_Info *server, char *buf) | |
189 | { | |
190 | struct mid_q_entry *mid; | |
31473fc4 PS |
191 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
192 | __u64 wire_mid = le64_to_cpu(shdr->MessageId); | |
093b2bda | 193 | |
31473fc4 | 194 | if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { |
373512ec SF |
195 | cifs_dbg(VFS, "encrypted frame parsing not supported yet"); |
196 | return NULL; | |
197 | } | |
198 | ||
093b2bda PS |
199 | spin_lock(&GlobalMid_Lock); |
200 | list_for_each_entry(mid, &server->pending_mid_q, qhead) { | |
9235d098 | 201 | if ((mid->mid == wire_mid) && |
093b2bda | 202 | (mid->mid_state == MID_REQUEST_SUBMITTED) && |
31473fc4 | 203 | (mid->command == shdr->Command)) { |
093b2bda PS |
204 | spin_unlock(&GlobalMid_Lock); |
205 | return mid; | |
206 | } | |
207 | } | |
208 | spin_unlock(&GlobalMid_Lock); | |
209 | return NULL; | |
210 | } | |
211 | ||
212 | static void | |
213 | smb2_dump_detail(void *buf) | |
214 | { | |
215 | #ifdef CONFIG_CIFS_DEBUG2 | |
31473fc4 | 216 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
093b2bda | 217 | |
f96637be | 218 | cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n", |
31473fc4 PS |
219 | shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId, |
220 | shdr->ProcessId); | |
221 | cifs_dbg(VFS, "smb buf %p len %u\n", buf, smb2_calc_size(buf)); | |
093b2bda PS |
222 | #endif |
223 | } | |
224 | ||
ec2e4523 PS |
225 | static bool |
226 | smb2_need_neg(struct TCP_Server_Info *server) | |
227 | { | |
228 | return server->max_read == 0; | |
229 | } | |
230 | ||
231 | static int | |
232 | smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |
233 | { | |
234 | int rc; | |
235 | ses->server->CurrentMid = 0; | |
236 | rc = SMB2_negotiate(xid, ses); | |
237 | /* BB we probably don't need to retry with modern servers */ | |
238 | if (rc == -EAGAIN) | |
239 | rc = -EHOSTDOWN; | |
240 | return rc; | |
241 | } | |
242 | ||
3a3bab50 PS |
243 | static unsigned int |
244 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | |
245 | { | |
246 | struct TCP_Server_Info *server = tcon->ses->server; | |
247 | unsigned int wsize; | |
248 | ||
249 | /* start with specified wsize, or default */ | |
250 | wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; | |
251 | wsize = min_t(unsigned int, wsize, server->max_write); | |
cb7e9eab PS |
252 | |
253 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) | |
254 | wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE); | |
3a3bab50 | 255 | |
3a3bab50 PS |
256 | return wsize; |
257 | } | |
258 | ||
259 | static unsigned int | |
260 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | |
261 | { | |
262 | struct TCP_Server_Info *server = tcon->ses->server; | |
263 | unsigned int rsize; | |
264 | ||
265 | /* start with specified rsize, or default */ | |
266 | rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; | |
267 | rsize = min_t(unsigned int, rsize, server->max_read); | |
bed9da02 PS |
268 | |
269 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) | |
270 | rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE); | |
3a3bab50 | 271 | |
3a3bab50 PS |
272 | return rsize; |
273 | } | |
274 | ||
c481e9fe SF |
275 | #ifdef CONFIG_CIFS_STATS2 |
276 | static int | |
277 | SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon) | |
278 | { | |
279 | int rc; | |
280 | unsigned int ret_data_len = 0; | |
281 | struct network_interface_info_ioctl_rsp *out_buf; | |
282 | ||
283 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, | |
284 | FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */, | |
51146625 | 285 | false /* use_ipc */, |
c481e9fe SF |
286 | NULL /* no data input */, 0 /* no data input */, |
287 | (char **)&out_buf, &ret_data_len); | |
9ffc5412 SF |
288 | if (rc != 0) |
289 | cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc); | |
290 | else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) { | |
291 | cifs_dbg(VFS, "server returned bad net interface info buf\n"); | |
292 | rc = -EINVAL; | |
293 | } else { | |
c481e9fe SF |
294 | /* Dump info on first interface */ |
295 | cifs_dbg(FYI, "Adapter Capability 0x%x\t", | |
296 | le32_to_cpu(out_buf->Capability)); | |
297 | cifs_dbg(FYI, "Link Speed %lld\n", | |
298 | le64_to_cpu(out_buf->LinkSpeed)); | |
9ffc5412 | 299 | } |
24df1483 | 300 | kfree(out_buf); |
c481e9fe SF |
301 | return rc; |
302 | } | |
303 | #endif /* STATS2 */ | |
304 | ||
af6a12ea SF |
305 | static void |
306 | smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) | |
307 | { | |
308 | int rc; | |
309 | __le16 srch_path = 0; /* Null - open root of share */ | |
310 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
311 | struct cifs_open_parms oparms; | |
312 | struct cifs_fid fid; | |
313 | ||
314 | oparms.tcon = tcon; | |
315 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
316 | oparms.disposition = FILE_OPEN; | |
317 | oparms.create_options = 0; | |
318 | oparms.fid = &fid; | |
319 | oparms.reconnect = false; | |
320 | ||
321 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); | |
322 | if (rc) | |
323 | return; | |
324 | ||
c481e9fe SF |
325 | #ifdef CONFIG_CIFS_STATS2 |
326 | SMB3_request_interfaces(xid, tcon); | |
327 | #endif /* STATS2 */ | |
328 | ||
af6a12ea SF |
329 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
330 | FS_ATTRIBUTE_INFORMATION); | |
331 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, | |
332 | FS_DEVICE_INFORMATION); | |
333 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, | |
334 | FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */ | |
335 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); | |
336 | return; | |
337 | } | |
338 | ||
34f62640 SF |
339 | static void |
340 | smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) | |
341 | { | |
342 | int rc; | |
343 | __le16 srch_path = 0; /* Null - open root of share */ | |
344 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
345 | struct cifs_open_parms oparms; | |
346 | struct cifs_fid fid; | |
347 | ||
348 | oparms.tcon = tcon; | |
349 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
350 | oparms.disposition = FILE_OPEN; | |
351 | oparms.create_options = 0; | |
352 | oparms.fid = &fid; | |
353 | oparms.reconnect = false; | |
354 | ||
355 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); | |
356 | if (rc) | |
357 | return; | |
358 | ||
2167114c SF |
359 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
360 | FS_ATTRIBUTE_INFORMATION); | |
361 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, | |
362 | FS_DEVICE_INFORMATION); | |
34f62640 SF |
363 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
364 | return; | |
365 | } | |
366 | ||
2503a0db PS |
367 | static int |
368 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, | |
369 | struct cifs_sb_info *cifs_sb, const char *full_path) | |
370 | { | |
371 | int rc; | |
2503a0db | 372 | __le16 *utf16_path; |
2e44b288 | 373 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
064f6047 PS |
374 | struct cifs_open_parms oparms; |
375 | struct cifs_fid fid; | |
2503a0db PS |
376 | |
377 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | |
378 | if (!utf16_path) | |
379 | return -ENOMEM; | |
380 | ||
064f6047 PS |
381 | oparms.tcon = tcon; |
382 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
383 | oparms.disposition = FILE_OPEN; | |
384 | oparms.create_options = 0; | |
385 | oparms.fid = &fid; | |
9cbc0b73 | 386 | oparms.reconnect = false; |
064f6047 | 387 | |
b42bf888 | 388 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
2503a0db PS |
389 | if (rc) { |
390 | kfree(utf16_path); | |
391 | return rc; | |
392 | } | |
393 | ||
064f6047 | 394 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
2503a0db PS |
395 | kfree(utf16_path); |
396 | return rc; | |
397 | } | |
398 | ||
be4cb9e3 PS |
399 | static int |
400 | smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, | |
401 | struct cifs_sb_info *cifs_sb, const char *full_path, | |
402 | u64 *uniqueid, FILE_ALL_INFO *data) | |
403 | { | |
404 | *uniqueid = le64_to_cpu(data->IndexNumber); | |
405 | return 0; | |
406 | } | |
407 | ||
b7546bc5 PS |
408 | static int |
409 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, | |
410 | struct cifs_fid *fid, FILE_ALL_INFO *data) | |
411 | { | |
412 | int rc; | |
413 | struct smb2_file_all_info *smb2_data; | |
414 | ||
1bbe4997 | 415 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
b7546bc5 PS |
416 | GFP_KERNEL); |
417 | if (smb2_data == NULL) | |
418 | return -ENOMEM; | |
419 | ||
420 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, | |
421 | smb2_data); | |
422 | if (!rc) | |
423 | move_smb2_info_to_cifs(data, smb2_data); | |
424 | kfree(smb2_data); | |
425 | return rc; | |
426 | } | |
427 | ||
9094fad1 PS |
428 | static bool |
429 | smb2_can_echo(struct TCP_Server_Info *server) | |
430 | { | |
431 | return server->echoes; | |
432 | } | |
433 | ||
d60622eb PS |
434 | static void |
435 | smb2_clear_stats(struct cifs_tcon *tcon) | |
436 | { | |
437 | #ifdef CONFIG_CIFS_STATS | |
438 | int i; | |
439 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { | |
440 | atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); | |
441 | atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); | |
442 | } | |
443 | #endif | |
444 | } | |
445 | ||
769ee6a4 SF |
446 | static void |
447 | smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) | |
448 | { | |
449 | seq_puts(m, "\n\tShare Capabilities:"); | |
450 | if (tcon->capabilities & SMB2_SHARE_CAP_DFS) | |
451 | seq_puts(m, " DFS,"); | |
452 | if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) | |
453 | seq_puts(m, " CONTINUOUS AVAILABILITY,"); | |
454 | if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) | |
455 | seq_puts(m, " SCALEOUT,"); | |
456 | if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) | |
457 | seq_puts(m, " CLUSTER,"); | |
458 | if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) | |
459 | seq_puts(m, " ASYMMETRIC,"); | |
460 | if (tcon->capabilities == 0) | |
461 | seq_puts(m, " None"); | |
af6a12ea SF |
462 | if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE) |
463 | seq_puts(m, " Aligned,"); | |
464 | if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE) | |
465 | seq_puts(m, " Partition Aligned,"); | |
466 | if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY) | |
467 | seq_puts(m, " SSD,"); | |
468 | if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED) | |
469 | seq_puts(m, " TRIM-support,"); | |
470 | ||
769ee6a4 | 471 | seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); |
af6a12ea SF |
472 | if (tcon->perf_sector_size) |
473 | seq_printf(m, "\tOptimal sector size: 0x%x", | |
474 | tcon->perf_sector_size); | |
769ee6a4 SF |
475 | } |
476 | ||
d60622eb PS |
477 | static void |
478 | smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) | |
479 | { | |
480 | #ifdef CONFIG_CIFS_STATS | |
481 | atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; | |
482 | atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; | |
483 | seq_printf(m, "\nNegotiates: %d sent %d failed", | |
484 | atomic_read(&sent[SMB2_NEGOTIATE_HE]), | |
485 | atomic_read(&failed[SMB2_NEGOTIATE_HE])); | |
486 | seq_printf(m, "\nSessionSetups: %d sent %d failed", | |
487 | atomic_read(&sent[SMB2_SESSION_SETUP_HE]), | |
488 | atomic_read(&failed[SMB2_SESSION_SETUP_HE])); | |
d60622eb PS |
489 | seq_printf(m, "\nLogoffs: %d sent %d failed", |
490 | atomic_read(&sent[SMB2_LOGOFF_HE]), | |
491 | atomic_read(&failed[SMB2_LOGOFF_HE])); | |
492 | seq_printf(m, "\nTreeConnects: %d sent %d failed", | |
493 | atomic_read(&sent[SMB2_TREE_CONNECT_HE]), | |
494 | atomic_read(&failed[SMB2_TREE_CONNECT_HE])); | |
495 | seq_printf(m, "\nTreeDisconnects: %d sent %d failed", | |
496 | atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]), | |
497 | atomic_read(&failed[SMB2_TREE_DISCONNECT_HE])); | |
498 | seq_printf(m, "\nCreates: %d sent %d failed", | |
499 | atomic_read(&sent[SMB2_CREATE_HE]), | |
500 | atomic_read(&failed[SMB2_CREATE_HE])); | |
501 | seq_printf(m, "\nCloses: %d sent %d failed", | |
502 | atomic_read(&sent[SMB2_CLOSE_HE]), | |
503 | atomic_read(&failed[SMB2_CLOSE_HE])); | |
504 | seq_printf(m, "\nFlushes: %d sent %d failed", | |
505 | atomic_read(&sent[SMB2_FLUSH_HE]), | |
506 | atomic_read(&failed[SMB2_FLUSH_HE])); | |
507 | seq_printf(m, "\nReads: %d sent %d failed", | |
508 | atomic_read(&sent[SMB2_READ_HE]), | |
509 | atomic_read(&failed[SMB2_READ_HE])); | |
510 | seq_printf(m, "\nWrites: %d sent %d failed", | |
511 | atomic_read(&sent[SMB2_WRITE_HE]), | |
512 | atomic_read(&failed[SMB2_WRITE_HE])); | |
513 | seq_printf(m, "\nLocks: %d sent %d failed", | |
514 | atomic_read(&sent[SMB2_LOCK_HE]), | |
515 | atomic_read(&failed[SMB2_LOCK_HE])); | |
516 | seq_printf(m, "\nIOCTLs: %d sent %d failed", | |
517 | atomic_read(&sent[SMB2_IOCTL_HE]), | |
518 | atomic_read(&failed[SMB2_IOCTL_HE])); | |
519 | seq_printf(m, "\nCancels: %d sent %d failed", | |
520 | atomic_read(&sent[SMB2_CANCEL_HE]), | |
521 | atomic_read(&failed[SMB2_CANCEL_HE])); | |
522 | seq_printf(m, "\nEchos: %d sent %d failed", | |
523 | atomic_read(&sent[SMB2_ECHO_HE]), | |
524 | atomic_read(&failed[SMB2_ECHO_HE])); | |
525 | seq_printf(m, "\nQueryDirectories: %d sent %d failed", | |
526 | atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]), | |
527 | atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE])); | |
528 | seq_printf(m, "\nChangeNotifies: %d sent %d failed", | |
529 | atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]), | |
530 | atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE])); | |
531 | seq_printf(m, "\nQueryInfos: %d sent %d failed", | |
532 | atomic_read(&sent[SMB2_QUERY_INFO_HE]), | |
533 | atomic_read(&failed[SMB2_QUERY_INFO_HE])); | |
534 | seq_printf(m, "\nSetInfos: %d sent %d failed", | |
535 | atomic_read(&sent[SMB2_SET_INFO_HE]), | |
536 | atomic_read(&failed[SMB2_SET_INFO_HE])); | |
537 | seq_printf(m, "\nOplockBreaks: %d sent %d failed", | |
538 | atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]), | |
539 | atomic_read(&failed[SMB2_OPLOCK_BREAK_HE])); | |
540 | #endif | |
541 | } | |
542 | ||
f0df737e PS |
543 | static void |
544 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) | |
545 | { | |
2b0143b5 | 546 | struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); |
53ef1016 PS |
547 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
548 | ||
f0df737e PS |
549 | cfile->fid.persistent_fid = fid->persistent_fid; |
550 | cfile->fid.volatile_fid = fid->volatile_fid; | |
42873b0a PS |
551 | server->ops->set_oplock_level(cinode, oplock, fid->epoch, |
552 | &fid->purge_cache); | |
18cceb6a | 553 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
94f87371 | 554 | memcpy(cfile->fid.create_guid, fid->create_guid, 16); |
f0df737e PS |
555 | } |
556 | ||
760ad0ca | 557 | static void |
f0df737e PS |
558 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
559 | struct cifs_fid *fid) | |
560 | { | |
760ad0ca | 561 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
f0df737e PS |
562 | } |
563 | ||
41c1358e SF |
564 | static int |
565 | SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, | |
566 | u64 persistent_fid, u64 volatile_fid, | |
567 | struct copychunk_ioctl *pcchunk) | |
568 | { | |
569 | int rc; | |
570 | unsigned int ret_data_len; | |
571 | struct resume_key_req *res_key; | |
572 | ||
573 | rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, | |
574 | FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */, | |
51146625 | 575 | false /* use_ipc */, |
41c1358e SF |
576 | NULL, 0 /* no input */, |
577 | (char **)&res_key, &ret_data_len); | |
578 | ||
579 | if (rc) { | |
580 | cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc); | |
581 | goto req_res_key_exit; | |
582 | } | |
583 | if (ret_data_len < sizeof(struct resume_key_req)) { | |
584 | cifs_dbg(VFS, "Invalid refcopy resume key length\n"); | |
585 | rc = -EINVAL; | |
586 | goto req_res_key_exit; | |
587 | } | |
588 | memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); | |
589 | ||
590 | req_res_key_exit: | |
591 | kfree(res_key); | |
592 | return rc; | |
593 | } | |
594 | ||
595 | static int | |
596 | smb2_clone_range(const unsigned int xid, | |
597 | struct cifsFileInfo *srcfile, | |
598 | struct cifsFileInfo *trgtfile, u64 src_off, | |
599 | u64 len, u64 dest_off) | |
600 | { | |
601 | int rc; | |
602 | unsigned int ret_data_len; | |
603 | struct copychunk_ioctl *pcchunk; | |
9bf0c9cd SF |
604 | struct copychunk_ioctl_rsp *retbuf = NULL; |
605 | struct cifs_tcon *tcon; | |
606 | int chunks_copied = 0; | |
607 | bool chunk_sizes_updated = false; | |
41c1358e SF |
608 | |
609 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); | |
610 | ||
611 | if (pcchunk == NULL) | |
612 | return -ENOMEM; | |
613 | ||
614 | cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n"); | |
615 | /* Request a key from the server to identify the source of the copy */ | |
616 | rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), | |
617 | srcfile->fid.persistent_fid, | |
618 | srcfile->fid.volatile_fid, pcchunk); | |
619 | ||
620 | /* Note: request_res_key sets res_key null only if rc !=0 */ | |
621 | if (rc) | |
9bf0c9cd | 622 | goto cchunk_out; |
41c1358e SF |
623 | |
624 | /* For now array only one chunk long, will make more flexible later */ | |
bc09d141 | 625 | pcchunk->ChunkCount = cpu_to_le32(1); |
41c1358e | 626 | pcchunk->Reserved = 0; |
41c1358e SF |
627 | pcchunk->Reserved2 = 0; |
628 | ||
9bf0c9cd | 629 | tcon = tlink_tcon(trgtfile->tlink); |
41c1358e | 630 | |
9bf0c9cd SF |
631 | while (len > 0) { |
632 | pcchunk->SourceOffset = cpu_to_le64(src_off); | |
633 | pcchunk->TargetOffset = cpu_to_le64(dest_off); | |
634 | pcchunk->Length = | |
635 | cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk)); | |
41c1358e | 636 | |
9bf0c9cd SF |
637 | /* Request server copy to target from src identified by key */ |
638 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, | |
639 | trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, | |
51146625 AA |
640 | true /* is_fsctl */, false /* use_ipc */, |
641 | (char *)pcchunk, | |
9bf0c9cd SF |
642 | sizeof(struct copychunk_ioctl), (char **)&retbuf, |
643 | &ret_data_len); | |
644 | if (rc == 0) { | |
645 | if (ret_data_len != | |
646 | sizeof(struct copychunk_ioctl_rsp)) { | |
647 | cifs_dbg(VFS, "invalid cchunk response size\n"); | |
648 | rc = -EIO; | |
649 | goto cchunk_out; | |
650 | } | |
651 | if (retbuf->TotalBytesWritten == 0) { | |
652 | cifs_dbg(FYI, "no bytes copied\n"); | |
653 | rc = -EIO; | |
654 | goto cchunk_out; | |
655 | } | |
656 | /* | |
657 | * Check if server claimed to write more than we asked | |
658 | */ | |
659 | if (le32_to_cpu(retbuf->TotalBytesWritten) > | |
660 | le32_to_cpu(pcchunk->Length)) { | |
661 | cifs_dbg(VFS, "invalid copy chunk response\n"); | |
662 | rc = -EIO; | |
663 | goto cchunk_out; | |
664 | } | |
665 | if (le32_to_cpu(retbuf->ChunksWritten) != 1) { | |
666 | cifs_dbg(VFS, "invalid num chunks written\n"); | |
667 | rc = -EIO; | |
668 | goto cchunk_out; | |
669 | } | |
670 | chunks_copied++; | |
671 | ||
672 | src_off += le32_to_cpu(retbuf->TotalBytesWritten); | |
673 | dest_off += le32_to_cpu(retbuf->TotalBytesWritten); | |
674 | len -= le32_to_cpu(retbuf->TotalBytesWritten); | |
675 | ||
676 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n", | |
677 | le32_to_cpu(retbuf->ChunksWritten), | |
678 | le32_to_cpu(retbuf->ChunkBytesWritten), | |
679 | le32_to_cpu(retbuf->TotalBytesWritten)); | |
680 | } else if (rc == -EINVAL) { | |
681 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) | |
682 | goto cchunk_out; | |
683 | ||
684 | cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n", | |
685 | le32_to_cpu(retbuf->ChunksWritten), | |
686 | le32_to_cpu(retbuf->ChunkBytesWritten), | |
687 | le32_to_cpu(retbuf->TotalBytesWritten)); | |
688 | ||
689 | /* | |
690 | * Check if this is the first request using these sizes, | |
691 | * (ie check if copy succeed once with original sizes | |
692 | * and check if the server gave us different sizes after | |
693 | * we already updated max sizes on previous request). | |
694 | * if not then why is the server returning an error now | |
695 | */ | |
696 | if ((chunks_copied != 0) || chunk_sizes_updated) | |
697 | goto cchunk_out; | |
698 | ||
699 | /* Check that server is not asking us to grow size */ | |
700 | if (le32_to_cpu(retbuf->ChunkBytesWritten) < | |
701 | tcon->max_bytes_chunk) | |
702 | tcon->max_bytes_chunk = | |
703 | le32_to_cpu(retbuf->ChunkBytesWritten); | |
704 | else | |
705 | goto cchunk_out; /* server gave us bogus size */ | |
706 | ||
707 | /* No need to change MaxChunks since already set to 1 */ | |
708 | chunk_sizes_updated = true; | |
2477bc58 SP |
709 | } else |
710 | goto cchunk_out; | |
9bf0c9cd | 711 | } |
41c1358e | 712 | |
9bf0c9cd | 713 | cchunk_out: |
41c1358e | 714 | kfree(pcchunk); |
24df1483 | 715 | kfree(retbuf); |
41c1358e SF |
716 | return rc; |
717 | } | |
718 | ||
7a5cfb19 PS |
719 | static int |
720 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, | |
721 | struct cifs_fid *fid) | |
722 | { | |
723 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); | |
724 | } | |
725 | ||
09a4707e PS |
726 | static unsigned int |
727 | smb2_read_data_offset(char *buf) | |
728 | { | |
729 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | |
730 | return rsp->DataOffset; | |
731 | } | |
732 | ||
733 | static unsigned int | |
734 | smb2_read_data_length(char *buf) | |
735 | { | |
736 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | |
737 | return le32_to_cpu(rsp->DataLength); | |
738 | } | |
739 | ||
d8e05039 PS |
740 | |
741 | static int | |
db8b631d | 742 | smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid, |
d8e05039 PS |
743 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
744 | char **buf, int *buf_type) | |
745 | { | |
db8b631d SF |
746 | parms->persistent_fid = pfid->persistent_fid; |
747 | parms->volatile_fid = pfid->volatile_fid; | |
d8e05039 PS |
748 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
749 | } | |
750 | ||
009d3443 | 751 | static int |
db8b631d | 752 | smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid, |
009d3443 PS |
753 | struct cifs_io_parms *parms, unsigned int *written, |
754 | struct kvec *iov, unsigned long nr_segs) | |
755 | { | |
756 | ||
db8b631d SF |
757 | parms->persistent_fid = pfid->persistent_fid; |
758 | parms->volatile_fid = pfid->volatile_fid; | |
009d3443 PS |
759 | return SMB2_write(xid, parms, written, iov, nr_segs); |
760 | } | |
761 | ||
d43cc793 SF |
762 | /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */ |
763 | static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, | |
764 | struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse) | |
765 | { | |
766 | struct cifsInodeInfo *cifsi; | |
767 | int rc; | |
768 | ||
769 | cifsi = CIFS_I(inode); | |
770 | ||
771 | /* if file already sparse don't bother setting sparse again */ | |
772 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse) | |
773 | return true; /* already sparse */ | |
774 | ||
775 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse) | |
776 | return true; /* already not sparse */ | |
777 | ||
778 | /* | |
779 | * Can't check for sparse support on share the usual way via the | |
780 | * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share | |
781 | * since Samba server doesn't set the flag on the share, yet | |
782 | * supports the set sparse FSCTL and returns sparse correctly | |
783 | * in the file attributes. If we fail setting sparse though we | |
784 | * mark that server does not support sparse files for this share | |
785 | * to avoid repeatedly sending the unsupported fsctl to server | |
786 | * if the file is repeatedly extended. | |
787 | */ | |
788 | if (tcon->broken_sparse_sup) | |
789 | return false; | |
790 | ||
791 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, | |
792 | cfile->fid.volatile_fid, FSCTL_SET_SPARSE, | |
51146625 AA |
793 | true /* is_fctl */, false /* use_ipc */, |
794 | &setsparse, 1, NULL, NULL); | |
d43cc793 SF |
795 | if (rc) { |
796 | tcon->broken_sparse_sup = true; | |
797 | cifs_dbg(FYI, "set sparse rc = %d\n", rc); | |
798 | return false; | |
799 | } | |
800 | ||
801 | if (setsparse) | |
802 | cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE; | |
803 | else | |
804 | cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE); | |
805 | ||
806 | return true; | |
807 | } | |
808 | ||
c839ff24 PS |
809 | static int |
810 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, | |
811 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) | |
812 | { | |
813 | __le64 eof = cpu_to_le64(size); | |
3d1a3745 SF |
814 | struct inode *inode; |
815 | ||
816 | /* | |
817 | * If extending file more than one page make sparse. Many Linux fs | |
818 | * make files sparse by default when extending via ftruncate | |
819 | */ | |
2b0143b5 | 820 | inode = d_inode(cfile->dentry); |
3d1a3745 SF |
821 | |
822 | if (!set_alloc && (size > inode->i_size + 8192)) { | |
3d1a3745 | 823 | __u8 set_sparse = 1; |
d43cc793 SF |
824 | |
825 | /* whether set sparse succeeds or not, extend the file */ | |
826 | smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); | |
3d1a3745 SF |
827 | } |
828 | ||
c839ff24 | 829 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
f29ebb47 | 830 | cfile->fid.volatile_fid, cfile->pid, &eof, false); |
c839ff24 PS |
831 | } |
832 | ||
02b16665 SF |
833 | static int |
834 | smb2_duplicate_extents(const unsigned int xid, | |
835 | struct cifsFileInfo *srcfile, | |
836 | struct cifsFileInfo *trgtfile, u64 src_off, | |
837 | u64 len, u64 dest_off) | |
838 | { | |
839 | int rc; | |
840 | unsigned int ret_data_len; | |
02b16665 SF |
841 | struct duplicate_extents_to_file dup_ext_buf; |
842 | struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); | |
843 | ||
844 | /* server fileays advertise duplicate extent support with this flag */ | |
845 | if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & | |
846 | FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0) | |
847 | return -EOPNOTSUPP; | |
848 | ||
849 | dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid; | |
850 | dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid; | |
851 | dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off); | |
852 | dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off); | |
853 | dup_ext_buf.ByteCount = cpu_to_le64(len); | |
854 | cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld", | |
855 | src_off, dest_off, len); | |
856 | ||
857 | rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); | |
858 | if (rc) | |
859 | goto duplicate_extents_out; | |
860 | ||
861 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, | |
862 | trgtfile->fid.volatile_fid, | |
863 | FSCTL_DUPLICATE_EXTENTS_TO_FILE, | |
51146625 AA |
864 | true /* is_fsctl */, false /* use_ipc */, |
865 | (char *)&dup_ext_buf, | |
02b16665 | 866 | sizeof(struct duplicate_extents_to_file), |
24df1483 | 867 | NULL, |
02b16665 SF |
868 | &ret_data_len); |
869 | ||
870 | if (ret_data_len > 0) | |
871 | cifs_dbg(FYI, "non-zero response length in duplicate extents"); | |
872 | ||
873 | duplicate_extents_out: | |
874 | return rc; | |
875 | } | |
02b16665 | 876 | |
64a5cfa6 SF |
877 | static int |
878 | smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, | |
879 | struct cifsFileInfo *cfile) | |
880 | { | |
881 | return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, | |
882 | cfile->fid.volatile_fid); | |
883 | } | |
884 | ||
b3152e2c SF |
885 | static int |
886 | smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon, | |
887 | struct cifsFileInfo *cfile) | |
888 | { | |
889 | struct fsctl_set_integrity_information_req integr_info; | |
b3152e2c SF |
890 | unsigned int ret_data_len; |
891 | ||
892 | integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED); | |
893 | integr_info.Flags = 0; | |
894 | integr_info.Reserved = 0; | |
895 | ||
896 | return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, | |
897 | cfile->fid.volatile_fid, | |
898 | FSCTL_SET_INTEGRITY_INFORMATION, | |
51146625 AA |
899 | true /* is_fsctl */, false /* use_ipc */, |
900 | (char *)&integr_info, | |
b3152e2c | 901 | sizeof(struct fsctl_set_integrity_information_req), |
24df1483 | 902 | NULL, |
b3152e2c SF |
903 | &ret_data_len); |
904 | ||
905 | } | |
906 | ||
834170c8 SF |
907 | static int |
908 | smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon, | |
909 | struct cifsFileInfo *cfile, void __user *ioc_buf) | |
910 | { | |
911 | char *retbuf = NULL; | |
912 | unsigned int ret_data_len = 0; | |
913 | int rc; | |
914 | struct smb_snapshot_array snapshot_in; | |
915 | ||
916 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, | |
917 | cfile->fid.volatile_fid, | |
918 | FSCTL_SRV_ENUMERATE_SNAPSHOTS, | |
51146625 AA |
919 | true /* is_fsctl */, false /* use_ipc */, |
920 | NULL, 0 /* no input data */, | |
834170c8 SF |
921 | (char **)&retbuf, |
922 | &ret_data_len); | |
923 | cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n", | |
924 | rc, ret_data_len); | |
925 | if (rc) | |
926 | return rc; | |
927 | ||
928 | if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) { | |
929 | /* Fixup buffer */ | |
930 | if (copy_from_user(&snapshot_in, ioc_buf, | |
931 | sizeof(struct smb_snapshot_array))) { | |
932 | rc = -EFAULT; | |
933 | kfree(retbuf); | |
934 | return rc; | |
935 | } | |
936 | if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) { | |
937 | rc = -ERANGE; | |
938 | return rc; | |
939 | } | |
940 | ||
941 | if (ret_data_len > snapshot_in.snapshot_array_size) | |
942 | ret_data_len = snapshot_in.snapshot_array_size; | |
943 | ||
944 | if (copy_to_user(ioc_buf, retbuf, ret_data_len)) | |
945 | rc = -EFAULT; | |
946 | } | |
947 | ||
948 | kfree(retbuf); | |
949 | return rc; | |
950 | } | |
951 | ||
d324f08d PS |
952 | static int |
953 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, | |
954 | const char *path, struct cifs_sb_info *cifs_sb, | |
955 | struct cifs_fid *fid, __u16 search_flags, | |
956 | struct cifs_search_info *srch_inf) | |
957 | { | |
958 | __le16 *utf16_path; | |
959 | int rc; | |
2e44b288 | 960 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
064f6047 | 961 | struct cifs_open_parms oparms; |
d324f08d PS |
962 | |
963 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); | |
964 | if (!utf16_path) | |
965 | return -ENOMEM; | |
966 | ||
064f6047 PS |
967 | oparms.tcon = tcon; |
968 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; | |
969 | oparms.disposition = FILE_OPEN; | |
970 | oparms.create_options = 0; | |
971 | oparms.fid = fid; | |
9cbc0b73 | 972 | oparms.reconnect = false; |
064f6047 | 973 | |
b42bf888 | 974 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
d324f08d PS |
975 | kfree(utf16_path); |
976 | if (rc) { | |
f96637be | 977 | cifs_dbg(VFS, "open dir failed\n"); |
d324f08d PS |
978 | return rc; |
979 | } | |
980 | ||
981 | srch_inf->entries_in_buffer = 0; | |
982 | srch_inf->index_of_last_entry = 0; | |
d324f08d | 983 | |
064f6047 PS |
984 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
985 | fid->volatile_fid, 0, srch_inf); | |
d324f08d | 986 | if (rc) { |
f96637be | 987 | cifs_dbg(VFS, "query directory failed\n"); |
064f6047 | 988 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
d324f08d PS |
989 | } |
990 | return rc; | |
991 | } | |
992 | ||
993 | static int | |
994 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, | |
995 | struct cifs_fid *fid, __u16 search_flags, | |
996 | struct cifs_search_info *srch_inf) | |
997 | { | |
998 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, | |
999 | fid->volatile_fid, 0, srch_inf); | |
1000 | } | |
1001 | ||
1002 | static int | |
1003 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, | |
1004 | struct cifs_fid *fid) | |
1005 | { | |
1006 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); | |
1007 | } | |
1008 | ||
2e44b288 PS |
1009 | /* |
1010 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update | |
1011 | * the number of credits and return true. Otherwise - return false. | |
1012 | */ | |
1013 | static bool | |
1014 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) | |
1015 | { | |
31473fc4 | 1016 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
2e44b288 | 1017 | |
31473fc4 | 1018 | if (shdr->Status != STATUS_PENDING) |
2e44b288 PS |
1019 | return false; |
1020 | ||
1021 | if (!length) { | |
1022 | spin_lock(&server->req_lock); | |
31473fc4 | 1023 | server->credits += le16_to_cpu(shdr->CreditRequest); |
2e44b288 PS |
1024 | spin_unlock(&server->req_lock); |
1025 | wake_up(&server->request_q); | |
1026 | } | |
1027 | ||
1028 | return true; | |
1029 | } | |
1030 | ||
983c88a4 PS |
1031 | static int |
1032 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, | |
1033 | struct cifsInodeInfo *cinode) | |
1034 | { | |
0822f514 PS |
1035 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
1036 | return SMB2_lease_break(0, tcon, cinode->lease_key, | |
1037 | smb2_get_lease_state(cinode)); | |
1038 | ||
983c88a4 PS |
1039 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
1040 | fid->volatile_fid, | |
18cceb6a | 1041 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
983c88a4 PS |
1042 | } |
1043 | ||
6fc05c25 PS |
1044 | static int |
1045 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, | |
1046 | struct kstatfs *buf) | |
1047 | { | |
1048 | int rc; | |
6fc05c25 PS |
1049 | __le16 srch_path = 0; /* Null - open root of share */ |
1050 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
064f6047 PS |
1051 | struct cifs_open_parms oparms; |
1052 | struct cifs_fid fid; | |
1053 | ||
1054 | oparms.tcon = tcon; | |
1055 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
1056 | oparms.disposition = FILE_OPEN; | |
1057 | oparms.create_options = 0; | |
1058 | oparms.fid = &fid; | |
9cbc0b73 | 1059 | oparms.reconnect = false; |
6fc05c25 | 1060 | |
b42bf888 | 1061 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
6fc05c25 PS |
1062 | if (rc) |
1063 | return rc; | |
1064 | buf->f_type = SMB2_MAGIC_NUMBER; | |
064f6047 PS |
1065 | rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
1066 | buf); | |
1067 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); | |
6fc05c25 PS |
1068 | return rc; |
1069 | } | |
1070 | ||
027e8eec PS |
1071 | static bool |
1072 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) | |
1073 | { | |
1074 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && | |
1075 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; | |
1076 | } | |
1077 | ||
f7ba7fe6 PS |
1078 | static int |
1079 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, | |
1080 | __u64 length, __u32 type, int lock, int unlock, bool wait) | |
1081 | { | |
1082 | if (unlock && !lock) | |
1083 | type = SMB2_LOCKFLAG_UNLOCK; | |
1084 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), | |
1085 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, | |
1086 | current->tgid, length, offset, type, wait); | |
1087 | } | |
1088 | ||
b8c32dbb PS |
1089 | static void |
1090 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) | |
1091 | { | |
1092 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); | |
1093 | } | |
1094 | ||
1095 | static void | |
1096 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) | |
1097 | { | |
1098 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); | |
1099 | } | |
1100 | ||
1101 | static void | |
1102 | smb2_new_lease_key(struct cifs_fid *fid) | |
1103 | { | |
fa70b87c | 1104 | generate_random_uuid(fid->lease_key); |
b8c32dbb PS |
1105 | } |
1106 | ||
9d49640a AA |
1107 | static int |
1108 | smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses, | |
1109 | const char *search_name, | |
1110 | struct dfs_info3_param **target_nodes, | |
1111 | unsigned int *num_of_nodes, | |
1112 | const struct nls_table *nls_codepage, int remap) | |
1113 | { | |
1114 | int rc; | |
1115 | __le16 *utf16_path = NULL; | |
1116 | int utf16_path_len = 0; | |
1117 | struct cifs_tcon *tcon; | |
1118 | struct fsctl_get_dfs_referral_req *dfs_req = NULL; | |
1119 | struct get_dfs_referral_rsp *dfs_rsp = NULL; | |
1120 | u32 dfs_req_size = 0, dfs_rsp_size = 0; | |
1121 | ||
1122 | cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name); | |
1123 | ||
1124 | /* | |
1125 | * Use any tcon from the current session. Here, the first one. | |
1126 | */ | |
1127 | spin_lock(&cifs_tcp_ses_lock); | |
1128 | tcon = list_first_entry_or_null(&ses->tcon_list, struct cifs_tcon, | |
1129 | tcon_list); | |
1130 | if (tcon) | |
1131 | tcon->tc_count++; | |
1132 | spin_unlock(&cifs_tcp_ses_lock); | |
1133 | ||
1134 | if (!tcon) { | |
1135 | cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n", | |
1136 | ses); | |
1137 | rc = -ENOTCONN; | |
1138 | goto out; | |
1139 | } | |
1140 | ||
1141 | utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX, | |
1142 | &utf16_path_len, | |
1143 | nls_codepage, remap); | |
1144 | if (!utf16_path) { | |
1145 | rc = -ENOMEM; | |
1146 | goto out; | |
1147 | } | |
1148 | ||
1149 | dfs_req_size = sizeof(*dfs_req) + utf16_path_len; | |
1150 | dfs_req = kzalloc(dfs_req_size, GFP_KERNEL); | |
1151 | if (!dfs_req) { | |
1152 | rc = -ENOMEM; | |
1153 | goto out; | |
1154 | } | |
1155 | ||
1156 | /* Highest DFS referral version understood */ | |
1157 | dfs_req->MaxReferralLevel = DFS_VERSION; | |
1158 | ||
1159 | /* Path to resolve in an UTF-16 null-terminated string */ | |
1160 | memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len); | |
1161 | ||
1162 | do { | |
1163 | /* try first with IPC */ | |
1164 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, | |
1165 | FSCTL_DFS_GET_REFERRALS, | |
1166 | true /* is_fsctl */, true /* use_ipc */, | |
1167 | (char *)dfs_req, dfs_req_size, | |
1168 | (char **)&dfs_rsp, &dfs_rsp_size); | |
1169 | if (rc == -ENOTCONN) { | |
1170 | /* try with normal tcon */ | |
1171 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, | |
1172 | FSCTL_DFS_GET_REFERRALS, | |
1173 | true /* is_fsctl */, false /*use_ipc*/, | |
1174 | (char *)dfs_req, dfs_req_size, | |
1175 | (char **)&dfs_rsp, &dfs_rsp_size); | |
1176 | } | |
1177 | } while (rc == -EAGAIN); | |
1178 | ||
1179 | if (rc) { | |
1180 | cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc); | |
1181 | goto out; | |
1182 | } | |
1183 | ||
1184 | rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size, | |
1185 | num_of_nodes, target_nodes, | |
1186 | nls_codepage, remap, search_name, | |
1187 | true /* is_unicode */); | |
1188 | if (rc) { | |
1189 | cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc); | |
1190 | goto out; | |
1191 | } | |
1192 | ||
1193 | out: | |
1194 | if (tcon) { | |
1195 | spin_lock(&cifs_tcp_ses_lock); | |
1196 | tcon->tc_count--; | |
1197 | spin_unlock(&cifs_tcp_ses_lock); | |
1198 | } | |
1199 | kfree(utf16_path); | |
1200 | kfree(dfs_req); | |
1201 | kfree(dfs_rsp); | |
1202 | return rc; | |
1203 | } | |
7893242e PS |
1204 | #define SMB2_SYMLINK_STRUCT_SIZE \ |
1205 | (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp)) | |
1206 | ||
b42bf888 PS |
1207 | static int |
1208 | smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, | |
1209 | const char *full_path, char **target_path, | |
1210 | struct cifs_sb_info *cifs_sb) | |
1211 | { | |
1212 | int rc; | |
1213 | __le16 *utf16_path; | |
1214 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
1215 | struct cifs_open_parms oparms; | |
1216 | struct cifs_fid fid; | |
1217 | struct smb2_err_rsp *err_buf = NULL; | |
1218 | struct smb2_symlink_err_rsp *symlink; | |
7893242e PS |
1219 | unsigned int sub_len; |
1220 | unsigned int sub_offset; | |
1221 | unsigned int print_len; | |
1222 | unsigned int print_offset; | |
b42bf888 PS |
1223 | |
1224 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); | |
1225 | ||
1226 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | |
1227 | if (!utf16_path) | |
1228 | return -ENOMEM; | |
1229 | ||
1230 | oparms.tcon = tcon; | |
1231 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
1232 | oparms.disposition = FILE_OPEN; | |
1233 | oparms.create_options = 0; | |
1234 | oparms.fid = &fid; | |
1235 | oparms.reconnect = false; | |
1236 | ||
1237 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf); | |
1238 | ||
1239 | if (!rc || !err_buf) { | |
1240 | kfree(utf16_path); | |
1241 | return -ENOENT; | |
1242 | } | |
7893242e PS |
1243 | |
1244 | if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) || | |
1245 | get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) { | |
1246 | kfree(utf16_path); | |
1247 | return -ENOENT; | |
1248 | } | |
1249 | ||
b42bf888 PS |
1250 | /* open must fail on symlink - reset rc */ |
1251 | rc = 0; | |
1252 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; | |
1253 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); | |
1254 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); | |
7893242e PS |
1255 | print_len = le16_to_cpu(symlink->PrintNameLength); |
1256 | print_offset = le16_to_cpu(symlink->PrintNameOffset); | |
1257 | ||
1258 | if (get_rfc1002_length(err_buf) + 4 < | |
1259 | SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) { | |
1260 | kfree(utf16_path); | |
1261 | return -ENOENT; | |
1262 | } | |
1263 | ||
1264 | if (get_rfc1002_length(err_buf) + 4 < | |
1265 | SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) { | |
1266 | kfree(utf16_path); | |
1267 | return -ENOENT; | |
1268 | } | |
1269 | ||
b42bf888 PS |
1270 | *target_path = cifs_strndup_from_utf16( |
1271 | (char *)symlink->PathBuffer + sub_offset, | |
1272 | sub_len, true, cifs_sb->local_nls); | |
1273 | if (!(*target_path)) { | |
1274 | kfree(utf16_path); | |
1275 | return -ENOMEM; | |
1276 | } | |
1277 | convert_delimiter(*target_path, '/'); | |
1278 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); | |
1279 | kfree(utf16_path); | |
1280 | return rc; | |
1281 | } | |
1282 | ||
30175628 SF |
1283 | static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, |
1284 | loff_t offset, loff_t len, bool keep_size) | |
1285 | { | |
1286 | struct inode *inode; | |
1287 | struct cifsInodeInfo *cifsi; | |
1288 | struct cifsFileInfo *cfile = file->private_data; | |
1289 | struct file_zero_data_information fsctl_buf; | |
1290 | long rc; | |
1291 | unsigned int xid; | |
1292 | ||
1293 | xid = get_xid(); | |
1294 | ||
2b0143b5 | 1295 | inode = d_inode(cfile->dentry); |
30175628 SF |
1296 | cifsi = CIFS_I(inode); |
1297 | ||
1298 | /* if file not oplocked can't be sure whether asking to extend size */ | |
1299 | if (!CIFS_CACHE_READ(cifsi)) | |
1300 | if (keep_size == false) | |
1301 | return -EOPNOTSUPP; | |
1302 | ||
2bb93d24 | 1303 | /* |
30175628 SF |
1304 | * Must check if file sparse since fallocate -z (zero range) assumes |
1305 | * non-sparse allocation | |
1306 | */ | |
1307 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) | |
1308 | return -EOPNOTSUPP; | |
1309 | ||
1310 | /* | |
1311 | * need to make sure we are not asked to extend the file since the SMB3 | |
1312 | * fsctl does not change the file size. In the future we could change | |
1313 | * this to zero the first part of the range then set the file size | |
1314 | * which for a non sparse file would zero the newly extended range | |
1315 | */ | |
1316 | if (keep_size == false) | |
1317 | if (i_size_read(inode) < offset + len) | |
1318 | return -EOPNOTSUPP; | |
1319 | ||
1320 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); | |
1321 | ||
1322 | fsctl_buf.FileOffset = cpu_to_le64(offset); | |
1323 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); | |
1324 | ||
1325 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, | |
1326 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, | |
51146625 AA |
1327 | true /* is_fctl */, false /* use_ipc */, |
1328 | (char *)&fsctl_buf, | |
30175628 SF |
1329 | sizeof(struct file_zero_data_information), NULL, NULL); |
1330 | free_xid(xid); | |
1331 | return rc; | |
1332 | } | |
1333 | ||
31742c5a SF |
1334 | static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, |
1335 | loff_t offset, loff_t len) | |
1336 | { | |
1337 | struct inode *inode; | |
1338 | struct cifsInodeInfo *cifsi; | |
1339 | struct cifsFileInfo *cfile = file->private_data; | |
1340 | struct file_zero_data_information fsctl_buf; | |
1341 | long rc; | |
1342 | unsigned int xid; | |
1343 | __u8 set_sparse = 1; | |
1344 | ||
1345 | xid = get_xid(); | |
1346 | ||
2b0143b5 | 1347 | inode = d_inode(cfile->dentry); |
31742c5a SF |
1348 | cifsi = CIFS_I(inode); |
1349 | ||
1350 | /* Need to make file sparse, if not already, before freeing range. */ | |
1351 | /* Consider adding equivalent for compressed since it could also work */ | |
1352 | if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) | |
1353 | return -EOPNOTSUPP; | |
1354 | ||
1355 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); | |
1356 | ||
1357 | fsctl_buf.FileOffset = cpu_to_le64(offset); | |
1358 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); | |
1359 | ||
1360 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, | |
1361 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, | |
51146625 AA |
1362 | true /* is_fctl */, false /* use_ipc */, |
1363 | (char *)&fsctl_buf, | |
31742c5a SF |
1364 | sizeof(struct file_zero_data_information), NULL, NULL); |
1365 | free_xid(xid); | |
1366 | return rc; | |
1367 | } | |
1368 | ||
9ccf3216 SF |
1369 | static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, |
1370 | loff_t off, loff_t len, bool keep_size) | |
1371 | { | |
1372 | struct inode *inode; | |
1373 | struct cifsInodeInfo *cifsi; | |
1374 | struct cifsFileInfo *cfile = file->private_data; | |
1375 | long rc = -EOPNOTSUPP; | |
1376 | unsigned int xid; | |
1377 | ||
1378 | xid = get_xid(); | |
1379 | ||
2b0143b5 | 1380 | inode = d_inode(cfile->dentry); |
9ccf3216 SF |
1381 | cifsi = CIFS_I(inode); |
1382 | ||
1383 | /* if file not oplocked can't be sure whether asking to extend size */ | |
1384 | if (!CIFS_CACHE_READ(cifsi)) | |
1385 | if (keep_size == false) | |
1386 | return -EOPNOTSUPP; | |
1387 | ||
1388 | /* | |
1389 | * Files are non-sparse by default so falloc may be a no-op | |
1390 | * Must check if file sparse. If not sparse, and not extending | |
1391 | * then no need to do anything since file already allocated | |
1392 | */ | |
1393 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { | |
1394 | if (keep_size == true) | |
1395 | return 0; | |
1396 | /* check if extending file */ | |
1397 | else if (i_size_read(inode) >= off + len) | |
1398 | /* not extending file and already not sparse */ | |
1399 | return 0; | |
1400 | /* BB: in future add else clause to extend file */ | |
1401 | else | |
1402 | return -EOPNOTSUPP; | |
1403 | } | |
1404 | ||
1405 | if ((keep_size == true) || (i_size_read(inode) >= off + len)) { | |
1406 | /* | |
1407 | * Check if falloc starts within first few pages of file | |
1408 | * and ends within a few pages of the end of file to | |
1409 | * ensure that most of file is being forced to be | |
1410 | * fallocated now. If so then setting whole file sparse | |
1411 | * ie potentially making a few extra pages at the beginning | |
1412 | * or end of the file non-sparse via set_sparse is harmless. | |
1413 | */ | |
1414 | if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) | |
1415 | return -EOPNOTSUPP; | |
1416 | ||
1417 | rc = smb2_set_sparse(xid, tcon, cfile, inode, false); | |
1418 | } | |
1419 | /* BB: else ... in future add code to extend file and set sparse */ | |
1420 | ||
1421 | ||
1422 | free_xid(xid); | |
1423 | return rc; | |
1424 | } | |
1425 | ||
1426 | ||
31742c5a SF |
1427 | static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, |
1428 | loff_t off, loff_t len) | |
1429 | { | |
1430 | /* KEEP_SIZE already checked for by do_fallocate */ | |
1431 | if (mode & FALLOC_FL_PUNCH_HOLE) | |
1432 | return smb3_punch_hole(file, tcon, off, len); | |
30175628 SF |
1433 | else if (mode & FALLOC_FL_ZERO_RANGE) { |
1434 | if (mode & FALLOC_FL_KEEP_SIZE) | |
1435 | return smb3_zero_range(file, tcon, off, len, true); | |
1436 | return smb3_zero_range(file, tcon, off, len, false); | |
9ccf3216 SF |
1437 | } else if (mode == FALLOC_FL_KEEP_SIZE) |
1438 | return smb3_simple_falloc(file, tcon, off, len, true); | |
1439 | else if (mode == 0) | |
1440 | return smb3_simple_falloc(file, tcon, off, len, false); | |
31742c5a SF |
1441 | |
1442 | return -EOPNOTSUPP; | |
1443 | } | |
1444 | ||
c11f1df5 SP |
1445 | static void |
1446 | smb2_downgrade_oplock(struct TCP_Server_Info *server, | |
1447 | struct cifsInodeInfo *cinode, bool set_level2) | |
1448 | { | |
1449 | if (set_level2) | |
1450 | server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II, | |
1451 | 0, NULL); | |
1452 | else | |
1453 | server->ops->set_oplock_level(cinode, 0, 0, NULL); | |
1454 | } | |
1455 | ||
53ef1016 | 1456 | static void |
42873b0a PS |
1457 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
1458 | unsigned int epoch, bool *purge_cache) | |
53ef1016 PS |
1459 | { |
1460 | oplock &= 0xFF; | |
1461 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) | |
1462 | return; | |
1463 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { | |
42873b0a | 1464 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
53ef1016 PS |
1465 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
1466 | &cinode->vfs_inode); | |
1467 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { | |
42873b0a | 1468 | cinode->oplock = CIFS_CACHE_RW_FLG; |
53ef1016 PS |
1469 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
1470 | &cinode->vfs_inode); | |
1471 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { | |
1472 | cinode->oplock = CIFS_CACHE_READ_FLG; | |
1473 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", | |
1474 | &cinode->vfs_inode); | |
1475 | } else | |
1476 | cinode->oplock = 0; | |
1477 | } | |
1478 | ||
1479 | static void | |
42873b0a PS |
1480 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
1481 | unsigned int epoch, bool *purge_cache) | |
53ef1016 PS |
1482 | { |
1483 | char message[5] = {0}; | |
1484 | ||
1485 | oplock &= 0xFF; | |
1486 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) | |
1487 | return; | |
1488 | ||
1489 | cinode->oplock = 0; | |
1490 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { | |
1491 | cinode->oplock |= CIFS_CACHE_READ_FLG; | |
1492 | strcat(message, "R"); | |
1493 | } | |
1494 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { | |
1495 | cinode->oplock |= CIFS_CACHE_HANDLE_FLG; | |
1496 | strcat(message, "H"); | |
1497 | } | |
1498 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { | |
1499 | cinode->oplock |= CIFS_CACHE_WRITE_FLG; | |
1500 | strcat(message, "W"); | |
1501 | } | |
1502 | if (!cinode->oplock) | |
1503 | strcat(message, "None"); | |
1504 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, | |
1505 | &cinode->vfs_inode); | |
1506 | } | |
1507 | ||
42873b0a PS |
1508 | static void |
1509 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, | |
1510 | unsigned int epoch, bool *purge_cache) | |
1511 | { | |
1512 | unsigned int old_oplock = cinode->oplock; | |
1513 | ||
1514 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); | |
1515 | ||
1516 | if (purge_cache) { | |
1517 | *purge_cache = false; | |
1518 | if (old_oplock == CIFS_CACHE_READ_FLG) { | |
1519 | if (cinode->oplock == CIFS_CACHE_READ_FLG && | |
1520 | (epoch - cinode->epoch > 0)) | |
1521 | *purge_cache = true; | |
1522 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && | |
1523 | (epoch - cinode->epoch > 1)) | |
1524 | *purge_cache = true; | |
1525 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && | |
1526 | (epoch - cinode->epoch > 1)) | |
1527 | *purge_cache = true; | |
1528 | else if (cinode->oplock == 0 && | |
1529 | (epoch - cinode->epoch > 0)) | |
1530 | *purge_cache = true; | |
1531 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { | |
1532 | if (cinode->oplock == CIFS_CACHE_RH_FLG && | |
1533 | (epoch - cinode->epoch > 0)) | |
1534 | *purge_cache = true; | |
1535 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && | |
1536 | (epoch - cinode->epoch > 1)) | |
1537 | *purge_cache = true; | |
1538 | } | |
1539 | cinode->epoch = epoch; | |
1540 | } | |
1541 | } | |
1542 | ||
53ef1016 PS |
1543 | static bool |
1544 | smb2_is_read_op(__u32 oplock) | |
1545 | { | |
1546 | return oplock == SMB2_OPLOCK_LEVEL_II; | |
1547 | } | |
1548 | ||
1549 | static bool | |
1550 | smb21_is_read_op(__u32 oplock) | |
1551 | { | |
1552 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && | |
1553 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); | |
1554 | } | |
1555 | ||
f047390a PS |
1556 | static __le32 |
1557 | map_oplock_to_lease(u8 oplock) | |
1558 | { | |
1559 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) | |
1560 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; | |
1561 | else if (oplock == SMB2_OPLOCK_LEVEL_II) | |
1562 | return SMB2_LEASE_READ_CACHING; | |
1563 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) | |
1564 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | | |
1565 | SMB2_LEASE_WRITE_CACHING; | |
1566 | return 0; | |
1567 | } | |
1568 | ||
a41a28bd PS |
1569 | static char * |
1570 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) | |
1571 | { | |
1572 | struct create_lease *buf; | |
1573 | ||
1574 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); | |
1575 | if (!buf) | |
1576 | return NULL; | |
1577 | ||
1578 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); | |
1579 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); | |
f047390a | 1580 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
a41a28bd PS |
1581 | |
1582 | buf->ccontext.DataOffset = cpu_to_le16(offsetof | |
1583 | (struct create_lease, lcontext)); | |
1584 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); | |
1585 | buf->ccontext.NameOffset = cpu_to_le16(offsetof | |
1586 | (struct create_lease, Name)); | |
1587 | buf->ccontext.NameLength = cpu_to_le16(4); | |
12197a7f | 1588 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
a41a28bd PS |
1589 | buf->Name[0] = 'R'; |
1590 | buf->Name[1] = 'q'; | |
1591 | buf->Name[2] = 'L'; | |
1592 | buf->Name[3] = 's'; | |
1593 | return (char *)buf; | |
1594 | } | |
1595 | ||
f047390a PS |
1596 | static char * |
1597 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) | |
1598 | { | |
1599 | struct create_lease_v2 *buf; | |
1600 | ||
1601 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); | |
1602 | if (!buf) | |
1603 | return NULL; | |
1604 | ||
1605 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); | |
1606 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); | |
1607 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); | |
1608 | ||
1609 | buf->ccontext.DataOffset = cpu_to_le16(offsetof | |
1610 | (struct create_lease_v2, lcontext)); | |
1611 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); | |
1612 | buf->ccontext.NameOffset = cpu_to_le16(offsetof | |
1613 | (struct create_lease_v2, Name)); | |
1614 | buf->ccontext.NameLength = cpu_to_le16(4); | |
12197a7f | 1615 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
f047390a PS |
1616 | buf->Name[0] = 'R'; |
1617 | buf->Name[1] = 'q'; | |
1618 | buf->Name[2] = 'L'; | |
1619 | buf->Name[3] = 's'; | |
1620 | return (char *)buf; | |
1621 | } | |
1622 | ||
b5c7cde3 | 1623 | static __u8 |
42873b0a | 1624 | smb2_parse_lease_buf(void *buf, unsigned int *epoch) |
b5c7cde3 PS |
1625 | { |
1626 | struct create_lease *lc = (struct create_lease *)buf; | |
1627 | ||
42873b0a | 1628 | *epoch = 0; /* not used */ |
b5c7cde3 PS |
1629 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
1630 | return SMB2_OPLOCK_LEVEL_NOCHANGE; | |
1631 | return le32_to_cpu(lc->lcontext.LeaseState); | |
1632 | } | |
1633 | ||
f047390a | 1634 | static __u8 |
42873b0a | 1635 | smb3_parse_lease_buf(void *buf, unsigned int *epoch) |
f047390a PS |
1636 | { |
1637 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; | |
1638 | ||
42873b0a | 1639 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
f047390a PS |
1640 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
1641 | return SMB2_OPLOCK_LEVEL_NOCHANGE; | |
1642 | return le32_to_cpu(lc->lcontext.LeaseState); | |
1643 | } | |
1644 | ||
7f6c5008 PS |
1645 | static unsigned int |
1646 | smb2_wp_retry_size(struct inode *inode) | |
1647 | { | |
1648 | return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize, | |
1649 | SMB2_MAX_BUFFER_SIZE); | |
1650 | } | |
1651 | ||
52755808 PS |
1652 | static bool |
1653 | smb2_dir_needs_close(struct cifsFileInfo *cfile) | |
1654 | { | |
1655 | return !cfile->invalidHandle; | |
1656 | } | |
1657 | ||
026e93dc PS |
1658 | static void |
1659 | fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, struct smb_rqst *old_rq) | |
1660 | { | |
1661 | struct smb2_sync_hdr *shdr = | |
1662 | (struct smb2_sync_hdr *)old_rq->rq_iov[1].iov_base; | |
1663 | unsigned int orig_len = get_rfc1002_length(old_rq->rq_iov[0].iov_base); | |
1664 | ||
1665 | memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr)); | |
1666 | tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; | |
1667 | tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); | |
1668 | tr_hdr->Flags = cpu_to_le16(0x01); | |
1669 | get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE); | |
1670 | memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); | |
1671 | inc_rfc1001_len(tr_hdr, sizeof(struct smb2_transform_hdr) - 4); | |
1672 | inc_rfc1001_len(tr_hdr, orig_len); | |
1673 | } | |
1674 | ||
1675 | static struct scatterlist * | |
1676 | init_sg(struct smb_rqst *rqst, u8 *sign) | |
1677 | { | |
1678 | unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1; | |
1679 | unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24; | |
1680 | struct scatterlist *sg; | |
1681 | unsigned int i; | |
1682 | unsigned int j; | |
1683 | ||
1684 | sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL); | |
1685 | if (!sg) | |
1686 | return NULL; | |
1687 | ||
1688 | sg_init_table(sg, sg_len); | |
1689 | sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len); | |
1690 | for (i = 1; i < rqst->rq_nvec; i++) | |
1691 | sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base, | |
1692 | rqst->rq_iov[i].iov_len); | |
1693 | for (j = 0; i < sg_len - 1; i++, j++) { | |
1694 | unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz | |
1695 | : rqst->rq_tailsz; | |
1696 | sg_set_page(&sg[i], rqst->rq_pages[j], len, 0); | |
1697 | } | |
1698 | sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE); | |
1699 | return sg; | |
1700 | } | |
1701 | ||
1702 | struct cifs_crypt_result { | |
1703 | int err; | |
1704 | struct completion completion; | |
1705 | }; | |
1706 | ||
1707 | static void cifs_crypt_complete(struct crypto_async_request *req, int err) | |
1708 | { | |
1709 | struct cifs_crypt_result *res = req->data; | |
1710 | ||
1711 | if (err == -EINPROGRESS) | |
1712 | return; | |
1713 | ||
1714 | res->err = err; | |
1715 | complete(&res->completion); | |
1716 | } | |
1717 | ||
61cfac6f PS |
1718 | static int |
1719 | smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key) | |
1720 | { | |
1721 | struct cifs_ses *ses; | |
1722 | u8 *ses_enc_key; | |
1723 | ||
1724 | spin_lock(&cifs_tcp_ses_lock); | |
1725 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { | |
1726 | if (ses->Suid != ses_id) | |
1727 | continue; | |
1728 | ses_enc_key = enc ? ses->smb3encryptionkey : | |
1729 | ses->smb3decryptionkey; | |
1730 | memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE); | |
1731 | spin_unlock(&cifs_tcp_ses_lock); | |
1732 | return 0; | |
1733 | } | |
1734 | spin_unlock(&cifs_tcp_ses_lock); | |
1735 | ||
1736 | return 1; | |
1737 | } | |
026e93dc PS |
1738 | /* |
1739 | * Encrypt or decrypt @rqst message. @rqst has the following format: | |
1740 | * iov[0] - transform header (associate data), | |
1741 | * iov[1-N] and pages - data to encrypt. | |
1742 | * On success return encrypted data in iov[1-N] and pages, leave iov[0] | |
1743 | * untouched. | |
1744 | */ | |
1745 | static int | |
1746 | crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc) | |
1747 | { | |
1748 | struct smb2_transform_hdr *tr_hdr = | |
1749 | (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base; | |
1750 | unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24; | |
026e93dc PS |
1751 | int rc = 0; |
1752 | struct scatterlist *sg; | |
1753 | u8 sign[SMB2_SIGNATURE_SIZE] = {}; | |
61cfac6f | 1754 | u8 key[SMB3_SIGN_KEY_SIZE]; |
026e93dc PS |
1755 | struct aead_request *req; |
1756 | char *iv; | |
1757 | unsigned int iv_len; | |
1758 | struct cifs_crypt_result result = {0, }; | |
1759 | struct crypto_aead *tfm; | |
1760 | unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize); | |
1761 | ||
1762 | init_completion(&result.completion); | |
1763 | ||
61cfac6f PS |
1764 | rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key); |
1765 | if (rc) { | |
1766 | cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__, | |
1767 | enc ? "en" : "de"); | |
026e93dc PS |
1768 | return 0; |
1769 | } | |
1770 | ||
1771 | rc = smb3_crypto_aead_allocate(server); | |
1772 | if (rc) { | |
1773 | cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__); | |
1774 | return rc; | |
1775 | } | |
1776 | ||
1777 | tfm = enc ? server->secmech.ccmaesencrypt : | |
1778 | server->secmech.ccmaesdecrypt; | |
61cfac6f | 1779 | rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE); |
026e93dc PS |
1780 | if (rc) { |
1781 | cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc); | |
1782 | return rc; | |
1783 | } | |
1784 | ||
1785 | rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE); | |
1786 | if (rc) { | |
1787 | cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc); | |
1788 | return rc; | |
1789 | } | |
1790 | ||
1791 | req = aead_request_alloc(tfm, GFP_KERNEL); | |
1792 | if (!req) { | |
1793 | cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__); | |
1794 | return -ENOMEM; | |
1795 | } | |
1796 | ||
1797 | if (!enc) { | |
1798 | memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE); | |
1799 | crypt_len += SMB2_SIGNATURE_SIZE; | |
1800 | } | |
1801 | ||
1802 | sg = init_sg(rqst, sign); | |
1803 | if (!sg) { | |
1804 | cifs_dbg(VFS, "%s: Failed to init sg %d", __func__, rc); | |
1805 | goto free_req; | |
1806 | } | |
1807 | ||
1808 | iv_len = crypto_aead_ivsize(tfm); | |
1809 | iv = kzalloc(iv_len, GFP_KERNEL); | |
1810 | if (!iv) { | |
1811 | cifs_dbg(VFS, "%s: Failed to alloc IV", __func__); | |
1812 | goto free_sg; | |
1813 | } | |
1814 | iv[0] = 3; | |
1815 | memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE); | |
1816 | ||
1817 | aead_request_set_crypt(req, sg, sg, crypt_len, iv); | |
1818 | aead_request_set_ad(req, assoc_data_len); | |
1819 | ||
1820 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
1821 | cifs_crypt_complete, &result); | |
1822 | ||
1823 | rc = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); | |
1824 | ||
1825 | if (rc == -EINPROGRESS || rc == -EBUSY) { | |
1826 | wait_for_completion(&result.completion); | |
1827 | rc = result.err; | |
1828 | } | |
1829 | ||
1830 | if (!rc && enc) | |
1831 | memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); | |
1832 | ||
1833 | kfree(iv); | |
1834 | free_sg: | |
1835 | kfree(sg); | |
1836 | free_req: | |
1837 | kfree(req); | |
1838 | return rc; | |
1839 | } | |
1840 | ||
1841 | static int | |
1842 | smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, | |
1843 | struct smb_rqst *old_rq) | |
1844 | { | |
1845 | struct kvec *iov; | |
1846 | struct page **pages; | |
1847 | struct smb2_transform_hdr *tr_hdr; | |
1848 | unsigned int npages = old_rq->rq_npages; | |
1849 | int i; | |
1850 | int rc = -ENOMEM; | |
1851 | ||
1852 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); | |
1853 | if (!pages) | |
1854 | return rc; | |
1855 | ||
1856 | new_rq->rq_pages = pages; | |
1857 | new_rq->rq_npages = old_rq->rq_npages; | |
1858 | new_rq->rq_pagesz = old_rq->rq_pagesz; | |
1859 | new_rq->rq_tailsz = old_rq->rq_tailsz; | |
1860 | ||
1861 | for (i = 0; i < npages; i++) { | |
1862 | pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); | |
1863 | if (!pages[i]) | |
1864 | goto err_free_pages; | |
1865 | } | |
1866 | ||
1867 | iov = kmalloc_array(old_rq->rq_nvec, sizeof(struct kvec), GFP_KERNEL); | |
1868 | if (!iov) | |
1869 | goto err_free_pages; | |
1870 | ||
1871 | /* copy all iovs from the old except the 1st one (rfc1002 length) */ | |
1872 | memcpy(&iov[1], &old_rq->rq_iov[1], | |
1873 | sizeof(struct kvec) * (old_rq->rq_nvec - 1)); | |
1874 | new_rq->rq_iov = iov; | |
1875 | new_rq->rq_nvec = old_rq->rq_nvec; | |
1876 | ||
1877 | tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL); | |
1878 | if (!tr_hdr) | |
1879 | goto err_free_iov; | |
1880 | ||
1881 | /* fill the 1st iov with a transform header */ | |
1882 | fill_transform_hdr(tr_hdr, old_rq); | |
1883 | new_rq->rq_iov[0].iov_base = tr_hdr; | |
1884 | new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr); | |
1885 | ||
1886 | /* copy pages form the old */ | |
1887 | for (i = 0; i < npages; i++) { | |
1888 | char *dst = kmap(new_rq->rq_pages[i]); | |
1889 | char *src = kmap(old_rq->rq_pages[i]); | |
1890 | unsigned int len = (i < npages - 1) ? new_rq->rq_pagesz : | |
1891 | new_rq->rq_tailsz; | |
1892 | memcpy(dst, src, len); | |
1893 | kunmap(new_rq->rq_pages[i]); | |
1894 | kunmap(old_rq->rq_pages[i]); | |
1895 | } | |
1896 | ||
1897 | rc = crypt_message(server, new_rq, 1); | |
1898 | cifs_dbg(FYI, "encrypt message returned %d", rc); | |
1899 | if (rc) | |
1900 | goto err_free_tr_hdr; | |
1901 | ||
1902 | return rc; | |
1903 | ||
1904 | err_free_tr_hdr: | |
1905 | kfree(tr_hdr); | |
1906 | err_free_iov: | |
1907 | kfree(iov); | |
1908 | err_free_pages: | |
1909 | for (i = i - 1; i >= 0; i--) | |
1910 | put_page(pages[i]); | |
1911 | kfree(pages); | |
1912 | return rc; | |
1913 | } | |
1914 | ||
1915 | static void | |
1916 | smb3_free_transform_rq(struct smb_rqst *rqst) | |
1917 | { | |
1918 | int i = rqst->rq_npages - 1; | |
1919 | ||
1920 | for (; i >= 0; i--) | |
1921 | put_page(rqst->rq_pages[i]); | |
1922 | kfree(rqst->rq_pages); | |
1923 | /* free transform header */ | |
1924 | kfree(rqst->rq_iov[0].iov_base); | |
1925 | kfree(rqst->rq_iov); | |
1926 | } | |
1927 | ||
4326ed2f PS |
1928 | static int |
1929 | smb3_is_transform_hdr(void *buf) | |
1930 | { | |
1931 | struct smb2_transform_hdr *trhdr = buf; | |
1932 | ||
1933 | return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM; | |
1934 | } | |
1935 | ||
1936 | static int | |
1937 | decrypt_raw_data(struct TCP_Server_Info *server, char *buf, | |
1938 | unsigned int buf_data_size, struct page **pages, | |
1939 | unsigned int npages, unsigned int page_data_size) | |
1940 | { | |
1941 | struct kvec iov[2]; | |
1942 | struct smb_rqst rqst = {NULL}; | |
1943 | struct smb2_hdr *hdr; | |
1944 | int rc; | |
1945 | ||
1946 | iov[0].iov_base = buf; | |
1947 | iov[0].iov_len = sizeof(struct smb2_transform_hdr); | |
1948 | iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr); | |
1949 | iov[1].iov_len = buf_data_size; | |
1950 | ||
1951 | rqst.rq_iov = iov; | |
1952 | rqst.rq_nvec = 2; | |
1953 | rqst.rq_pages = pages; | |
1954 | rqst.rq_npages = npages; | |
1955 | rqst.rq_pagesz = PAGE_SIZE; | |
1956 | rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE; | |
1957 | ||
1958 | rc = crypt_message(server, &rqst, 0); | |
1959 | cifs_dbg(FYI, "decrypt message returned %d\n", rc); | |
1960 | ||
1961 | if (rc) | |
1962 | return rc; | |
1963 | ||
1964 | memmove(buf + 4, iov[1].iov_base, buf_data_size); | |
1965 | hdr = (struct smb2_hdr *)buf; | |
1966 | hdr->smb2_buf_length = cpu_to_be32(buf_data_size + page_data_size); | |
1967 | server->total_read = buf_data_size + page_data_size + 4; | |
1968 | ||
1969 | return rc; | |
1970 | } | |
1971 | ||
c42a6abe PS |
1972 | static int |
1973 | read_data_into_pages(struct TCP_Server_Info *server, struct page **pages, | |
1974 | unsigned int npages, unsigned int len) | |
1975 | { | |
1976 | int i; | |
1977 | int length; | |
1978 | ||
1979 | for (i = 0; i < npages; i++) { | |
1980 | struct page *page = pages[i]; | |
1981 | size_t n; | |
1982 | ||
1983 | n = len; | |
1984 | if (len >= PAGE_SIZE) { | |
1985 | /* enough data to fill the page */ | |
1986 | n = PAGE_SIZE; | |
1987 | len -= n; | |
1988 | } else { | |
1989 | zero_user(page, len, PAGE_SIZE - len); | |
1990 | len = 0; | |
1991 | } | |
1992 | length = cifs_read_page_from_socket(server, page, n); | |
1993 | if (length < 0) | |
1994 | return length; | |
1995 | server->total_read += length; | |
1996 | } | |
1997 | ||
1998 | return 0; | |
1999 | } | |
2000 | ||
2001 | static int | |
2002 | init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size, | |
2003 | unsigned int cur_off, struct bio_vec **page_vec) | |
2004 | { | |
2005 | struct bio_vec *bvec; | |
2006 | int i; | |
2007 | ||
2008 | bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL); | |
2009 | if (!bvec) | |
2010 | return -ENOMEM; | |
2011 | ||
2012 | for (i = 0; i < npages; i++) { | |
2013 | bvec[i].bv_page = pages[i]; | |
2014 | bvec[i].bv_offset = (i == 0) ? cur_off : 0; | |
2015 | bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size); | |
2016 | data_size -= bvec[i].bv_len; | |
2017 | } | |
2018 | ||
2019 | if (data_size != 0) { | |
2020 | cifs_dbg(VFS, "%s: something went wrong\n", __func__); | |
2021 | kfree(bvec); | |
2022 | return -EIO; | |
2023 | } | |
2024 | ||
2025 | *page_vec = bvec; | |
2026 | return 0; | |
2027 | } | |
2028 | ||
4326ed2f PS |
2029 | static int |
2030 | handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, | |
2031 | char *buf, unsigned int buf_len, struct page **pages, | |
2032 | unsigned int npages, unsigned int page_data_size) | |
2033 | { | |
2034 | unsigned int data_offset; | |
2035 | unsigned int data_len; | |
c42a6abe PS |
2036 | unsigned int cur_off; |
2037 | unsigned int cur_page_idx; | |
2038 | unsigned int pad_len; | |
4326ed2f PS |
2039 | struct cifs_readdata *rdata = mid->callback_data; |
2040 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); | |
2041 | struct bio_vec *bvec = NULL; | |
2042 | struct iov_iter iter; | |
2043 | struct kvec iov; | |
2044 | int length; | |
2045 | ||
2046 | if (shdr->Command != SMB2_READ) { | |
2047 | cifs_dbg(VFS, "only big read responses are supported\n"); | |
2048 | return -ENOTSUPP; | |
2049 | } | |
2050 | ||
2051 | if (server->ops->is_status_pending && | |
2052 | server->ops->is_status_pending(buf, server, 0)) | |
2053 | return -1; | |
2054 | ||
2055 | rdata->result = server->ops->map_error(buf, false); | |
2056 | if (rdata->result != 0) { | |
2057 | cifs_dbg(FYI, "%s: server returned error %d\n", | |
2058 | __func__, rdata->result); | |
2059 | dequeue_mid(mid, rdata->result); | |
2060 | return 0; | |
2061 | } | |
2062 | ||
2063 | data_offset = server->ops->read_data_offset(buf) + 4; | |
2064 | data_len = server->ops->read_data_length(buf); | |
2065 | ||
2066 | if (data_offset < server->vals->read_rsp_size) { | |
2067 | /* | |
2068 | * win2k8 sometimes sends an offset of 0 when the read | |
2069 | * is beyond the EOF. Treat it as if the data starts just after | |
2070 | * the header. | |
2071 | */ | |
2072 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", | |
2073 | __func__, data_offset); | |
2074 | data_offset = server->vals->read_rsp_size; | |
2075 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { | |
2076 | /* data_offset is beyond the end of smallbuf */ | |
2077 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", | |
2078 | __func__, data_offset); | |
2079 | rdata->result = -EIO; | |
2080 | dequeue_mid(mid, rdata->result); | |
2081 | return 0; | |
2082 | } | |
2083 | ||
c42a6abe PS |
2084 | pad_len = data_offset - server->vals->read_rsp_size; |
2085 | ||
4326ed2f PS |
2086 | if (buf_len <= data_offset) { |
2087 | /* read response payload is in pages */ | |
c42a6abe PS |
2088 | cur_page_idx = pad_len / PAGE_SIZE; |
2089 | cur_off = pad_len % PAGE_SIZE; | |
2090 | ||
2091 | if (cur_page_idx != 0) { | |
2092 | /* data offset is beyond the 1st page of response */ | |
2093 | cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n", | |
2094 | __func__, data_offset); | |
2095 | rdata->result = -EIO; | |
2096 | dequeue_mid(mid, rdata->result); | |
2097 | return 0; | |
2098 | } | |
2099 | ||
2100 | if (data_len > page_data_size - pad_len) { | |
2101 | /* data_len is corrupt -- discard frame */ | |
2102 | rdata->result = -EIO; | |
2103 | dequeue_mid(mid, rdata->result); | |
2104 | return 0; | |
2105 | } | |
2106 | ||
2107 | rdata->result = init_read_bvec(pages, npages, page_data_size, | |
2108 | cur_off, &bvec); | |
2109 | if (rdata->result != 0) { | |
2110 | dequeue_mid(mid, rdata->result); | |
2111 | return 0; | |
2112 | } | |
2113 | ||
2114 | iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len); | |
4326ed2f PS |
2115 | } else if (buf_len >= data_offset + data_len) { |
2116 | /* read response payload is in buf */ | |
2117 | WARN_ONCE(npages > 0, "read data can be either in buf or in pages"); | |
2118 | iov.iov_base = buf + data_offset; | |
2119 | iov.iov_len = data_len; | |
2120 | iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len); | |
2121 | } else { | |
2122 | /* read response payload cannot be in both buf and pages */ | |
2123 | WARN_ONCE(1, "buf can not contain only a part of read data"); | |
2124 | rdata->result = -EIO; | |
2125 | dequeue_mid(mid, rdata->result); | |
2126 | return 0; | |
2127 | } | |
2128 | ||
2129 | /* set up first iov for signature check */ | |
2130 | rdata->iov[0].iov_base = buf; | |
2131 | rdata->iov[0].iov_len = 4; | |
2132 | rdata->iov[1].iov_base = buf + 4; | |
2133 | rdata->iov[1].iov_len = server->vals->read_rsp_size - 4; | |
2134 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", | |
2135 | rdata->iov[0].iov_base, server->vals->read_rsp_size); | |
2136 | ||
2137 | length = rdata->copy_into_pages(server, rdata, &iter); | |
2138 | ||
2139 | kfree(bvec); | |
2140 | ||
2141 | if (length < 0) | |
2142 | return length; | |
2143 | ||
2144 | dequeue_mid(mid, false); | |
2145 | return length; | |
2146 | } | |
2147 | ||
c42a6abe PS |
2148 | static int |
2149 | receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid) | |
2150 | { | |
2151 | char *buf = server->smallbuf; | |
2152 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; | |
2153 | unsigned int npages; | |
2154 | struct page **pages; | |
2155 | unsigned int len; | |
2156 | unsigned int buflen = get_rfc1002_length(buf) + 4; | |
2157 | int rc; | |
2158 | int i = 0; | |
2159 | ||
2160 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size - 4 + | |
2161 | sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1; | |
2162 | ||
2163 | rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len); | |
2164 | if (rc < 0) | |
2165 | return rc; | |
2166 | server->total_read += rc; | |
2167 | ||
2168 | len = le32_to_cpu(tr_hdr->OriginalMessageSize) + 4 - | |
2169 | server->vals->read_rsp_size; | |
2170 | npages = DIV_ROUND_UP(len, PAGE_SIZE); | |
2171 | ||
2172 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); | |
2173 | if (!pages) { | |
2174 | rc = -ENOMEM; | |
2175 | goto discard_data; | |
2176 | } | |
2177 | ||
2178 | for (; i < npages; i++) { | |
2179 | pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); | |
2180 | if (!pages[i]) { | |
2181 | rc = -ENOMEM; | |
2182 | goto discard_data; | |
2183 | } | |
2184 | } | |
2185 | ||
2186 | /* read read data into pages */ | |
2187 | rc = read_data_into_pages(server, pages, npages, len); | |
2188 | if (rc) | |
2189 | goto free_pages; | |
2190 | ||
2191 | rc = cifs_discard_remaining_data(server); | |
2192 | if (rc) | |
2193 | goto free_pages; | |
2194 | ||
2195 | rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size - 4, | |
2196 | pages, npages, len); | |
2197 | if (rc) | |
2198 | goto free_pages; | |
2199 | ||
2200 | *mid = smb2_find_mid(server, buf); | |
2201 | if (*mid == NULL) | |
2202 | cifs_dbg(FYI, "mid not found\n"); | |
2203 | else { | |
2204 | cifs_dbg(FYI, "mid found\n"); | |
2205 | (*mid)->decrypted = true; | |
2206 | rc = handle_read_data(server, *mid, buf, | |
2207 | server->vals->read_rsp_size, | |
2208 | pages, npages, len); | |
2209 | } | |
2210 | ||
2211 | free_pages: | |
2212 | for (i = i - 1; i >= 0; i--) | |
2213 | put_page(pages[i]); | |
2214 | kfree(pages); | |
2215 | return rc; | |
2216 | discard_data: | |
2217 | cifs_discard_remaining_data(server); | |
2218 | goto free_pages; | |
2219 | } | |
2220 | ||
4326ed2f PS |
2221 | static int |
2222 | receive_encrypted_standard(struct TCP_Server_Info *server, | |
2223 | struct mid_q_entry **mid) | |
2224 | { | |
2225 | int length; | |
2226 | char *buf = server->smallbuf; | |
2227 | unsigned int pdu_length = get_rfc1002_length(buf); | |
2228 | unsigned int buf_size; | |
2229 | struct mid_q_entry *mid_entry; | |
2230 | ||
2231 | /* switch to large buffer if too big for a small one */ | |
2232 | if (pdu_length + 4 > MAX_CIFS_SMALL_BUFFER_SIZE) { | |
2233 | server->large_buf = true; | |
2234 | memcpy(server->bigbuf, buf, server->total_read); | |
2235 | buf = server->bigbuf; | |
2236 | } | |
2237 | ||
2238 | /* now read the rest */ | |
2239 | length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, | |
2240 | pdu_length - HEADER_SIZE(server) + 1 + 4); | |
2241 | if (length < 0) | |
2242 | return length; | |
2243 | server->total_read += length; | |
2244 | ||
2245 | buf_size = pdu_length + 4 - sizeof(struct smb2_transform_hdr); | |
2246 | length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0); | |
2247 | if (length) | |
2248 | return length; | |
2249 | ||
2250 | mid_entry = smb2_find_mid(server, buf); | |
2251 | if (mid_entry == NULL) | |
2252 | cifs_dbg(FYI, "mid not found\n"); | |
2253 | else { | |
2254 | cifs_dbg(FYI, "mid found\n"); | |
2255 | mid_entry->decrypted = true; | |
2256 | } | |
2257 | ||
2258 | *mid = mid_entry; | |
2259 | ||
2260 | if (mid_entry && mid_entry->handle) | |
2261 | return mid_entry->handle(server, mid_entry); | |
2262 | ||
2263 | return cifs_handle_standard(server, mid_entry); | |
2264 | } | |
2265 | ||
2266 | static int | |
2267 | smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid) | |
2268 | { | |
2269 | char *buf = server->smallbuf; | |
2270 | unsigned int pdu_length = get_rfc1002_length(buf); | |
2271 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; | |
2272 | unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize); | |
2273 | ||
2274 | if (pdu_length + 4 < sizeof(struct smb2_transform_hdr) + | |
2275 | sizeof(struct smb2_sync_hdr)) { | |
2276 | cifs_dbg(VFS, "Transform message is too small (%u)\n", | |
2277 | pdu_length); | |
2278 | cifs_reconnect(server); | |
2279 | wake_up(&server->response_q); | |
2280 | return -ECONNABORTED; | |
2281 | } | |
2282 | ||
2283 | if (pdu_length + 4 < orig_len + sizeof(struct smb2_transform_hdr)) { | |
2284 | cifs_dbg(VFS, "Transform message is broken\n"); | |
2285 | cifs_reconnect(server); | |
2286 | wake_up(&server->response_q); | |
2287 | return -ECONNABORTED; | |
2288 | } | |
2289 | ||
c42a6abe PS |
2290 | if (pdu_length + 4 > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) |
2291 | return receive_encrypted_read(server, mid); | |
4326ed2f PS |
2292 | |
2293 | return receive_encrypted_standard(server, mid); | |
2294 | } | |
2295 | ||
2296 | int | |
2297 | smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |
2298 | { | |
2299 | char *buf = server->large_buf ? server->bigbuf : server->smallbuf; | |
2300 | ||
2301 | return handle_read_data(server, mid, buf, get_rfc1002_length(buf) + 4, | |
2302 | NULL, 0, 0); | |
2303 | } | |
2304 | ||
53ef1016 | 2305 | struct smb_version_operations smb20_operations = { |
027e8eec | 2306 | .compare_fids = smb2_compare_fids, |
2dc7e1c0 | 2307 | .setup_request = smb2_setup_request, |
c95b8eed | 2308 | .setup_async_request = smb2_setup_async_request, |
2dc7e1c0 | 2309 | .check_receive = smb2_check_receive, |
28ea5290 PS |
2310 | .add_credits = smb2_add_credits, |
2311 | .set_credits = smb2_set_credits, | |
2312 | .get_credits_field = smb2_get_credits_field, | |
2313 | .get_credits = smb2_get_credits, | |
cb7e9eab | 2314 | .wait_mtu_credits = cifs_wait_mtu_credits, |
2dc7e1c0 | 2315 | .get_next_mid = smb2_get_next_mid, |
09a4707e PS |
2316 | .read_data_offset = smb2_read_data_offset, |
2317 | .read_data_length = smb2_read_data_length, | |
2318 | .map_error = map_smb2_to_linux_error, | |
093b2bda PS |
2319 | .find_mid = smb2_find_mid, |
2320 | .check_message = smb2_check_message, | |
2321 | .dump_detail = smb2_dump_detail, | |
d60622eb PS |
2322 | .clear_stats = smb2_clear_stats, |
2323 | .print_stats = smb2_print_stats, | |
983c88a4 | 2324 | .is_oplock_break = smb2_is_valid_oplock_break, |
c11f1df5 | 2325 | .downgrade_oplock = smb2_downgrade_oplock, |
ec2e4523 PS |
2326 | .need_neg = smb2_need_neg, |
2327 | .negotiate = smb2_negotiate, | |
3a3bab50 PS |
2328 | .negotiate_wsize = smb2_negotiate_wsize, |
2329 | .negotiate_rsize = smb2_negotiate_rsize, | |
5478f9ba PS |
2330 | .sess_setup = SMB2_sess_setup, |
2331 | .logoff = SMB2_logoff, | |
faaf946a PS |
2332 | .tree_connect = SMB2_tcon, |
2333 | .tree_disconnect = SMB2_tdis, | |
34f62640 | 2334 | .qfs_tcon = smb2_qfs_tcon, |
2503a0db | 2335 | .is_path_accessible = smb2_is_path_accessible, |
9094fad1 PS |
2336 | .can_echo = smb2_can_echo, |
2337 | .echo = SMB2_echo, | |
be4cb9e3 PS |
2338 | .query_path_info = smb2_query_path_info, |
2339 | .get_srv_inum = smb2_get_srv_inum, | |
b7546bc5 | 2340 | .query_file_info = smb2_query_file_info, |
c839ff24 PS |
2341 | .set_path_size = smb2_set_path_size, |
2342 | .set_file_size = smb2_set_file_size, | |
1feeaac7 | 2343 | .set_file_info = smb2_set_file_info, |
64a5cfa6 | 2344 | .set_compression = smb2_set_compression, |
a0e73183 PS |
2345 | .mkdir = smb2_mkdir, |
2346 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
1a500f01 | 2347 | .rmdir = smb2_rmdir, |
cbe6f439 | 2348 | .unlink = smb2_unlink, |
35143eb5 | 2349 | .rename = smb2_rename_path, |
568798cc | 2350 | .create_hardlink = smb2_create_hardlink, |
b42bf888 | 2351 | .query_symlink = smb2_query_symlink, |
5b23c97d SP |
2352 | .query_mf_symlink = smb3_query_mf_symlink, |
2353 | .create_mf_symlink = smb3_create_mf_symlink, | |
f0df737e PS |
2354 | .open = smb2_open_file, |
2355 | .set_fid = smb2_set_fid, | |
2356 | .close = smb2_close_file, | |
7a5cfb19 | 2357 | .flush = smb2_flush_file, |
09a4707e | 2358 | .async_readv = smb2_async_readv, |
33319141 | 2359 | .async_writev = smb2_async_writev, |
d8e05039 | 2360 | .sync_read = smb2_sync_read, |
009d3443 | 2361 | .sync_write = smb2_sync_write, |
d324f08d PS |
2362 | .query_dir_first = smb2_query_dir_first, |
2363 | .query_dir_next = smb2_query_dir_next, | |
2364 | .close_dir = smb2_close_dir, | |
2365 | .calc_smb_size = smb2_calc_size, | |
2e44b288 | 2366 | .is_status_pending = smb2_is_status_pending, |
983c88a4 | 2367 | .oplock_response = smb2_oplock_response, |
6fc05c25 | 2368 | .queryfs = smb2_queryfs, |
f7ba7fe6 PS |
2369 | .mand_lock = smb2_mand_lock, |
2370 | .mand_unlock_range = smb2_unlock_range, | |
b140799a | 2371 | .push_mand_locks = smb2_push_mandatory_locks, |
b8c32dbb PS |
2372 | .get_lease_key = smb2_get_lease_key, |
2373 | .set_lease_key = smb2_set_lease_key, | |
2374 | .new_lease_key = smb2_new_lease_key, | |
38107d45 | 2375 | .calc_signature = smb2_calc_signature, |
53ef1016 PS |
2376 | .is_read_op = smb2_is_read_op, |
2377 | .set_oplock_level = smb2_set_oplock_level, | |
a41a28bd | 2378 | .create_lease_buf = smb2_create_lease_buf, |
b5c7cde3 | 2379 | .parse_lease_buf = smb2_parse_lease_buf, |
41c1358e | 2380 | .clone_range = smb2_clone_range, |
7f6c5008 | 2381 | .wp_retry_size = smb2_wp_retry_size, |
52755808 | 2382 | .dir_needs_close = smb2_dir_needs_close, |
9d49640a | 2383 | .get_dfs_refer = smb2_get_dfs_refer, |
38107d45 SF |
2384 | }; |
2385 | ||
53ef1016 PS |
2386 | struct smb_version_operations smb21_operations = { |
2387 | .compare_fids = smb2_compare_fids, | |
2388 | .setup_request = smb2_setup_request, | |
2389 | .setup_async_request = smb2_setup_async_request, | |
2390 | .check_receive = smb2_check_receive, | |
2391 | .add_credits = smb2_add_credits, | |
2392 | .set_credits = smb2_set_credits, | |
2393 | .get_credits_field = smb2_get_credits_field, | |
2394 | .get_credits = smb2_get_credits, | |
cb7e9eab | 2395 | .wait_mtu_credits = smb2_wait_mtu_credits, |
53ef1016 PS |
2396 | .get_next_mid = smb2_get_next_mid, |
2397 | .read_data_offset = smb2_read_data_offset, | |
2398 | .read_data_length = smb2_read_data_length, | |
2399 | .map_error = map_smb2_to_linux_error, | |
2400 | .find_mid = smb2_find_mid, | |
2401 | .check_message = smb2_check_message, | |
2402 | .dump_detail = smb2_dump_detail, | |
2403 | .clear_stats = smb2_clear_stats, | |
2404 | .print_stats = smb2_print_stats, | |
2405 | .is_oplock_break = smb2_is_valid_oplock_break, | |
c11f1df5 | 2406 | .downgrade_oplock = smb2_downgrade_oplock, |
53ef1016 PS |
2407 | .need_neg = smb2_need_neg, |
2408 | .negotiate = smb2_negotiate, | |
2409 | .negotiate_wsize = smb2_negotiate_wsize, | |
2410 | .negotiate_rsize = smb2_negotiate_rsize, | |
2411 | .sess_setup = SMB2_sess_setup, | |
2412 | .logoff = SMB2_logoff, | |
2413 | .tree_connect = SMB2_tcon, | |
2414 | .tree_disconnect = SMB2_tdis, | |
34f62640 | 2415 | .qfs_tcon = smb2_qfs_tcon, |
53ef1016 PS |
2416 | .is_path_accessible = smb2_is_path_accessible, |
2417 | .can_echo = smb2_can_echo, | |
2418 | .echo = SMB2_echo, | |
2419 | .query_path_info = smb2_query_path_info, | |
2420 | .get_srv_inum = smb2_get_srv_inum, | |
2421 | .query_file_info = smb2_query_file_info, | |
2422 | .set_path_size = smb2_set_path_size, | |
2423 | .set_file_size = smb2_set_file_size, | |
2424 | .set_file_info = smb2_set_file_info, | |
64a5cfa6 | 2425 | .set_compression = smb2_set_compression, |
53ef1016 PS |
2426 | .mkdir = smb2_mkdir, |
2427 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
2428 | .rmdir = smb2_rmdir, | |
2429 | .unlink = smb2_unlink, | |
2430 | .rename = smb2_rename_path, | |
2431 | .create_hardlink = smb2_create_hardlink, | |
2432 | .query_symlink = smb2_query_symlink, | |
c22870ea | 2433 | .query_mf_symlink = smb3_query_mf_symlink, |
5ab97578 | 2434 | .create_mf_symlink = smb3_create_mf_symlink, |
53ef1016 PS |
2435 | .open = smb2_open_file, |
2436 | .set_fid = smb2_set_fid, | |
2437 | .close = smb2_close_file, | |
2438 | .flush = smb2_flush_file, | |
2439 | .async_readv = smb2_async_readv, | |
2440 | .async_writev = smb2_async_writev, | |
2441 | .sync_read = smb2_sync_read, | |
2442 | .sync_write = smb2_sync_write, | |
2443 | .query_dir_first = smb2_query_dir_first, | |
2444 | .query_dir_next = smb2_query_dir_next, | |
2445 | .close_dir = smb2_close_dir, | |
2446 | .calc_smb_size = smb2_calc_size, | |
2447 | .is_status_pending = smb2_is_status_pending, | |
2448 | .oplock_response = smb2_oplock_response, | |
2449 | .queryfs = smb2_queryfs, | |
2450 | .mand_lock = smb2_mand_lock, | |
2451 | .mand_unlock_range = smb2_unlock_range, | |
2452 | .push_mand_locks = smb2_push_mandatory_locks, | |
2453 | .get_lease_key = smb2_get_lease_key, | |
2454 | .set_lease_key = smb2_set_lease_key, | |
2455 | .new_lease_key = smb2_new_lease_key, | |
2456 | .calc_signature = smb2_calc_signature, | |
2457 | .is_read_op = smb21_is_read_op, | |
2458 | .set_oplock_level = smb21_set_oplock_level, | |
a41a28bd | 2459 | .create_lease_buf = smb2_create_lease_buf, |
b5c7cde3 | 2460 | .parse_lease_buf = smb2_parse_lease_buf, |
41c1358e | 2461 | .clone_range = smb2_clone_range, |
7f6c5008 | 2462 | .wp_retry_size = smb2_wp_retry_size, |
52755808 | 2463 | .dir_needs_close = smb2_dir_needs_close, |
834170c8 | 2464 | .enum_snapshots = smb3_enum_snapshots, |
9d49640a | 2465 | .get_dfs_refer = smb2_get_dfs_refer, |
53ef1016 | 2466 | }; |
38107d45 SF |
2467 | |
2468 | struct smb_version_operations smb30_operations = { | |
2469 | .compare_fids = smb2_compare_fids, | |
2470 | .setup_request = smb2_setup_request, | |
2471 | .setup_async_request = smb2_setup_async_request, | |
2472 | .check_receive = smb2_check_receive, | |
2473 | .add_credits = smb2_add_credits, | |
2474 | .set_credits = smb2_set_credits, | |
2475 | .get_credits_field = smb2_get_credits_field, | |
2476 | .get_credits = smb2_get_credits, | |
cb7e9eab | 2477 | .wait_mtu_credits = smb2_wait_mtu_credits, |
38107d45 SF |
2478 | .get_next_mid = smb2_get_next_mid, |
2479 | .read_data_offset = smb2_read_data_offset, | |
2480 | .read_data_length = smb2_read_data_length, | |
2481 | .map_error = map_smb2_to_linux_error, | |
2482 | .find_mid = smb2_find_mid, | |
2483 | .check_message = smb2_check_message, | |
2484 | .dump_detail = smb2_dump_detail, | |
2485 | .clear_stats = smb2_clear_stats, | |
2486 | .print_stats = smb2_print_stats, | |
769ee6a4 | 2487 | .dump_share_caps = smb2_dump_share_caps, |
38107d45 | 2488 | .is_oplock_break = smb2_is_valid_oplock_break, |
c11f1df5 | 2489 | .downgrade_oplock = smb2_downgrade_oplock, |
38107d45 SF |
2490 | .need_neg = smb2_need_neg, |
2491 | .negotiate = smb2_negotiate, | |
2492 | .negotiate_wsize = smb2_negotiate_wsize, | |
2493 | .negotiate_rsize = smb2_negotiate_rsize, | |
2494 | .sess_setup = SMB2_sess_setup, | |
2495 | .logoff = SMB2_logoff, | |
2496 | .tree_connect = SMB2_tcon, | |
2497 | .tree_disconnect = SMB2_tdis, | |
af6a12ea | 2498 | .qfs_tcon = smb3_qfs_tcon, |
38107d45 SF |
2499 | .is_path_accessible = smb2_is_path_accessible, |
2500 | .can_echo = smb2_can_echo, | |
2501 | .echo = SMB2_echo, | |
2502 | .query_path_info = smb2_query_path_info, | |
2503 | .get_srv_inum = smb2_get_srv_inum, | |
2504 | .query_file_info = smb2_query_file_info, | |
2505 | .set_path_size = smb2_set_path_size, | |
2506 | .set_file_size = smb2_set_file_size, | |
2507 | .set_file_info = smb2_set_file_info, | |
64a5cfa6 | 2508 | .set_compression = smb2_set_compression, |
38107d45 SF |
2509 | .mkdir = smb2_mkdir, |
2510 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
2511 | .rmdir = smb2_rmdir, | |
2512 | .unlink = smb2_unlink, | |
2513 | .rename = smb2_rename_path, | |
2514 | .create_hardlink = smb2_create_hardlink, | |
b42bf888 | 2515 | .query_symlink = smb2_query_symlink, |
c22870ea | 2516 | .query_mf_symlink = smb3_query_mf_symlink, |
5ab97578 | 2517 | .create_mf_symlink = smb3_create_mf_symlink, |
38107d45 SF |
2518 | .open = smb2_open_file, |
2519 | .set_fid = smb2_set_fid, | |
2520 | .close = smb2_close_file, | |
2521 | .flush = smb2_flush_file, | |
2522 | .async_readv = smb2_async_readv, | |
2523 | .async_writev = smb2_async_writev, | |
2524 | .sync_read = smb2_sync_read, | |
2525 | .sync_write = smb2_sync_write, | |
2526 | .query_dir_first = smb2_query_dir_first, | |
2527 | .query_dir_next = smb2_query_dir_next, | |
2528 | .close_dir = smb2_close_dir, | |
2529 | .calc_smb_size = smb2_calc_size, | |
2530 | .is_status_pending = smb2_is_status_pending, | |
2531 | .oplock_response = smb2_oplock_response, | |
2532 | .queryfs = smb2_queryfs, | |
2533 | .mand_lock = smb2_mand_lock, | |
2534 | .mand_unlock_range = smb2_unlock_range, | |
2535 | .push_mand_locks = smb2_push_mandatory_locks, | |
2536 | .get_lease_key = smb2_get_lease_key, | |
2537 | .set_lease_key = smb2_set_lease_key, | |
2538 | .new_lease_key = smb2_new_lease_key, | |
373512ec | 2539 | .generate_signingkey = generate_smb30signingkey, |
38107d45 | 2540 | .calc_signature = smb3_calc_signature, |
b3152e2c | 2541 | .set_integrity = smb3_set_integrity, |
53ef1016 | 2542 | .is_read_op = smb21_is_read_op, |
42873b0a | 2543 | .set_oplock_level = smb3_set_oplock_level, |
f047390a PS |
2544 | .create_lease_buf = smb3_create_lease_buf, |
2545 | .parse_lease_buf = smb3_parse_lease_buf, | |
41c1358e | 2546 | .clone_range = smb2_clone_range, |
ca9e7a1c | 2547 | .duplicate_extents = smb2_duplicate_extents, |
ff1c038a | 2548 | .validate_negotiate = smb3_validate_negotiate, |
7f6c5008 | 2549 | .wp_retry_size = smb2_wp_retry_size, |
52755808 | 2550 | .dir_needs_close = smb2_dir_needs_close, |
31742c5a | 2551 | .fallocate = smb3_fallocate, |
834170c8 | 2552 | .enum_snapshots = smb3_enum_snapshots, |
026e93dc PS |
2553 | .init_transform_rq = smb3_init_transform_rq, |
2554 | .free_transform_rq = smb3_free_transform_rq, | |
4326ed2f PS |
2555 | .is_transform_hdr = smb3_is_transform_hdr, |
2556 | .receive_transform = smb3_receive_transform, | |
9d49640a | 2557 | .get_dfs_refer = smb2_get_dfs_refer, |
1080ef75 SF |
2558 | }; |
2559 | ||
aab1893d SF |
2560 | #ifdef CONFIG_CIFS_SMB311 |
2561 | struct smb_version_operations smb311_operations = { | |
2562 | .compare_fids = smb2_compare_fids, | |
2563 | .setup_request = smb2_setup_request, | |
2564 | .setup_async_request = smb2_setup_async_request, | |
2565 | .check_receive = smb2_check_receive, | |
2566 | .add_credits = smb2_add_credits, | |
2567 | .set_credits = smb2_set_credits, | |
2568 | .get_credits_field = smb2_get_credits_field, | |
2569 | .get_credits = smb2_get_credits, | |
2570 | .wait_mtu_credits = smb2_wait_mtu_credits, | |
2571 | .get_next_mid = smb2_get_next_mid, | |
2572 | .read_data_offset = smb2_read_data_offset, | |
2573 | .read_data_length = smb2_read_data_length, | |
2574 | .map_error = map_smb2_to_linux_error, | |
2575 | .find_mid = smb2_find_mid, | |
2576 | .check_message = smb2_check_message, | |
2577 | .dump_detail = smb2_dump_detail, | |
2578 | .clear_stats = smb2_clear_stats, | |
2579 | .print_stats = smb2_print_stats, | |
2580 | .dump_share_caps = smb2_dump_share_caps, | |
2581 | .is_oplock_break = smb2_is_valid_oplock_break, | |
2582 | .downgrade_oplock = smb2_downgrade_oplock, | |
2583 | .need_neg = smb2_need_neg, | |
2584 | .negotiate = smb2_negotiate, | |
2585 | .negotiate_wsize = smb2_negotiate_wsize, | |
2586 | .negotiate_rsize = smb2_negotiate_rsize, | |
2587 | .sess_setup = SMB2_sess_setup, | |
2588 | .logoff = SMB2_logoff, | |
2589 | .tree_connect = SMB2_tcon, | |
2590 | .tree_disconnect = SMB2_tdis, | |
2591 | .qfs_tcon = smb3_qfs_tcon, | |
2592 | .is_path_accessible = smb2_is_path_accessible, | |
2593 | .can_echo = smb2_can_echo, | |
2594 | .echo = SMB2_echo, | |
2595 | .query_path_info = smb2_query_path_info, | |
2596 | .get_srv_inum = smb2_get_srv_inum, | |
2597 | .query_file_info = smb2_query_file_info, | |
2598 | .set_path_size = smb2_set_path_size, | |
2599 | .set_file_size = smb2_set_file_size, | |
2600 | .set_file_info = smb2_set_file_info, | |
2601 | .set_compression = smb2_set_compression, | |
2602 | .mkdir = smb2_mkdir, | |
2603 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
2604 | .rmdir = smb2_rmdir, | |
2605 | .unlink = smb2_unlink, | |
2606 | .rename = smb2_rename_path, | |
2607 | .create_hardlink = smb2_create_hardlink, | |
2608 | .query_symlink = smb2_query_symlink, | |
2609 | .query_mf_symlink = smb3_query_mf_symlink, | |
2610 | .create_mf_symlink = smb3_create_mf_symlink, | |
2611 | .open = smb2_open_file, | |
2612 | .set_fid = smb2_set_fid, | |
2613 | .close = smb2_close_file, | |
2614 | .flush = smb2_flush_file, | |
2615 | .async_readv = smb2_async_readv, | |
2616 | .async_writev = smb2_async_writev, | |
2617 | .sync_read = smb2_sync_read, | |
2618 | .sync_write = smb2_sync_write, | |
2619 | .query_dir_first = smb2_query_dir_first, | |
2620 | .query_dir_next = smb2_query_dir_next, | |
2621 | .close_dir = smb2_close_dir, | |
2622 | .calc_smb_size = smb2_calc_size, | |
2623 | .is_status_pending = smb2_is_status_pending, | |
2624 | .oplock_response = smb2_oplock_response, | |
2625 | .queryfs = smb2_queryfs, | |
2626 | .mand_lock = smb2_mand_lock, | |
2627 | .mand_unlock_range = smb2_unlock_range, | |
2628 | .push_mand_locks = smb2_push_mandatory_locks, | |
2629 | .get_lease_key = smb2_get_lease_key, | |
2630 | .set_lease_key = smb2_set_lease_key, | |
2631 | .new_lease_key = smb2_new_lease_key, | |
373512ec | 2632 | .generate_signingkey = generate_smb311signingkey, |
aab1893d | 2633 | .calc_signature = smb3_calc_signature, |
b3152e2c | 2634 | .set_integrity = smb3_set_integrity, |
aab1893d SF |
2635 | .is_read_op = smb21_is_read_op, |
2636 | .set_oplock_level = smb3_set_oplock_level, | |
2637 | .create_lease_buf = smb3_create_lease_buf, | |
2638 | .parse_lease_buf = smb3_parse_lease_buf, | |
2639 | .clone_range = smb2_clone_range, | |
02b16665 | 2640 | .duplicate_extents = smb2_duplicate_extents, |
aab1893d SF |
2641 | /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */ |
2642 | .wp_retry_size = smb2_wp_retry_size, | |
2643 | .dir_needs_close = smb2_dir_needs_close, | |
2644 | .fallocate = smb3_fallocate, | |
834170c8 | 2645 | .enum_snapshots = smb3_enum_snapshots, |
026e93dc PS |
2646 | .init_transform_rq = smb3_init_transform_rq, |
2647 | .free_transform_rq = smb3_free_transform_rq, | |
4326ed2f PS |
2648 | .is_transform_hdr = smb3_is_transform_hdr, |
2649 | .receive_transform = smb3_receive_transform, | |
9d49640a | 2650 | .get_dfs_refer = smb2_get_dfs_refer, |
aab1893d SF |
2651 | }; |
2652 | #endif /* CIFS_SMB311 */ | |
2653 | ||
dd446b16 SF |
2654 | struct smb_version_values smb20_values = { |
2655 | .version_string = SMB20_VERSION_STRING, | |
2656 | .protocol_id = SMB20_PROT_ID, | |
2657 | .req_capabilities = 0, /* MBZ */ | |
2658 | .large_lock_type = 0, | |
2659 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
2660 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
2661 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
2662 | .header_size = sizeof(struct smb2_hdr), | |
2663 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
2664 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
2665 | .lock_cmd = SMB2_LOCK, | |
2666 | .cap_unix = 0, | |
2667 | .cap_nt_find = SMB2_NT_FIND, | |
2668 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
2669 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
2670 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
a41a28bd | 2671 | .create_lease_size = sizeof(struct create_lease), |
dd446b16 SF |
2672 | }; |
2673 | ||
1080ef75 SF |
2674 | struct smb_version_values smb21_values = { |
2675 | .version_string = SMB21_VERSION_STRING, | |
e4aa25e7 SF |
2676 | .protocol_id = SMB21_PROT_ID, |
2677 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ | |
2678 | .large_lock_type = 0, | |
2679 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
2680 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
2681 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
2682 | .header_size = sizeof(struct smb2_hdr), | |
2683 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
2684 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
2685 | .lock_cmd = SMB2_LOCK, | |
2686 | .cap_unix = 0, | |
2687 | .cap_nt_find = SMB2_NT_FIND, | |
2688 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
2689 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
2690 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
a41a28bd | 2691 | .create_lease_size = sizeof(struct create_lease), |
e4aa25e7 SF |
2692 | }; |
2693 | ||
2694 | struct smb_version_values smb30_values = { | |
2695 | .version_string = SMB30_VERSION_STRING, | |
2696 | .protocol_id = SMB30_PROT_ID, | |
373512ec | 2697 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, |
027e8eec PS |
2698 | .large_lock_type = 0, |
2699 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
2700 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
2701 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
093b2bda PS |
2702 | .header_size = sizeof(struct smb2_hdr), |
2703 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
09a4707e | 2704 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
2dc7e1c0 | 2705 | .lock_cmd = SMB2_LOCK, |
29e20f9c PS |
2706 | .cap_unix = 0, |
2707 | .cap_nt_find = SMB2_NT_FIND, | |
2708 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
2709 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
2710 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
f047390a | 2711 | .create_lease_size = sizeof(struct create_lease_v2), |
1080ef75 | 2712 | }; |
20b6d8b4 SF |
2713 | |
2714 | struct smb_version_values smb302_values = { | |
2715 | .version_string = SMB302_VERSION_STRING, | |
2716 | .protocol_id = SMB302_PROT_ID, | |
373512ec | 2717 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, |
20b6d8b4 SF |
2718 | .large_lock_type = 0, |
2719 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
2720 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
2721 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
2722 | .header_size = sizeof(struct smb2_hdr), | |
2723 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
2724 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
2725 | .lock_cmd = SMB2_LOCK, | |
2726 | .cap_unix = 0, | |
2727 | .cap_nt_find = SMB2_NT_FIND, | |
2728 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
2729 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
2730 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
f047390a | 2731 | .create_lease_size = sizeof(struct create_lease_v2), |
20b6d8b4 | 2732 | }; |
5f7fbf73 SF |
2733 | |
2734 | #ifdef CONFIG_CIFS_SMB311 | |
2735 | struct smb_version_values smb311_values = { | |
2736 | .version_string = SMB311_VERSION_STRING, | |
2737 | .protocol_id = SMB311_PROT_ID, | |
b618f001 | 2738 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES, |
5f7fbf73 SF |
2739 | .large_lock_type = 0, |
2740 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
2741 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
2742 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
2743 | .header_size = sizeof(struct smb2_hdr), | |
2744 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
2745 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
2746 | .lock_cmd = SMB2_LOCK, | |
2747 | .cap_unix = 0, | |
2748 | .cap_nt_find = SMB2_NT_FIND, | |
2749 | .cap_large_files = SMB2_LARGE_FILES, | |
2750 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
2751 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
2752 | .create_lease_size = sizeof(struct create_lease_v2), | |
2753 | }; | |
2754 | #endif /* SMB311 */ |