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
20 #include <linux/pagemap.h>
21 #include <linux/vfs.h>
22 #include <linux/falloc.h>
23 #include "cifsglob.h"
24 #include "smb2pdu.h"
25 #include "smb2proto.h"
26 #include "cifsproto.h"
27 #include "cifs_debug.h"
28 #include "cifs_unicode.h"
29 #include "smb2status.h"
30 #include "smb2glob.h"
31
32 static int
change_conf(struct TCP_Server_Info * server)33 change_conf(struct TCP_Server_Info *server)
34 {
35 server->credits += server->echo_credits + server->oplock_credits;
36 server->oplock_credits = server->echo_credits = 0;
37 switch (server->credits) {
38 case 0:
39 return -1;
40 case 1:
41 server->echoes = false;
42 server->oplocks = false;
43 cifs_dbg(VFS, "disabling echoes and oplocks\n");
44 break;
45 case 2:
46 server->echoes = true;
47 server->oplocks = false;
48 server->echo_credits = 1;
49 cifs_dbg(FYI, "disabling oplocks\n");
50 break;
51 default:
52 server->echoes = true;
53 if (enable_oplocks) {
54 server->oplocks = true;
55 server->oplock_credits = 1;
56 } else
57 server->oplocks = false;
58
59 server->echo_credits = 1;
60 }
61 server->credits -= server->echo_credits + server->oplock_credits;
62 return 0;
63 }
64
65 static void
smb2_add_credits(struct TCP_Server_Info * server,const unsigned int add,const int optype)66 smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
67 const int optype)
68 {
69 int *val, rc = 0;
70 spin_lock(&server->req_lock);
71 val = server->ops->get_credits_field(server, optype);
72 *val += add;
73 server->in_flight--;
74 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
75 rc = change_conf(server);
76 /*
77 * Sometimes server returns 0 credits on oplock break ack - we need to
78 * rebalance credits in this case.
79 */
80 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
81 server->oplocks) {
82 if (server->credits > 1) {
83 server->credits--;
84 server->oplock_credits++;
85 }
86 }
87 spin_unlock(&server->req_lock);
88 wake_up(&server->request_q);
89 if (rc)
90 cifs_reconnect(server);
91 }
92
93 static void
smb2_set_credits(struct TCP_Server_Info * server,const int val)94 smb2_set_credits(struct TCP_Server_Info *server, const int val)
95 {
96 spin_lock(&server->req_lock);
97 server->credits = val;
98 spin_unlock(&server->req_lock);
99 }
100
101 static int *
smb2_get_credits_field(struct TCP_Server_Info * server,const int optype)102 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
103 {
104 switch (optype) {
105 case CIFS_ECHO_OP:
106 return &server->echo_credits;
107 case CIFS_OBREAK_OP:
108 return &server->oplock_credits;
109 default:
110 return &server->credits;
111 }
112 }
113
114 static unsigned int
smb2_get_credits(struct mid_q_entry * mid)115 smb2_get_credits(struct mid_q_entry *mid)
116 {
117 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
118 }
119
120 static int
smb2_wait_mtu_credits(struct TCP_Server_Info * server,unsigned int size,unsigned int * num,unsigned int * credits)121 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
122 unsigned int *num, unsigned int *credits)
123 {
124 int rc = 0;
125 unsigned int scredits;
126
127 spin_lock(&server->req_lock);
128 while (1) {
129 if (server->credits <= 0) {
130 spin_unlock(&server->req_lock);
131 cifs_num_waiters_inc(server);
132 rc = wait_event_killable(server->request_q,
133 has_credits(server, &server->credits));
134 cifs_num_waiters_dec(server);
135 if (rc)
136 return rc;
137 spin_lock(&server->req_lock);
138 } else {
139 if (server->tcpStatus == CifsExiting) {
140 spin_unlock(&server->req_lock);
141 return -ENOENT;
142 }
143
144 scredits = server->credits;
145 /* can deadlock with reopen */
146 if (scredits == 1) {
147 *num = SMB2_MAX_BUFFER_SIZE;
148 *credits = 0;
149 break;
150 }
151
152 /* leave one credit for a possible reopen */
153 scredits--;
154 *num = min_t(unsigned int, size,
155 scredits * SMB2_MAX_BUFFER_SIZE);
156
157 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
158 server->credits -= *credits;
159 server->in_flight++;
160 break;
161 }
162 }
163 spin_unlock(&server->req_lock);
164 return rc;
165 }
166
167 static __u64
smb2_get_next_mid(struct TCP_Server_Info * server)168 smb2_get_next_mid(struct TCP_Server_Info *server)
169 {
170 __u64 mid;
171 /* for SMB2 we need the current value */
172 spin_lock(&GlobalMid_Lock);
173 mid = server->CurrentMid++;
174 spin_unlock(&GlobalMid_Lock);
175 return mid;
176 }
177
178 static struct mid_q_entry *
smb2_find_mid(struct TCP_Server_Info * server,char * buf)179 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
180 {
181 struct mid_q_entry *mid;
182 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
183 __u64 wire_mid = le64_to_cpu(hdr->MessageId);
184
185 spin_lock(&GlobalMid_Lock);
186 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
187 if ((mid->mid == wire_mid) &&
188 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
189 (mid->command == hdr->Command)) {
190 spin_unlock(&GlobalMid_Lock);
191 return mid;
192 }
193 }
194 spin_unlock(&GlobalMid_Lock);
195 return NULL;
196 }
197
198 static void
smb2_dump_detail(void * buf)199 smb2_dump_detail(void *buf)
200 {
201 #ifdef CONFIG_CIFS_DEBUG2
202 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
203
204 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
205 smb->Command, smb->Status, smb->Flags, smb->MessageId,
206 smb->ProcessId);
207 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
208 #endif
209 }
210
211 static bool
smb2_need_neg(struct TCP_Server_Info * server)212 smb2_need_neg(struct TCP_Server_Info *server)
213 {
214 return server->max_read == 0;
215 }
216
217 static int
smb2_negotiate(const unsigned int xid,struct cifs_ses * ses)218 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
219 {
220 int rc;
221 ses->server->CurrentMid = 0;
222 rc = SMB2_negotiate(xid, ses);
223 /* BB we probably don't need to retry with modern servers */
224 if (rc == -EAGAIN)
225 rc = -EHOSTDOWN;
226 return rc;
227 }
228
229 static unsigned int
smb2_negotiate_wsize(struct cifs_tcon * tcon,struct smb_vol * volume_info)230 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
231 {
232 struct TCP_Server_Info *server = tcon->ses->server;
233 unsigned int wsize;
234
235 /* start with specified wsize, or default */
236 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
237 wsize = min_t(unsigned int, wsize, server->max_write);
238
239 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
240 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
241
242 return wsize;
243 }
244
245 static unsigned int
smb2_negotiate_rsize(struct cifs_tcon * tcon,struct smb_vol * volume_info)246 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
247 {
248 struct TCP_Server_Info *server = tcon->ses->server;
249 unsigned int rsize;
250
251 /* start with specified rsize, or default */
252 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
253 rsize = min_t(unsigned int, rsize, server->max_read);
254
255 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
256 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
257
258 return rsize;
259 }
260
261 #ifdef CONFIG_CIFS_STATS2
262 static int
SMB3_request_interfaces(const unsigned int xid,struct cifs_tcon * tcon)263 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
264 {
265 int rc;
266 unsigned int ret_data_len = 0;
267 struct network_interface_info_ioctl_rsp *out_buf;
268
269 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
270 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
271 NULL /* no data input */, 0 /* no data input */,
272 (char **)&out_buf, &ret_data_len);
273 if (rc != 0)
274 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
275 else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
276 cifs_dbg(VFS, "server returned bad net interface info buf\n");
277 rc = -EINVAL;
278 } else {
279 /* Dump info on first interface */
280 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
281 le32_to_cpu(out_buf->Capability));
282 cifs_dbg(FYI, "Link Speed %lld\n",
283 le64_to_cpu(out_buf->LinkSpeed));
284 }
285
286 return rc;
287 }
288 #endif /* STATS2 */
289
290 static void
smb3_qfs_tcon(const unsigned int xid,struct cifs_tcon * tcon)291 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
292 {
293 int rc;
294 __le16 srch_path = 0; /* Null - open root of share */
295 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
296 struct cifs_open_parms oparms;
297 struct cifs_fid fid;
298
299 oparms.tcon = tcon;
300 oparms.desired_access = FILE_READ_ATTRIBUTES;
301 oparms.disposition = FILE_OPEN;
302 oparms.create_options = 0;
303 oparms.fid = &fid;
304 oparms.reconnect = false;
305
306 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
307 if (rc)
308 return;
309
310 #ifdef CONFIG_CIFS_STATS2
311 SMB3_request_interfaces(xid, tcon);
312 #endif /* STATS2 */
313
314 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
315 FS_ATTRIBUTE_INFORMATION);
316 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
317 FS_DEVICE_INFORMATION);
318 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
319 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
320 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
321 return;
322 }
323
324 static void
smb2_qfs_tcon(const unsigned int xid,struct cifs_tcon * tcon)325 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
326 {
327 int rc;
328 __le16 srch_path = 0; /* Null - open root of share */
329 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
330 struct cifs_open_parms oparms;
331 struct cifs_fid fid;
332
333 oparms.tcon = tcon;
334 oparms.desired_access = FILE_READ_ATTRIBUTES;
335 oparms.disposition = FILE_OPEN;
336 oparms.create_options = 0;
337 oparms.fid = &fid;
338 oparms.reconnect = false;
339
340 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
341 if (rc)
342 return;
343
344 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
345 FS_ATTRIBUTE_INFORMATION);
346 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
347 FS_DEVICE_INFORMATION);
348 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
349 return;
350 }
351
352 static int
smb2_is_path_accessible(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_sb_info * cifs_sb,const char * full_path)353 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
354 struct cifs_sb_info *cifs_sb, const char *full_path)
355 {
356 int rc;
357 __le16 *utf16_path;
358 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
359 struct cifs_open_parms oparms;
360 struct cifs_fid fid;
361
362 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
363 if (!utf16_path)
364 return -ENOMEM;
365
366 oparms.tcon = tcon;
367 oparms.desired_access = FILE_READ_ATTRIBUTES;
368 oparms.disposition = FILE_OPEN;
369 oparms.create_options = 0;
370 oparms.fid = &fid;
371 oparms.reconnect = false;
372
373 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
374 if (rc) {
375 kfree(utf16_path);
376 return rc;
377 }
378
379 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
380 kfree(utf16_path);
381 return rc;
382 }
383
384 static int
smb2_get_srv_inum(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_sb_info * cifs_sb,const char * full_path,u64 * uniqueid,FILE_ALL_INFO * data)385 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
386 struct cifs_sb_info *cifs_sb, const char *full_path,
387 u64 *uniqueid, FILE_ALL_INFO *data)
388 {
389 *uniqueid = le64_to_cpu(data->IndexNumber);
390 return 0;
391 }
392
393 static int
smb2_query_file_info(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_fid * fid,FILE_ALL_INFO * data)394 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
395 struct cifs_fid *fid, FILE_ALL_INFO *data)
396 {
397 int rc;
398 struct smb2_file_all_info *smb2_data;
399
400 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
401 GFP_KERNEL);
402 if (smb2_data == NULL)
403 return -ENOMEM;
404
405 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
406 smb2_data);
407 if (!rc)
408 move_smb2_info_to_cifs(data, smb2_data);
409 kfree(smb2_data);
410 return rc;
411 }
412
413 static bool
smb2_can_echo(struct TCP_Server_Info * server)414 smb2_can_echo(struct TCP_Server_Info *server)
415 {
416 return server->echoes;
417 }
418
419 static void
smb2_clear_stats(struct cifs_tcon * tcon)420 smb2_clear_stats(struct cifs_tcon *tcon)
421 {
422 #ifdef CONFIG_CIFS_STATS
423 int i;
424 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
425 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
426 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
427 }
428 #endif
429 }
430
431 static void
smb2_dump_share_caps(struct seq_file * m,struct cifs_tcon * tcon)432 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
433 {
434 seq_puts(m, "\n\tShare Capabilities:");
435 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
436 seq_puts(m, " DFS,");
437 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
438 seq_puts(m, " CONTINUOUS AVAILABILITY,");
439 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
440 seq_puts(m, " SCALEOUT,");
441 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
442 seq_puts(m, " CLUSTER,");
443 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
444 seq_puts(m, " ASYMMETRIC,");
445 if (tcon->capabilities == 0)
446 seq_puts(m, " None");
447 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
448 seq_puts(m, " Aligned,");
449 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
450 seq_puts(m, " Partition Aligned,");
451 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
452 seq_puts(m, " SSD,");
453 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
454 seq_puts(m, " TRIM-support,");
455
456 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
457 if (tcon->perf_sector_size)
458 seq_printf(m, "\tOptimal sector size: 0x%x",
459 tcon->perf_sector_size);
460 }
461
462 static void
smb2_print_stats(struct seq_file * m,struct cifs_tcon * tcon)463 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
464 {
465 #ifdef CONFIG_CIFS_STATS
466 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
467 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
468 seq_printf(m, "\nNegotiates: %d sent %d failed",
469 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
470 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
471 seq_printf(m, "\nSessionSetups: %d sent %d failed",
472 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
473 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
474 seq_printf(m, "\nLogoffs: %d sent %d failed",
475 atomic_read(&sent[SMB2_LOGOFF_HE]),
476 atomic_read(&failed[SMB2_LOGOFF_HE]));
477 seq_printf(m, "\nTreeConnects: %d sent %d failed",
478 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
479 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
480 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
481 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
482 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
483 seq_printf(m, "\nCreates: %d sent %d failed",
484 atomic_read(&sent[SMB2_CREATE_HE]),
485 atomic_read(&failed[SMB2_CREATE_HE]));
486 seq_printf(m, "\nCloses: %d sent %d failed",
487 atomic_read(&sent[SMB2_CLOSE_HE]),
488 atomic_read(&failed[SMB2_CLOSE_HE]));
489 seq_printf(m, "\nFlushes: %d sent %d failed",
490 atomic_read(&sent[SMB2_FLUSH_HE]),
491 atomic_read(&failed[SMB2_FLUSH_HE]));
492 seq_printf(m, "\nReads: %d sent %d failed",
493 atomic_read(&sent[SMB2_READ_HE]),
494 atomic_read(&failed[SMB2_READ_HE]));
495 seq_printf(m, "\nWrites: %d sent %d failed",
496 atomic_read(&sent[SMB2_WRITE_HE]),
497 atomic_read(&failed[SMB2_WRITE_HE]));
498 seq_printf(m, "\nLocks: %d sent %d failed",
499 atomic_read(&sent[SMB2_LOCK_HE]),
500 atomic_read(&failed[SMB2_LOCK_HE]));
501 seq_printf(m, "\nIOCTLs: %d sent %d failed",
502 atomic_read(&sent[SMB2_IOCTL_HE]),
503 atomic_read(&failed[SMB2_IOCTL_HE]));
504 seq_printf(m, "\nCancels: %d sent %d failed",
505 atomic_read(&sent[SMB2_CANCEL_HE]),
506 atomic_read(&failed[SMB2_CANCEL_HE]));
507 seq_printf(m, "\nEchos: %d sent %d failed",
508 atomic_read(&sent[SMB2_ECHO_HE]),
509 atomic_read(&failed[SMB2_ECHO_HE]));
510 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
511 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
512 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
513 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
514 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
515 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
516 seq_printf(m, "\nQueryInfos: %d sent %d failed",
517 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
518 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
519 seq_printf(m, "\nSetInfos: %d sent %d failed",
520 atomic_read(&sent[SMB2_SET_INFO_HE]),
521 atomic_read(&failed[SMB2_SET_INFO_HE]));
522 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
523 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
524 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
525 #endif
526 }
527
528 static void
smb2_set_fid(struct cifsFileInfo * cfile,struct cifs_fid * fid,__u32 oplock)529 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
530 {
531 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
532 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
533
534 cfile->fid.persistent_fid = fid->persistent_fid;
535 cfile->fid.volatile_fid = fid->volatile_fid;
536 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
537 &fid->purge_cache);
538 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
539 }
540
541 static void
smb2_close_file(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_fid * fid)542 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
543 struct cifs_fid *fid)
544 {
545 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
546 }
547
548 static int
SMB2_request_res_key(const unsigned int xid,struct cifs_tcon * tcon,u64 persistent_fid,u64 volatile_fid,struct copychunk_ioctl * pcchunk)549 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
550 u64 persistent_fid, u64 volatile_fid,
551 struct copychunk_ioctl *pcchunk)
552 {
553 int rc;
554 unsigned int ret_data_len;
555 struct resume_key_req *res_key;
556
557 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
558 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
559 NULL, 0 /* no input */,
560 (char **)&res_key, &ret_data_len);
561
562 if (rc) {
563 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
564 goto req_res_key_exit;
565 }
566 if (ret_data_len < sizeof(struct resume_key_req)) {
567 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
568 rc = -EINVAL;
569 goto req_res_key_exit;
570 }
571 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
572
573 req_res_key_exit:
574 kfree(res_key);
575 return rc;
576 }
577
578 static int
smb2_clone_range(const unsigned int xid,struct cifsFileInfo * srcfile,struct cifsFileInfo * trgtfile,u64 src_off,u64 len,u64 dest_off)579 smb2_clone_range(const unsigned int xid,
580 struct cifsFileInfo *srcfile,
581 struct cifsFileInfo *trgtfile, u64 src_off,
582 u64 len, u64 dest_off)
583 {
584 int rc;
585 unsigned int ret_data_len;
586 struct copychunk_ioctl *pcchunk;
587 struct copychunk_ioctl_rsp *retbuf = NULL;
588 struct cifs_tcon *tcon;
589 int chunks_copied = 0;
590 bool chunk_sizes_updated = false;
591
592 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
593
594 if (pcchunk == NULL)
595 return -ENOMEM;
596
597 cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
598 /* Request a key from the server to identify the source of the copy */
599 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
600 srcfile->fid.persistent_fid,
601 srcfile->fid.volatile_fid, pcchunk);
602
603 /* Note: request_res_key sets res_key null only if rc !=0 */
604 if (rc)
605 goto cchunk_out;
606
607 /* For now array only one chunk long, will make more flexible later */
608 pcchunk->ChunkCount = cpu_to_le32(1);
609 pcchunk->Reserved = 0;
610 pcchunk->Reserved2 = 0;
611
612 tcon = tlink_tcon(trgtfile->tlink);
613
614 while (len > 0) {
615 pcchunk->SourceOffset = cpu_to_le64(src_off);
616 pcchunk->TargetOffset = cpu_to_le64(dest_off);
617 pcchunk->Length =
618 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
619
620 /* Request server copy to target from src identified by key */
621 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
622 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
623 true /* is_fsctl */, (char *)pcchunk,
624 sizeof(struct copychunk_ioctl), (char **)&retbuf,
625 &ret_data_len);
626 if (rc == 0) {
627 if (ret_data_len !=
628 sizeof(struct copychunk_ioctl_rsp)) {
629 cifs_dbg(VFS, "invalid cchunk response size\n");
630 rc = -EIO;
631 goto cchunk_out;
632 }
633 if (retbuf->TotalBytesWritten == 0) {
634 cifs_dbg(FYI, "no bytes copied\n");
635 rc = -EIO;
636 goto cchunk_out;
637 }
638 /*
639 * Check if server claimed to write more than we asked
640 */
641 if (le32_to_cpu(retbuf->TotalBytesWritten) >
642 le32_to_cpu(pcchunk->Length)) {
643 cifs_dbg(VFS, "invalid copy chunk response\n");
644 rc = -EIO;
645 goto cchunk_out;
646 }
647 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
648 cifs_dbg(VFS, "invalid num chunks written\n");
649 rc = -EIO;
650 goto cchunk_out;
651 }
652 chunks_copied++;
653
654 src_off += le32_to_cpu(retbuf->TotalBytesWritten);
655 dest_off += le32_to_cpu(retbuf->TotalBytesWritten);
656 len -= le32_to_cpu(retbuf->TotalBytesWritten);
657
658 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n",
659 le32_to_cpu(retbuf->ChunksWritten),
660 le32_to_cpu(retbuf->ChunkBytesWritten),
661 le32_to_cpu(retbuf->TotalBytesWritten));
662 } else if (rc == -EINVAL) {
663 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
664 goto cchunk_out;
665
666 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
667 le32_to_cpu(retbuf->ChunksWritten),
668 le32_to_cpu(retbuf->ChunkBytesWritten),
669 le32_to_cpu(retbuf->TotalBytesWritten));
670
671 /*
672 * Check if this is the first request using these sizes,
673 * (ie check if copy succeed once with original sizes
674 * and check if the server gave us different sizes after
675 * we already updated max sizes on previous request).
676 * if not then why is the server returning an error now
677 */
678 if ((chunks_copied != 0) || chunk_sizes_updated)
679 goto cchunk_out;
680
681 /* Check that server is not asking us to grow size */
682 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
683 tcon->max_bytes_chunk)
684 tcon->max_bytes_chunk =
685 le32_to_cpu(retbuf->ChunkBytesWritten);
686 else
687 goto cchunk_out; /* server gave us bogus size */
688
689 /* No need to change MaxChunks since already set to 1 */
690 chunk_sizes_updated = true;
691 } else
692 goto cchunk_out;
693 }
694
695 cchunk_out:
696 kfree(pcchunk);
697 return rc;
698 }
699
700 static int
smb2_flush_file(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_fid * fid)701 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
702 struct cifs_fid *fid)
703 {
704 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
705 }
706
707 static unsigned int
smb2_read_data_offset(char * buf)708 smb2_read_data_offset(char *buf)
709 {
710 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
711 return rsp->DataOffset;
712 }
713
714 static unsigned int
smb2_read_data_length(char * buf)715 smb2_read_data_length(char *buf)
716 {
717 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
718 return le32_to_cpu(rsp->DataLength);
719 }
720
721
722 static int
smb2_sync_read(const unsigned int xid,struct cifs_fid * pfid,struct cifs_io_parms * parms,unsigned int * bytes_read,char ** buf,int * buf_type)723 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
724 struct cifs_io_parms *parms, unsigned int *bytes_read,
725 char **buf, int *buf_type)
726 {
727 parms->persistent_fid = pfid->persistent_fid;
728 parms->volatile_fid = pfid->volatile_fid;
729 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
730 }
731
732 static int
smb2_sync_write(const unsigned int xid,struct cifs_fid * pfid,struct cifs_io_parms * parms,unsigned int * written,struct kvec * iov,unsigned long nr_segs)733 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
734 struct cifs_io_parms *parms, unsigned int *written,
735 struct kvec *iov, unsigned long nr_segs)
736 {
737
738 parms->persistent_fid = pfid->persistent_fid;
739 parms->volatile_fid = pfid->volatile_fid;
740 return SMB2_write(xid, parms, written, iov, nr_segs);
741 }
742
743 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
smb2_set_sparse(const unsigned int xid,struct cifs_tcon * tcon,struct cifsFileInfo * cfile,struct inode * inode,__u8 setsparse)744 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
745 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
746 {
747 struct cifsInodeInfo *cifsi;
748 int rc;
749
750 cifsi = CIFS_I(inode);
751
752 /* if file already sparse don't bother setting sparse again */
753 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
754 return true; /* already sparse */
755
756 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
757 return true; /* already not sparse */
758
759 /*
760 * Can't check for sparse support on share the usual way via the
761 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
762 * since Samba server doesn't set the flag on the share, yet
763 * supports the set sparse FSCTL and returns sparse correctly
764 * in the file attributes. If we fail setting sparse though we
765 * mark that server does not support sparse files for this share
766 * to avoid repeatedly sending the unsupported fsctl to server
767 * if the file is repeatedly extended.
768 */
769 if (tcon->broken_sparse_sup)
770 return false;
771
772 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
773 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
774 true /* is_fctl */, &setsparse, 1, NULL, NULL);
775 if (rc) {
776 tcon->broken_sparse_sup = true;
777 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
778 return false;
779 }
780
781 if (setsparse)
782 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
783 else
784 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
785
786 return true;
787 }
788
789 static int
smb2_set_file_size(const unsigned int xid,struct cifs_tcon * tcon,struct cifsFileInfo * cfile,__u64 size,bool set_alloc)790 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
791 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
792 {
793 __le64 eof = cpu_to_le64(size);
794 struct inode *inode;
795
796 /*
797 * If extending file more than one page make sparse. Many Linux fs
798 * make files sparse by default when extending via ftruncate
799 */
800 inode = d_inode(cfile->dentry);
801
802 if (!set_alloc && (size > inode->i_size + 8192)) {
803 __u8 set_sparse = 1;
804
805 /* whether set sparse succeeds or not, extend the file */
806 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
807 }
808
809 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
810 cfile->fid.volatile_fid, cfile->pid, &eof, false);
811 }
812
813 static int
smb2_set_compression(const unsigned int xid,struct cifs_tcon * tcon,struct cifsFileInfo * cfile)814 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
815 struct cifsFileInfo *cfile)
816 {
817 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
818 cfile->fid.volatile_fid);
819 }
820
821 static int
smb2_query_dir_first(const unsigned int xid,struct cifs_tcon * tcon,const char * path,struct cifs_sb_info * cifs_sb,struct cifs_fid * fid,__u16 search_flags,struct cifs_search_info * srch_inf)822 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
823 const char *path, struct cifs_sb_info *cifs_sb,
824 struct cifs_fid *fid, __u16 search_flags,
825 struct cifs_search_info *srch_inf)
826 {
827 __le16 *utf16_path;
828 int rc;
829 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
830 struct cifs_open_parms oparms;
831
832 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
833 if (!utf16_path)
834 return -ENOMEM;
835
836 oparms.tcon = tcon;
837 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
838 oparms.disposition = FILE_OPEN;
839 oparms.create_options = 0;
840 oparms.fid = fid;
841 oparms.reconnect = false;
842
843 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
844 kfree(utf16_path);
845 if (rc) {
846 cifs_dbg(VFS, "open dir failed\n");
847 return rc;
848 }
849
850 srch_inf->entries_in_buffer = 0;
851 srch_inf->index_of_last_entry = 0;
852
853 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
854 fid->volatile_fid, 0, srch_inf);
855 if (rc) {
856 cifs_dbg(VFS, "query directory failed\n");
857 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
858 }
859 return rc;
860 }
861
862 static int
smb2_query_dir_next(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_fid * fid,__u16 search_flags,struct cifs_search_info * srch_inf)863 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
864 struct cifs_fid *fid, __u16 search_flags,
865 struct cifs_search_info *srch_inf)
866 {
867 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
868 fid->volatile_fid, 0, srch_inf);
869 }
870
871 static int
smb2_close_dir(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_fid * fid)872 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
873 struct cifs_fid *fid)
874 {
875 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
876 }
877
878 /*
879 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
880 * the number of credits and return true. Otherwise - return false.
881 */
882 static bool
smb2_is_status_pending(char * buf,struct TCP_Server_Info * server,int length)883 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
884 {
885 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
886
887 if (hdr->Status != STATUS_PENDING)
888 return false;
889
890 if (!length) {
891 spin_lock(&server->req_lock);
892 server->credits += le16_to_cpu(hdr->CreditRequest);
893 spin_unlock(&server->req_lock);
894 wake_up(&server->request_q);
895 }
896
897 return true;
898 }
899
900 static int
smb2_oplock_response(struct cifs_tcon * tcon,struct cifs_fid * fid,struct cifsInodeInfo * cinode)901 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
902 struct cifsInodeInfo *cinode)
903 {
904 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
905 return SMB2_lease_break(0, tcon, cinode->lease_key,
906 smb2_get_lease_state(cinode));
907
908 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
909 fid->volatile_fid,
910 CIFS_CACHE_READ(cinode) ? 1 : 0);
911 }
912
913 static int
smb2_queryfs(const unsigned int xid,struct cifs_tcon * tcon,struct kstatfs * buf)914 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
915 struct kstatfs *buf)
916 {
917 int rc;
918 __le16 srch_path = 0; /* Null - open root of share */
919 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
920 struct cifs_open_parms oparms;
921 struct cifs_fid fid;
922
923 oparms.tcon = tcon;
924 oparms.desired_access = FILE_READ_ATTRIBUTES;
925 oparms.disposition = FILE_OPEN;
926 oparms.create_options = 0;
927 oparms.fid = &fid;
928 oparms.reconnect = false;
929
930 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
931 if (rc)
932 return rc;
933 buf->f_type = SMB2_MAGIC_NUMBER;
934 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
935 buf);
936 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
937 return rc;
938 }
939
940 static bool
smb2_compare_fids(struct cifsFileInfo * ob1,struct cifsFileInfo * ob2)941 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
942 {
943 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
944 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
945 }
946
947 static int
smb2_mand_lock(const unsigned int xid,struct cifsFileInfo * cfile,__u64 offset,__u64 length,__u32 type,int lock,int unlock,bool wait)948 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
949 __u64 length, __u32 type, int lock, int unlock, bool wait)
950 {
951 if (unlock && !lock)
952 type = SMB2_LOCKFLAG_UNLOCK;
953 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
954 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
955 current->tgid, length, offset, type, wait);
956 }
957
958 static void
smb2_get_lease_key(struct inode * inode,struct cifs_fid * fid)959 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
960 {
961 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
962 }
963
964 static void
smb2_set_lease_key(struct inode * inode,struct cifs_fid * fid)965 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
966 {
967 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
968 }
969
970 static void
smb2_new_lease_key(struct cifs_fid * fid)971 smb2_new_lease_key(struct cifs_fid *fid)
972 {
973 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
974 }
975
976 static int
smb2_query_symlink(const unsigned int xid,struct cifs_tcon * tcon,const char * full_path,char ** target_path,struct cifs_sb_info * cifs_sb)977 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
978 const char *full_path, char **target_path,
979 struct cifs_sb_info *cifs_sb)
980 {
981 int rc;
982 __le16 *utf16_path;
983 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
984 struct cifs_open_parms oparms;
985 struct cifs_fid fid;
986 struct smb2_err_rsp *err_buf = NULL;
987 struct smb2_symlink_err_rsp *symlink;
988 unsigned int sub_len, sub_offset;
989
990 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
991
992 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
993 if (!utf16_path)
994 return -ENOMEM;
995
996 oparms.tcon = tcon;
997 oparms.desired_access = FILE_READ_ATTRIBUTES;
998 oparms.disposition = FILE_OPEN;
999 oparms.create_options = 0;
1000 oparms.fid = &fid;
1001 oparms.reconnect = false;
1002
1003 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
1004
1005 if (!rc || !err_buf) {
1006 kfree(utf16_path);
1007 return -ENOENT;
1008 }
1009 /* open must fail on symlink - reset rc */
1010 rc = 0;
1011 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1012 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1013 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
1014 *target_path = cifs_strndup_from_utf16(
1015 (char *)symlink->PathBuffer + sub_offset,
1016 sub_len, true, cifs_sb->local_nls);
1017 if (!(*target_path)) {
1018 kfree(utf16_path);
1019 return -ENOMEM;
1020 }
1021 convert_delimiter(*target_path, '/');
1022 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1023 kfree(utf16_path);
1024 return rc;
1025 }
1026
smb3_zero_range(struct file * file,struct cifs_tcon * tcon,loff_t offset,loff_t len,bool keep_size)1027 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1028 loff_t offset, loff_t len, bool keep_size)
1029 {
1030 struct inode *inode;
1031 struct cifsInodeInfo *cifsi;
1032 struct cifsFileInfo *cfile = file->private_data;
1033 struct file_zero_data_information fsctl_buf;
1034 long rc;
1035 unsigned int xid;
1036
1037 xid = get_xid();
1038
1039 inode = d_inode(cfile->dentry);
1040 cifsi = CIFS_I(inode);
1041
1042 /* if file not oplocked can't be sure whether asking to extend size */
1043 if (!CIFS_CACHE_READ(cifsi))
1044 if (keep_size == false)
1045 return -EOPNOTSUPP;
1046
1047 /*
1048 * Must check if file sparse since fallocate -z (zero range) assumes
1049 * non-sparse allocation
1050 */
1051 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
1052 return -EOPNOTSUPP;
1053
1054 /*
1055 * need to make sure we are not asked to extend the file since the SMB3
1056 * fsctl does not change the file size. In the future we could change
1057 * this to zero the first part of the range then set the file size
1058 * which for a non sparse file would zero the newly extended range
1059 */
1060 if (keep_size == false)
1061 if (i_size_read(inode) < offset + len)
1062 return -EOPNOTSUPP;
1063
1064 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1065
1066 fsctl_buf.FileOffset = cpu_to_le64(offset);
1067 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1068
1069 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1070 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1071 true /* is_fctl */, (char *)&fsctl_buf,
1072 sizeof(struct file_zero_data_information), NULL, NULL);
1073 free_xid(xid);
1074 return rc;
1075 }
1076
smb3_punch_hole(struct file * file,struct cifs_tcon * tcon,loff_t offset,loff_t len)1077 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1078 loff_t offset, loff_t len)
1079 {
1080 struct inode *inode;
1081 struct cifsInodeInfo *cifsi;
1082 struct cifsFileInfo *cfile = file->private_data;
1083 struct file_zero_data_information fsctl_buf;
1084 long rc;
1085 unsigned int xid;
1086 __u8 set_sparse = 1;
1087
1088 xid = get_xid();
1089
1090 inode = d_inode(cfile->dentry);
1091 cifsi = CIFS_I(inode);
1092
1093 /* Need to make file sparse, if not already, before freeing range. */
1094 /* Consider adding equivalent for compressed since it could also work */
1095 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
1096 return -EOPNOTSUPP;
1097
1098 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1099
1100 fsctl_buf.FileOffset = cpu_to_le64(offset);
1101 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1102
1103 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1104 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1105 true /* is_fctl */, (char *)&fsctl_buf,
1106 sizeof(struct file_zero_data_information), NULL, NULL);
1107 free_xid(xid);
1108 return rc;
1109 }
1110
smb3_simple_falloc(struct file * file,struct cifs_tcon * tcon,loff_t off,loff_t len,bool keep_size)1111 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1112 loff_t off, loff_t len, bool keep_size)
1113 {
1114 struct inode *inode;
1115 struct cifsInodeInfo *cifsi;
1116 struct cifsFileInfo *cfile = file->private_data;
1117 long rc = -EOPNOTSUPP;
1118 unsigned int xid;
1119
1120 xid = get_xid();
1121
1122 inode = d_inode(cfile->dentry);
1123 cifsi = CIFS_I(inode);
1124
1125 /* if file not oplocked can't be sure whether asking to extend size */
1126 if (!CIFS_CACHE_READ(cifsi))
1127 if (keep_size == false)
1128 return -EOPNOTSUPP;
1129
1130 /*
1131 * Files are non-sparse by default so falloc may be a no-op
1132 * Must check if file sparse. If not sparse, and not extending
1133 * then no need to do anything since file already allocated
1134 */
1135 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
1136 if (keep_size == true)
1137 return 0;
1138 /* check if extending file */
1139 else if (i_size_read(inode) >= off + len)
1140 /* not extending file and already not sparse */
1141 return 0;
1142 /* BB: in future add else clause to extend file */
1143 else
1144 return -EOPNOTSUPP;
1145 }
1146
1147 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
1148 /*
1149 * Check if falloc starts within first few pages of file
1150 * and ends within a few pages of the end of file to
1151 * ensure that most of file is being forced to be
1152 * fallocated now. If so then setting whole file sparse
1153 * ie potentially making a few extra pages at the beginning
1154 * or end of the file non-sparse via set_sparse is harmless.
1155 */
1156 if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
1157 return -EOPNOTSUPP;
1158
1159 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
1160 }
1161 /* BB: else ... in future add code to extend file and set sparse */
1162
1163
1164 free_xid(xid);
1165 return rc;
1166 }
1167
1168
smb3_fallocate(struct file * file,struct cifs_tcon * tcon,int mode,loff_t off,loff_t len)1169 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
1170 loff_t off, loff_t len)
1171 {
1172 /* KEEP_SIZE already checked for by do_fallocate */
1173 if (mode & FALLOC_FL_PUNCH_HOLE)
1174 return smb3_punch_hole(file, tcon, off, len);
1175 else if (mode & FALLOC_FL_ZERO_RANGE) {
1176 if (mode & FALLOC_FL_KEEP_SIZE)
1177 return smb3_zero_range(file, tcon, off, len, true);
1178 return smb3_zero_range(file, tcon, off, len, false);
1179 } else if (mode == FALLOC_FL_KEEP_SIZE)
1180 return smb3_simple_falloc(file, tcon, off, len, true);
1181 else if (mode == 0)
1182 return smb3_simple_falloc(file, tcon, off, len, false);
1183
1184 return -EOPNOTSUPP;
1185 }
1186
1187 static void
smb2_downgrade_oplock(struct TCP_Server_Info * server,struct cifsInodeInfo * cinode,bool set_level2)1188 smb2_downgrade_oplock(struct TCP_Server_Info *server,
1189 struct cifsInodeInfo *cinode, bool set_level2)
1190 {
1191 if (set_level2)
1192 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
1193 0, NULL);
1194 else
1195 server->ops->set_oplock_level(cinode, 0, 0, NULL);
1196 }
1197
1198 static void
smb2_set_oplock_level(struct cifsInodeInfo * cinode,__u32 oplock,unsigned int epoch,bool * purge_cache)1199 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1200 unsigned int epoch, bool *purge_cache)
1201 {
1202 oplock &= 0xFF;
1203 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1204 return;
1205 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
1206 cinode->oplock = CIFS_CACHE_RHW_FLG;
1207 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
1208 &cinode->vfs_inode);
1209 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
1210 cinode->oplock = CIFS_CACHE_RW_FLG;
1211 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
1212 &cinode->vfs_inode);
1213 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
1214 cinode->oplock = CIFS_CACHE_READ_FLG;
1215 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
1216 &cinode->vfs_inode);
1217 } else
1218 cinode->oplock = 0;
1219 }
1220
1221 static void
smb21_set_oplock_level(struct cifsInodeInfo * cinode,__u32 oplock,unsigned int epoch,bool * purge_cache)1222 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1223 unsigned int epoch, bool *purge_cache)
1224 {
1225 char message[5] = {0};
1226
1227 oplock &= 0xFF;
1228 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1229 return;
1230
1231 cinode->oplock = 0;
1232 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
1233 cinode->oplock |= CIFS_CACHE_READ_FLG;
1234 strcat(message, "R");
1235 }
1236 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
1237 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
1238 strcat(message, "H");
1239 }
1240 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
1241 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
1242 strcat(message, "W");
1243 }
1244 if (!cinode->oplock)
1245 strcat(message, "None");
1246 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
1247 &cinode->vfs_inode);
1248 }
1249
1250 static void
smb3_set_oplock_level(struct cifsInodeInfo * cinode,__u32 oplock,unsigned int epoch,bool * purge_cache)1251 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1252 unsigned int epoch, bool *purge_cache)
1253 {
1254 unsigned int old_oplock = cinode->oplock;
1255
1256 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
1257
1258 if (purge_cache) {
1259 *purge_cache = false;
1260 if (old_oplock == CIFS_CACHE_READ_FLG) {
1261 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
1262 (epoch - cinode->epoch > 0))
1263 *purge_cache = true;
1264 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1265 (epoch - cinode->epoch > 1))
1266 *purge_cache = true;
1267 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1268 (epoch - cinode->epoch > 1))
1269 *purge_cache = true;
1270 else if (cinode->oplock == 0 &&
1271 (epoch - cinode->epoch > 0))
1272 *purge_cache = true;
1273 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
1274 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1275 (epoch - cinode->epoch > 0))
1276 *purge_cache = true;
1277 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1278 (epoch - cinode->epoch > 1))
1279 *purge_cache = true;
1280 }
1281 cinode->epoch = epoch;
1282 }
1283 }
1284
1285 static bool
smb2_is_read_op(__u32 oplock)1286 smb2_is_read_op(__u32 oplock)
1287 {
1288 return oplock == SMB2_OPLOCK_LEVEL_II;
1289 }
1290
1291 static bool
smb21_is_read_op(__u32 oplock)1292 smb21_is_read_op(__u32 oplock)
1293 {
1294 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
1295 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
1296 }
1297
1298 static __le32
map_oplock_to_lease(u8 oplock)1299 map_oplock_to_lease(u8 oplock)
1300 {
1301 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1302 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
1303 else if (oplock == SMB2_OPLOCK_LEVEL_II)
1304 return SMB2_LEASE_READ_CACHING;
1305 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
1306 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
1307 SMB2_LEASE_WRITE_CACHING;
1308 return 0;
1309 }
1310
1311 static char *
smb2_create_lease_buf(u8 * lease_key,u8 oplock)1312 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
1313 {
1314 struct create_lease *buf;
1315
1316 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
1317 if (!buf)
1318 return NULL;
1319
1320 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1321 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1322 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1323
1324 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1325 (struct create_lease, lcontext));
1326 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
1327 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1328 (struct create_lease, Name));
1329 buf->ccontext.NameLength = cpu_to_le16(4);
1330 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1331 buf->Name[0] = 'R';
1332 buf->Name[1] = 'q';
1333 buf->Name[2] = 'L';
1334 buf->Name[3] = 's';
1335 return (char *)buf;
1336 }
1337
1338 static char *
smb3_create_lease_buf(u8 * lease_key,u8 oplock)1339 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
1340 {
1341 struct create_lease_v2 *buf;
1342
1343 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
1344 if (!buf)
1345 return NULL;
1346
1347 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1348 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1349 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1350
1351 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1352 (struct create_lease_v2, lcontext));
1353 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
1354 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1355 (struct create_lease_v2, Name));
1356 buf->ccontext.NameLength = cpu_to_le16(4);
1357 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1358 buf->Name[0] = 'R';
1359 buf->Name[1] = 'q';
1360 buf->Name[2] = 'L';
1361 buf->Name[3] = 's';
1362 return (char *)buf;
1363 }
1364
1365 static __u8
smb2_parse_lease_buf(void * buf,unsigned int * epoch)1366 smb2_parse_lease_buf(void *buf, unsigned int *epoch)
1367 {
1368 struct create_lease *lc = (struct create_lease *)buf;
1369
1370 *epoch = 0; /* not used */
1371 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1372 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1373 return le32_to_cpu(lc->lcontext.LeaseState);
1374 }
1375
1376 static __u8
smb3_parse_lease_buf(void * buf,unsigned int * epoch)1377 smb3_parse_lease_buf(void *buf, unsigned int *epoch)
1378 {
1379 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
1380
1381 *epoch = le16_to_cpu(lc->lcontext.Epoch);
1382 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1383 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1384 return le32_to_cpu(lc->lcontext.LeaseState);
1385 }
1386
1387 static unsigned int
smb2_wp_retry_size(struct inode * inode)1388 smb2_wp_retry_size(struct inode *inode)
1389 {
1390 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
1391 SMB2_MAX_BUFFER_SIZE);
1392 }
1393
1394 static bool
smb2_dir_needs_close(struct cifsFileInfo * cfile)1395 smb2_dir_needs_close(struct cifsFileInfo *cfile)
1396 {
1397 return !cfile->invalidHandle;
1398 }
1399
1400 struct smb_version_operations smb20_operations = {
1401 .compare_fids = smb2_compare_fids,
1402 .setup_request = smb2_setup_request,
1403 .setup_async_request = smb2_setup_async_request,
1404 .check_receive = smb2_check_receive,
1405 .add_credits = smb2_add_credits,
1406 .set_credits = smb2_set_credits,
1407 .get_credits_field = smb2_get_credits_field,
1408 .get_credits = smb2_get_credits,
1409 .wait_mtu_credits = cifs_wait_mtu_credits,
1410 .get_next_mid = smb2_get_next_mid,
1411 .read_data_offset = smb2_read_data_offset,
1412 .read_data_length = smb2_read_data_length,
1413 .map_error = map_smb2_to_linux_error,
1414 .find_mid = smb2_find_mid,
1415 .check_message = smb2_check_message,
1416 .dump_detail = smb2_dump_detail,
1417 .clear_stats = smb2_clear_stats,
1418 .print_stats = smb2_print_stats,
1419 .is_oplock_break = smb2_is_valid_oplock_break,
1420 .downgrade_oplock = smb2_downgrade_oplock,
1421 .need_neg = smb2_need_neg,
1422 .negotiate = smb2_negotiate,
1423 .negotiate_wsize = smb2_negotiate_wsize,
1424 .negotiate_rsize = smb2_negotiate_rsize,
1425 .sess_setup = SMB2_sess_setup,
1426 .logoff = SMB2_logoff,
1427 .tree_connect = SMB2_tcon,
1428 .tree_disconnect = SMB2_tdis,
1429 .qfs_tcon = smb2_qfs_tcon,
1430 .is_path_accessible = smb2_is_path_accessible,
1431 .can_echo = smb2_can_echo,
1432 .echo = SMB2_echo,
1433 .query_path_info = smb2_query_path_info,
1434 .get_srv_inum = smb2_get_srv_inum,
1435 .query_file_info = smb2_query_file_info,
1436 .set_path_size = smb2_set_path_size,
1437 .set_file_size = smb2_set_file_size,
1438 .set_file_info = smb2_set_file_info,
1439 .set_compression = smb2_set_compression,
1440 .mkdir = smb2_mkdir,
1441 .mkdir_setinfo = smb2_mkdir_setinfo,
1442 .rmdir = smb2_rmdir,
1443 .unlink = smb2_unlink,
1444 .rename = smb2_rename_path,
1445 .create_hardlink = smb2_create_hardlink,
1446 .query_symlink = smb2_query_symlink,
1447 .open = smb2_open_file,
1448 .set_fid = smb2_set_fid,
1449 .close = smb2_close_file,
1450 .flush = smb2_flush_file,
1451 .async_readv = smb2_async_readv,
1452 .async_writev = smb2_async_writev,
1453 .sync_read = smb2_sync_read,
1454 .sync_write = smb2_sync_write,
1455 .query_dir_first = smb2_query_dir_first,
1456 .query_dir_next = smb2_query_dir_next,
1457 .close_dir = smb2_close_dir,
1458 .calc_smb_size = smb2_calc_size,
1459 .is_status_pending = smb2_is_status_pending,
1460 .oplock_response = smb2_oplock_response,
1461 .queryfs = smb2_queryfs,
1462 .mand_lock = smb2_mand_lock,
1463 .mand_unlock_range = smb2_unlock_range,
1464 .push_mand_locks = smb2_push_mandatory_locks,
1465 .get_lease_key = smb2_get_lease_key,
1466 .set_lease_key = smb2_set_lease_key,
1467 .new_lease_key = smb2_new_lease_key,
1468 .calc_signature = smb2_calc_signature,
1469 .is_read_op = smb2_is_read_op,
1470 .set_oplock_level = smb2_set_oplock_level,
1471 .create_lease_buf = smb2_create_lease_buf,
1472 .parse_lease_buf = smb2_parse_lease_buf,
1473 .clone_range = smb2_clone_range,
1474 .wp_retry_size = smb2_wp_retry_size,
1475 .dir_needs_close = smb2_dir_needs_close,
1476 };
1477
1478 struct smb_version_operations smb21_operations = {
1479 .compare_fids = smb2_compare_fids,
1480 .setup_request = smb2_setup_request,
1481 .setup_async_request = smb2_setup_async_request,
1482 .check_receive = smb2_check_receive,
1483 .add_credits = smb2_add_credits,
1484 .set_credits = smb2_set_credits,
1485 .get_credits_field = smb2_get_credits_field,
1486 .get_credits = smb2_get_credits,
1487 .wait_mtu_credits = smb2_wait_mtu_credits,
1488 .get_next_mid = smb2_get_next_mid,
1489 .read_data_offset = smb2_read_data_offset,
1490 .read_data_length = smb2_read_data_length,
1491 .map_error = map_smb2_to_linux_error,
1492 .find_mid = smb2_find_mid,
1493 .check_message = smb2_check_message,
1494 .dump_detail = smb2_dump_detail,
1495 .clear_stats = smb2_clear_stats,
1496 .print_stats = smb2_print_stats,
1497 .is_oplock_break = smb2_is_valid_oplock_break,
1498 .downgrade_oplock = smb2_downgrade_oplock,
1499 .need_neg = smb2_need_neg,
1500 .negotiate = smb2_negotiate,
1501 .negotiate_wsize = smb2_negotiate_wsize,
1502 .negotiate_rsize = smb2_negotiate_rsize,
1503 .sess_setup = SMB2_sess_setup,
1504 .logoff = SMB2_logoff,
1505 .tree_connect = SMB2_tcon,
1506 .tree_disconnect = SMB2_tdis,
1507 .qfs_tcon = smb2_qfs_tcon,
1508 .is_path_accessible = smb2_is_path_accessible,
1509 .can_echo = smb2_can_echo,
1510 .echo = SMB2_echo,
1511 .query_path_info = smb2_query_path_info,
1512 .get_srv_inum = smb2_get_srv_inum,
1513 .query_file_info = smb2_query_file_info,
1514 .set_path_size = smb2_set_path_size,
1515 .set_file_size = smb2_set_file_size,
1516 .set_file_info = smb2_set_file_info,
1517 .set_compression = smb2_set_compression,
1518 .mkdir = smb2_mkdir,
1519 .mkdir_setinfo = smb2_mkdir_setinfo,
1520 .rmdir = smb2_rmdir,
1521 .unlink = smb2_unlink,
1522 .rename = smb2_rename_path,
1523 .create_hardlink = smb2_create_hardlink,
1524 .query_symlink = smb2_query_symlink,
1525 .query_mf_symlink = smb3_query_mf_symlink,
1526 .create_mf_symlink = smb3_create_mf_symlink,
1527 .open = smb2_open_file,
1528 .set_fid = smb2_set_fid,
1529 .close = smb2_close_file,
1530 .flush = smb2_flush_file,
1531 .async_readv = smb2_async_readv,
1532 .async_writev = smb2_async_writev,
1533 .sync_read = smb2_sync_read,
1534 .sync_write = smb2_sync_write,
1535 .query_dir_first = smb2_query_dir_first,
1536 .query_dir_next = smb2_query_dir_next,
1537 .close_dir = smb2_close_dir,
1538 .calc_smb_size = smb2_calc_size,
1539 .is_status_pending = smb2_is_status_pending,
1540 .oplock_response = smb2_oplock_response,
1541 .queryfs = smb2_queryfs,
1542 .mand_lock = smb2_mand_lock,
1543 .mand_unlock_range = smb2_unlock_range,
1544 .push_mand_locks = smb2_push_mandatory_locks,
1545 .get_lease_key = smb2_get_lease_key,
1546 .set_lease_key = smb2_set_lease_key,
1547 .new_lease_key = smb2_new_lease_key,
1548 .calc_signature = smb2_calc_signature,
1549 .is_read_op = smb21_is_read_op,
1550 .set_oplock_level = smb21_set_oplock_level,
1551 .create_lease_buf = smb2_create_lease_buf,
1552 .parse_lease_buf = smb2_parse_lease_buf,
1553 .clone_range = smb2_clone_range,
1554 .wp_retry_size = smb2_wp_retry_size,
1555 .dir_needs_close = smb2_dir_needs_close,
1556 };
1557
1558 struct smb_version_operations smb30_operations = {
1559 .compare_fids = smb2_compare_fids,
1560 .setup_request = smb2_setup_request,
1561 .setup_async_request = smb2_setup_async_request,
1562 .check_receive = smb2_check_receive,
1563 .add_credits = smb2_add_credits,
1564 .set_credits = smb2_set_credits,
1565 .get_credits_field = smb2_get_credits_field,
1566 .get_credits = smb2_get_credits,
1567 .wait_mtu_credits = smb2_wait_mtu_credits,
1568 .get_next_mid = smb2_get_next_mid,
1569 .read_data_offset = smb2_read_data_offset,
1570 .read_data_length = smb2_read_data_length,
1571 .map_error = map_smb2_to_linux_error,
1572 .find_mid = smb2_find_mid,
1573 .check_message = smb2_check_message,
1574 .dump_detail = smb2_dump_detail,
1575 .clear_stats = smb2_clear_stats,
1576 .print_stats = smb2_print_stats,
1577 .dump_share_caps = smb2_dump_share_caps,
1578 .is_oplock_break = smb2_is_valid_oplock_break,
1579 .downgrade_oplock = smb2_downgrade_oplock,
1580 .need_neg = smb2_need_neg,
1581 .negotiate = smb2_negotiate,
1582 .negotiate_wsize = smb2_negotiate_wsize,
1583 .negotiate_rsize = smb2_negotiate_rsize,
1584 .sess_setup = SMB2_sess_setup,
1585 .logoff = SMB2_logoff,
1586 .tree_connect = SMB2_tcon,
1587 .tree_disconnect = SMB2_tdis,
1588 .qfs_tcon = smb3_qfs_tcon,
1589 .is_path_accessible = smb2_is_path_accessible,
1590 .can_echo = smb2_can_echo,
1591 .echo = SMB2_echo,
1592 .query_path_info = smb2_query_path_info,
1593 .get_srv_inum = smb2_get_srv_inum,
1594 .query_file_info = smb2_query_file_info,
1595 .set_path_size = smb2_set_path_size,
1596 .set_file_size = smb2_set_file_size,
1597 .set_file_info = smb2_set_file_info,
1598 .set_compression = smb2_set_compression,
1599 .mkdir = smb2_mkdir,
1600 .mkdir_setinfo = smb2_mkdir_setinfo,
1601 .rmdir = smb2_rmdir,
1602 .unlink = smb2_unlink,
1603 .rename = smb2_rename_path,
1604 .create_hardlink = smb2_create_hardlink,
1605 .query_symlink = smb2_query_symlink,
1606 .query_mf_symlink = smb3_query_mf_symlink,
1607 .create_mf_symlink = smb3_create_mf_symlink,
1608 .open = smb2_open_file,
1609 .set_fid = smb2_set_fid,
1610 .close = smb2_close_file,
1611 .flush = smb2_flush_file,
1612 .async_readv = smb2_async_readv,
1613 .async_writev = smb2_async_writev,
1614 .sync_read = smb2_sync_read,
1615 .sync_write = smb2_sync_write,
1616 .query_dir_first = smb2_query_dir_first,
1617 .query_dir_next = smb2_query_dir_next,
1618 .close_dir = smb2_close_dir,
1619 .calc_smb_size = smb2_calc_size,
1620 .is_status_pending = smb2_is_status_pending,
1621 .oplock_response = smb2_oplock_response,
1622 .queryfs = smb2_queryfs,
1623 .mand_lock = smb2_mand_lock,
1624 .mand_unlock_range = smb2_unlock_range,
1625 .push_mand_locks = smb2_push_mandatory_locks,
1626 .get_lease_key = smb2_get_lease_key,
1627 .set_lease_key = smb2_set_lease_key,
1628 .new_lease_key = smb2_new_lease_key,
1629 .generate_signingkey = generate_smb3signingkey,
1630 .calc_signature = smb3_calc_signature,
1631 .is_read_op = smb21_is_read_op,
1632 .set_oplock_level = smb3_set_oplock_level,
1633 .create_lease_buf = smb3_create_lease_buf,
1634 .parse_lease_buf = smb3_parse_lease_buf,
1635 .clone_range = smb2_clone_range,
1636 .validate_negotiate = smb3_validate_negotiate,
1637 .wp_retry_size = smb2_wp_retry_size,
1638 .dir_needs_close = smb2_dir_needs_close,
1639 .fallocate = smb3_fallocate,
1640 };
1641
1642 struct smb_version_values smb20_values = {
1643 .version_string = SMB20_VERSION_STRING,
1644 .protocol_id = SMB20_PROT_ID,
1645 .req_capabilities = 0, /* MBZ */
1646 .large_lock_type = 0,
1647 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1648 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1649 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1650 .header_size = sizeof(struct smb2_hdr),
1651 .max_header_size = MAX_SMB2_HDR_SIZE,
1652 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1653 .lock_cmd = SMB2_LOCK,
1654 .cap_unix = 0,
1655 .cap_nt_find = SMB2_NT_FIND,
1656 .cap_large_files = SMB2_LARGE_FILES,
1657 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1658 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1659 .create_lease_size = sizeof(struct create_lease),
1660 };
1661
1662 struct smb_version_values smb21_values = {
1663 .version_string = SMB21_VERSION_STRING,
1664 .protocol_id = SMB21_PROT_ID,
1665 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
1666 .large_lock_type = 0,
1667 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1668 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1669 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1670 .header_size = sizeof(struct smb2_hdr),
1671 .max_header_size = MAX_SMB2_HDR_SIZE,
1672 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1673 .lock_cmd = SMB2_LOCK,
1674 .cap_unix = 0,
1675 .cap_nt_find = SMB2_NT_FIND,
1676 .cap_large_files = SMB2_LARGE_FILES,
1677 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1678 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1679 .create_lease_size = sizeof(struct create_lease),
1680 };
1681
1682 struct smb_version_values smb30_values = {
1683 .version_string = SMB30_VERSION_STRING,
1684 .protocol_id = SMB30_PROT_ID,
1685 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
1686 .large_lock_type = 0,
1687 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1688 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1689 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1690 .header_size = sizeof(struct smb2_hdr),
1691 .max_header_size = MAX_SMB2_HDR_SIZE,
1692 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1693 .lock_cmd = SMB2_LOCK,
1694 .cap_unix = 0,
1695 .cap_nt_find = SMB2_NT_FIND,
1696 .cap_large_files = SMB2_LARGE_FILES,
1697 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1698 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1699 .create_lease_size = sizeof(struct create_lease_v2),
1700 };
1701
1702 struct smb_version_values smb302_values = {
1703 .version_string = SMB302_VERSION_STRING,
1704 .protocol_id = SMB302_PROT_ID,
1705 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
1706 .large_lock_type = 0,
1707 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1708 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1709 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1710 .header_size = sizeof(struct smb2_hdr),
1711 .max_header_size = MAX_SMB2_HDR_SIZE,
1712 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1713 .lock_cmd = SMB2_LOCK,
1714 .cap_unix = 0,
1715 .cap_nt_find = SMB2_NT_FIND,
1716 .cap_large_files = SMB2_LARGE_FILES,
1717 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1718 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1719 .create_lease_size = sizeof(struct create_lease_v2),
1720 };
1721