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