1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * SMB1 (CIFS) version specific operations
4 *
5 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
6 */
7
8 #include <linux/pagemap.h>
9 #include <linux/vfs.h>
10 #include <uapi/linux/magic.h>
11 #include "cifsglob.h"
12 #include "cifsproto.h"
13 #include "cifs_debug.h"
14 #include "cifspdu.h"
15 #include "cifs_unicode.h"
16 #include "fs_context.h"
17 #include "nterr.h"
18 #include "smberr.h"
19
20 /*
21 * An NT cancel request header looks just like the original request except:
22 *
23 * The Command is SMB_COM_NT_CANCEL
24 * The WordCount is zeroed out
25 * The ByteCount is zeroed out
26 *
27 * This function mangles an existing request buffer into a
28 * SMB_COM_NT_CANCEL request and then sends it.
29 */
30 static int
send_nt_cancel(struct TCP_Server_Info * server,struct smb_rqst * rqst,struct mid_q_entry * mid)31 send_nt_cancel(struct TCP_Server_Info *server, struct smb_rqst *rqst,
32 struct mid_q_entry *mid)
33 {
34 int rc = 0;
35 struct smb_hdr *in_buf = (struct smb_hdr *)rqst->rq_iov[0].iov_base;
36
37 /* -4 for RFC1001 length and +2 for BCC field */
38 in_buf->smb_buf_length = cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2);
39 in_buf->Command = SMB_COM_NT_CANCEL;
40 in_buf->WordCount = 0;
41 put_bcc(0, in_buf);
42
43 cifs_server_lock(server);
44 rc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
45 if (rc) {
46 cifs_server_unlock(server);
47 return rc;
48 }
49
50 /*
51 * The response to this call was already factored into the sequence
52 * number when the call went out, so we must adjust it back downward
53 * after signing here.
54 */
55 --server->sequence_number;
56 rc = smb_send(server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
57 if (rc < 0)
58 server->sequence_number--;
59
60 cifs_server_unlock(server);
61
62 cifs_dbg(FYI, "issued NT_CANCEL for mid %u, rc = %d\n",
63 get_mid(in_buf), rc);
64
65 return rc;
66 }
67
68 static bool
cifs_compare_fids(struct cifsFileInfo * ob1,struct cifsFileInfo * ob2)69 cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
70 {
71 return ob1->fid.netfid == ob2->fid.netfid;
72 }
73
74 static unsigned int
cifs_read_data_offset(char * buf)75 cifs_read_data_offset(char *buf)
76 {
77 READ_RSP *rsp = (READ_RSP *)buf;
78 return le16_to_cpu(rsp->DataOffset);
79 }
80
81 static unsigned int
cifs_read_data_length(char * buf,bool in_remaining)82 cifs_read_data_length(char *buf, bool in_remaining)
83 {
84 READ_RSP *rsp = (READ_RSP *)buf;
85 /* It's a bug reading remaining data for SMB1 packets */
86 WARN_ON(in_remaining);
87 return (le16_to_cpu(rsp->DataLengthHigh) << 16) +
88 le16_to_cpu(rsp->DataLength);
89 }
90
91 static struct mid_q_entry *
cifs_find_mid(struct TCP_Server_Info * server,char * buffer)92 cifs_find_mid(struct TCP_Server_Info *server, char *buffer)
93 {
94 struct smb_hdr *buf = (struct smb_hdr *)buffer;
95 struct mid_q_entry *mid;
96
97 spin_lock(&server->mid_lock);
98 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
99 if (compare_mid(mid->mid, buf) &&
100 mid->mid_state == MID_REQUEST_SUBMITTED &&
101 le16_to_cpu(mid->command) == buf->Command) {
102 kref_get(&mid->refcount);
103 spin_unlock(&server->mid_lock);
104 return mid;
105 }
106 }
107 spin_unlock(&server->mid_lock);
108 return NULL;
109 }
110
111 static void
cifs_add_credits(struct TCP_Server_Info * server,struct cifs_credits * credits,const int optype)112 cifs_add_credits(struct TCP_Server_Info *server,
113 struct cifs_credits *credits, const int optype)
114 {
115 spin_lock(&server->req_lock);
116 server->credits += credits->value;
117 server->in_flight--;
118 spin_unlock(&server->req_lock);
119 wake_up(&server->request_q);
120 }
121
122 static void
cifs_set_credits(struct TCP_Server_Info * server,const int val)123 cifs_set_credits(struct TCP_Server_Info *server, const int val)
124 {
125 spin_lock(&server->req_lock);
126 server->credits = val;
127 server->oplocks = val > 1 ? enable_oplocks : false;
128 spin_unlock(&server->req_lock);
129 }
130
131 static int *
cifs_get_credits_field(struct TCP_Server_Info * server,const int optype)132 cifs_get_credits_field(struct TCP_Server_Info *server, const int optype)
133 {
134 return &server->credits;
135 }
136
137 static unsigned int
cifs_get_credits(struct mid_q_entry * mid)138 cifs_get_credits(struct mid_q_entry *mid)
139 {
140 return 1;
141 }
142
143 /*
144 * Find a free multiplex id (SMB mid). Otherwise there could be
145 * mid collisions which might cause problems, demultiplexing the
146 * wrong response to this request. Multiplex ids could collide if
147 * one of a series requests takes much longer than the others, or
148 * if a very large number of long lived requests (byte range
149 * locks or FindNotify requests) are pending. No more than
150 * 64K-1 requests can be outstanding at one time. If no
151 * mids are available, return zero. A future optimization
152 * could make the combination of mids and uid the key we use
153 * to demultiplex on (rather than mid alone).
154 * In addition to the above check, the cifs demultiplex
155 * code already used the command code as a secondary
156 * check of the frame and if signing is negotiated the
157 * response would be discarded if the mid were the same
158 * but the signature was wrong. Since the mid is not put in the
159 * pending queue until later (when it is about to be dispatched)
160 * we do have to limit the number of outstanding requests
161 * to somewhat less than 64K-1 although it is hard to imagine
162 * so many threads being in the vfs at one time.
163 */
164 static __u64
cifs_get_next_mid(struct TCP_Server_Info * server)165 cifs_get_next_mid(struct TCP_Server_Info *server)
166 {
167 __u64 mid = 0;
168 __u16 last_mid, cur_mid;
169 bool collision, reconnect = false;
170
171 spin_lock(&server->mid_lock);
172
173 /* mid is 16 bit only for CIFS/SMB */
174 cur_mid = (__u16)((server->CurrentMid) & 0xffff);
175 /* we do not want to loop forever */
176 last_mid = cur_mid;
177 cur_mid++;
178 /* avoid 0xFFFF MID */
179 if (cur_mid == 0xffff)
180 cur_mid++;
181
182 /*
183 * This nested loop looks more expensive than it is.
184 * In practice the list of pending requests is short,
185 * fewer than 50, and the mids are likely to be unique
186 * on the first pass through the loop unless some request
187 * takes longer than the 64 thousand requests before it
188 * (and it would also have to have been a request that
189 * did not time out).
190 */
191 while (cur_mid != last_mid) {
192 struct mid_q_entry *mid_entry;
193 unsigned int num_mids;
194
195 collision = false;
196 if (cur_mid == 0)
197 cur_mid++;
198
199 num_mids = 0;
200 list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
201 ++num_mids;
202 if (mid_entry->mid == cur_mid &&
203 mid_entry->mid_state == MID_REQUEST_SUBMITTED) {
204 /* This mid is in use, try a different one */
205 collision = true;
206 break;
207 }
208 }
209
210 /*
211 * if we have more than 32k mids in the list, then something
212 * is very wrong. Possibly a local user is trying to DoS the
213 * box by issuing long-running calls and SIGKILL'ing them. If
214 * we get to 2^16 mids then we're in big trouble as this
215 * function could loop forever.
216 *
217 * Go ahead and assign out the mid in this situation, but force
218 * an eventual reconnect to clean out the pending_mid_q.
219 */
220 if (num_mids > 32768)
221 reconnect = true;
222
223 if (!collision) {
224 mid = (__u64)cur_mid;
225 server->CurrentMid = mid;
226 break;
227 }
228 cur_mid++;
229 }
230 spin_unlock(&server->mid_lock);
231
232 if (reconnect) {
233 cifs_signal_cifsd_for_reconnect(server, false);
234 }
235
236 return mid;
237 }
238
239 /*
240 return codes:
241 0 not a transact2, or all data present
242 >0 transact2 with that much data missing
243 -EINVAL invalid transact2
244 */
245 static int
check2ndT2(char * buf)246 check2ndT2(char *buf)
247 {
248 struct smb_hdr *pSMB = (struct smb_hdr *)buf;
249 struct smb_t2_rsp *pSMBt;
250 int remaining;
251 __u16 total_data_size, data_in_this_rsp;
252
253 if (pSMB->Command != SMB_COM_TRANSACTION2)
254 return 0;
255
256 /* check for plausible wct, bcc and t2 data and parm sizes */
257 /* check for parm and data offset going beyond end of smb */
258 if (pSMB->WordCount != 10) { /* coalesce_t2 depends on this */
259 cifs_dbg(FYI, "Invalid transact2 word count\n");
260 return -EINVAL;
261 }
262
263 pSMBt = (struct smb_t2_rsp *)pSMB;
264
265 total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
266 data_in_this_rsp = get_unaligned_le16(&pSMBt->t2_rsp.DataCount);
267
268 if (total_data_size == data_in_this_rsp)
269 return 0;
270 else if (total_data_size < data_in_this_rsp) {
271 cifs_dbg(FYI, "total data %d smaller than data in frame %d\n",
272 total_data_size, data_in_this_rsp);
273 return -EINVAL;
274 }
275
276 remaining = total_data_size - data_in_this_rsp;
277
278 cifs_dbg(FYI, "missing %d bytes from transact2, check next response\n",
279 remaining);
280 if (total_data_size > CIFSMaxBufSize) {
281 cifs_dbg(VFS, "TotalDataSize %d is over maximum buffer %d\n",
282 total_data_size, CIFSMaxBufSize);
283 return -EINVAL;
284 }
285 return remaining;
286 }
287
288 static int
coalesce_t2(char * second_buf,struct smb_hdr * target_hdr)289 coalesce_t2(char *second_buf, struct smb_hdr *target_hdr)
290 {
291 struct smb_t2_rsp *pSMBs = (struct smb_t2_rsp *)second_buf;
292 struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)target_hdr;
293 char *data_area_of_tgt;
294 char *data_area_of_src;
295 int remaining;
296 unsigned int byte_count, total_in_tgt;
297 __u16 tgt_total_cnt, src_total_cnt, total_in_src;
298
299 src_total_cnt = get_unaligned_le16(&pSMBs->t2_rsp.TotalDataCount);
300 tgt_total_cnt = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
301
302 if (tgt_total_cnt != src_total_cnt)
303 cifs_dbg(FYI, "total data count of primary and secondary t2 differ source=%hu target=%hu\n",
304 src_total_cnt, tgt_total_cnt);
305
306 total_in_tgt = get_unaligned_le16(&pSMBt->t2_rsp.DataCount);
307
308 remaining = tgt_total_cnt - total_in_tgt;
309
310 if (remaining < 0) {
311 cifs_dbg(FYI, "Server sent too much data. tgt_total_cnt=%hu total_in_tgt=%u\n",
312 tgt_total_cnt, total_in_tgt);
313 return -EPROTO;
314 }
315
316 if (remaining == 0) {
317 /* nothing to do, ignore */
318 cifs_dbg(FYI, "no more data remains\n");
319 return 0;
320 }
321
322 total_in_src = get_unaligned_le16(&pSMBs->t2_rsp.DataCount);
323 if (remaining < total_in_src)
324 cifs_dbg(FYI, "transact2 2nd response contains too much data\n");
325
326 /* find end of first SMB data area */
327 data_area_of_tgt = (char *)&pSMBt->hdr.Protocol +
328 get_unaligned_le16(&pSMBt->t2_rsp.DataOffset);
329
330 /* validate target area */
331 data_area_of_src = (char *)&pSMBs->hdr.Protocol +
332 get_unaligned_le16(&pSMBs->t2_rsp.DataOffset);
333
334 data_area_of_tgt += total_in_tgt;
335
336 total_in_tgt += total_in_src;
337 /* is the result too big for the field? */
338 if (total_in_tgt > USHRT_MAX) {
339 cifs_dbg(FYI, "coalesced DataCount too large (%u)\n",
340 total_in_tgt);
341 return -EPROTO;
342 }
343 put_unaligned_le16(total_in_tgt, &pSMBt->t2_rsp.DataCount);
344
345 /* fix up the BCC */
346 byte_count = get_bcc(target_hdr);
347 byte_count += total_in_src;
348 /* is the result too big for the field? */
349 if (byte_count > USHRT_MAX) {
350 cifs_dbg(FYI, "coalesced BCC too large (%u)\n", byte_count);
351 return -EPROTO;
352 }
353 put_bcc(byte_count, target_hdr);
354
355 byte_count = be32_to_cpu(target_hdr->smb_buf_length);
356 byte_count += total_in_src;
357 /* don't allow buffer to overflow */
358 if (byte_count > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) {
359 cifs_dbg(FYI, "coalesced BCC exceeds buffer size (%u)\n",
360 byte_count);
361 return -ENOBUFS;
362 }
363 target_hdr->smb_buf_length = cpu_to_be32(byte_count);
364
365 /* copy second buffer into end of first buffer */
366 memcpy(data_area_of_tgt, data_area_of_src, total_in_src);
367
368 if (remaining != total_in_src) {
369 /* more responses to go */
370 cifs_dbg(FYI, "waiting for more secondary responses\n");
371 return 1;
372 }
373
374 /* we are done */
375 cifs_dbg(FYI, "found the last secondary response\n");
376 return 0;
377 }
378
379 static void
cifs_downgrade_oplock(struct TCP_Server_Info * server,struct cifsInodeInfo * cinode,__u32 oplock,__u16 epoch,bool * purge_cache)380 cifs_downgrade_oplock(struct TCP_Server_Info *server,
381 struct cifsInodeInfo *cinode, __u32 oplock,
382 __u16 epoch, bool *purge_cache)
383 {
384 cifs_set_oplock_level(cinode, oplock);
385 }
386
387 static bool
cifs_check_trans2(struct mid_q_entry * mid,struct TCP_Server_Info * server,char * buf,int malformed)388 cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server,
389 char *buf, int malformed)
390 {
391 if (malformed)
392 return false;
393 if (check2ndT2(buf) <= 0)
394 return false;
395 mid->multiRsp = true;
396 if (mid->resp_buf) {
397 /* merge response - fix up 1st*/
398 malformed = coalesce_t2(buf, mid->resp_buf);
399 if (malformed > 0)
400 return true;
401 /* All parts received or packet is malformed. */
402 mid->multiEnd = true;
403 dequeue_mid(mid, malformed);
404 return true;
405 }
406 if (!server->large_buf) {
407 /*FIXME: switch to already allocated largebuf?*/
408 cifs_dbg(VFS, "1st trans2 resp needs bigbuf\n");
409 } else {
410 /* Have first buffer */
411 mid->resp_buf = buf;
412 mid->large_buf = true;
413 server->bigbuf = NULL;
414 }
415 return true;
416 }
417
418 static bool
cifs_need_neg(struct TCP_Server_Info * server)419 cifs_need_neg(struct TCP_Server_Info *server)
420 {
421 return server->maxBuf == 0;
422 }
423
424 static int
cifs_negotiate(const unsigned int xid,struct cifs_ses * ses,struct TCP_Server_Info * server)425 cifs_negotiate(const unsigned int xid,
426 struct cifs_ses *ses,
427 struct TCP_Server_Info *server)
428 {
429 int rc;
430 rc = CIFSSMBNegotiate(xid, ses, server);
431 return rc;
432 }
433
434 static unsigned int
cifs_negotiate_wsize(struct cifs_tcon * tcon,struct smb3_fs_context * ctx)435 cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
436 {
437 __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
438 struct TCP_Server_Info *server = tcon->ses->server;
439 unsigned int wsize;
440
441 /* start with specified wsize, or default */
442 if (ctx->got_wsize)
443 wsize = ctx->vol_wsize;
444 else if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_WRITE_CAP))
445 wsize = CIFS_DEFAULT_IOSIZE;
446 else
447 wsize = CIFS_DEFAULT_NON_POSIX_WSIZE;
448
449 /* can server support 24-bit write sizes? (via UNIX extensions) */
450 if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP))
451 wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1002_WSIZE);
452
453 /*
454 * no CAP_LARGE_WRITE_X or is signing enabled without CAP_UNIX set?
455 * Limit it to max buffer offered by the server, minus the size of the
456 * WRITEX header, not including the 4 byte RFC1001 length.
457 */
458 if (!(server->capabilities & CAP_LARGE_WRITE_X) ||
459 (!(server->capabilities & CAP_UNIX) && server->sign))
460 wsize = min_t(unsigned int, wsize,
461 server->maxBuf - sizeof(WRITE_REQ) + 4);
462
463 /* hard limit of CIFS_MAX_WSIZE */
464 wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE);
465
466 return wsize;
467 }
468
469 static unsigned int
cifs_negotiate_rsize(struct cifs_tcon * tcon,struct smb3_fs_context * ctx)470 cifs_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
471 {
472 __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
473 struct TCP_Server_Info *server = tcon->ses->server;
474 unsigned int rsize, defsize;
475
476 /*
477 * Set default value...
478 *
479 * HACK alert! Ancient servers have very small buffers. Even though
480 * MS-CIFS indicates that servers are only limited by the client's
481 * bufsize for reads, testing against win98se shows that it throws
482 * INVALID_PARAMETER errors if you try to request too large a read.
483 * OS/2 just sends back short reads.
484 *
485 * If the server doesn't advertise CAP_LARGE_READ_X, then assume that
486 * it can't handle a read request larger than its MaxBufferSize either.
487 */
488 if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_READ_CAP))
489 defsize = CIFS_DEFAULT_IOSIZE;
490 else if (server->capabilities & CAP_LARGE_READ_X)
491 defsize = CIFS_DEFAULT_NON_POSIX_RSIZE;
492 else
493 defsize = server->maxBuf - sizeof(READ_RSP);
494
495 rsize = ctx->got_rsize ? ctx->vol_rsize : defsize;
496
497 /*
498 * no CAP_LARGE_READ_X? Then MS-CIFS states that we must limit this to
499 * the client's MaxBufferSize.
500 */
501 if (!(server->capabilities & CAP_LARGE_READ_X))
502 rsize = min_t(unsigned int, CIFSMaxBufSize, rsize);
503
504 /* hard limit of CIFS_MAX_RSIZE */
505 rsize = min_t(unsigned int, rsize, CIFS_MAX_RSIZE);
506
507 return rsize;
508 }
509
510 static void
cifs_qfs_tcon(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_sb_info * cifs_sb)511 cifs_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
512 struct cifs_sb_info *cifs_sb)
513 {
514 CIFSSMBQFSDeviceInfo(xid, tcon);
515 CIFSSMBQFSAttributeInfo(xid, tcon);
516 }
517
518 static int
cifs_is_path_accessible(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_sb_info * cifs_sb,const char * full_path)519 cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
520 struct cifs_sb_info *cifs_sb, const char *full_path)
521 {
522 int rc;
523 FILE_ALL_INFO *file_info;
524
525 file_info = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
526 if (file_info == NULL)
527 return -ENOMEM;
528
529 rc = CIFSSMBQPathInfo(xid, tcon, full_path, file_info,
530 0 /* not legacy */, cifs_sb->local_nls,
531 cifs_remap(cifs_sb));
532
533 if (rc == -EOPNOTSUPP || rc == -EINVAL)
534 rc = SMBQueryInformation(xid, tcon, full_path, file_info,
535 cifs_sb->local_nls, cifs_remap(cifs_sb));
536 kfree(file_info);
537 return rc;
538 }
539
cifs_query_path_info(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_sb_info * cifs_sb,const char * full_path,struct cifs_open_info_data * data)540 static int cifs_query_path_info(const unsigned int xid,
541 struct cifs_tcon *tcon,
542 struct cifs_sb_info *cifs_sb,
543 const char *full_path,
544 struct cifs_open_info_data *data)
545 {
546 int rc;
547 FILE_ALL_INFO fi = {};
548
549 data->reparse_point = false;
550 data->adjust_tz = false;
551
552 /* could do find first instead but this returns more info */
553 rc = CIFSSMBQPathInfo(xid, tcon, full_path, &fi, 0 /* not legacy */, cifs_sb->local_nls,
554 cifs_remap(cifs_sb));
555 /*
556 * BB optimize code so we do not make the above call when server claims
557 * no NT SMB support and the above call failed at least once - set flag
558 * in tcon or mount.
559 */
560 if ((rc == -EOPNOTSUPP) || (rc == -EINVAL)) {
561 rc = SMBQueryInformation(xid, tcon, full_path, &fi, cifs_sb->local_nls,
562 cifs_remap(cifs_sb));
563 data->adjust_tz = true;
564 }
565
566 if (!rc) {
567 move_cifs_info_to_smb2(&data->fi, &fi);
568 data->reparse_point = le32_to_cpu(fi.Attributes) & ATTR_REPARSE;
569 }
570
571 return rc;
572 }
573
cifs_get_srv_inum(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_sb_info * cifs_sb,const char * full_path,u64 * uniqueid,struct cifs_open_info_data * unused)574 static int cifs_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
575 struct cifs_sb_info *cifs_sb, const char *full_path,
576 u64 *uniqueid, struct cifs_open_info_data *unused)
577 {
578 /*
579 * We can not use the IndexNumber field by default from Windows or
580 * Samba (in ALL_INFO buf) but we can request it explicitly. The SNIA
581 * CIFS spec claims that this value is unique within the scope of a
582 * share, and the windows docs hint that it's actually unique
583 * per-machine.
584 *
585 * There may be higher info levels that work but are there Windows
586 * server or network appliances for which IndexNumber field is not
587 * guaranteed unique?
588 *
589 * CIFSGetSrvInodeNumber() uses SMB_QUERY_FILE_INTERNAL_INFO
590 * which is SMB PASSTHROUGH level therefore check for capability.
591 * Note that this function can be called with tcon == NULL.
592 */
593 if (tcon && !(tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU))
594 return -EOPNOTSUPP;
595 return CIFSGetSrvInodeNumber(xid, tcon, full_path, uniqueid,
596 cifs_sb->local_nls,
597 cifs_remap(cifs_sb));
598 }
599
cifs_query_file_info(const unsigned int xid,struct cifs_tcon * tcon,struct cifsFileInfo * cfile,struct cifs_open_info_data * data)600 static int cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
601 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
602 {
603 int rc;
604 FILE_ALL_INFO fi = {};
605
606 if (cfile->symlink_target) {
607 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
608 if (!data->symlink_target)
609 return -ENOMEM;
610 }
611
612 rc = CIFSSMBQFileInfo(xid, tcon, cfile->fid.netfid, &fi);
613 if (!rc)
614 move_cifs_info_to_smb2(&data->fi, &fi);
615 return rc;
616 }
617
618 static void
cifs_clear_stats(struct cifs_tcon * tcon)619 cifs_clear_stats(struct cifs_tcon *tcon)
620 {
621 atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
622 atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
623 atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
624 atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
625 atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
626 atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
627 atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
628 atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
629 atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
630 atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
631 atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
632 atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
633 atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
634 atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
635 atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
636 atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
637 atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
638 atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
639 atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
640 atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
641 atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
642 }
643
644 static void
cifs_print_stats(struct seq_file * m,struct cifs_tcon * tcon)645 cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
646 {
647 seq_printf(m, " Oplocks breaks: %d",
648 atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
649 seq_printf(m, "\nReads: %d Bytes: %llu",
650 atomic_read(&tcon->stats.cifs_stats.num_reads),
651 (long long)(tcon->bytes_read));
652 seq_printf(m, "\nWrites: %d Bytes: %llu",
653 atomic_read(&tcon->stats.cifs_stats.num_writes),
654 (long long)(tcon->bytes_written));
655 seq_printf(m, "\nFlushes: %d",
656 atomic_read(&tcon->stats.cifs_stats.num_flushes));
657 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
658 atomic_read(&tcon->stats.cifs_stats.num_locks),
659 atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
660 atomic_read(&tcon->stats.cifs_stats.num_symlinks));
661 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
662 atomic_read(&tcon->stats.cifs_stats.num_opens),
663 atomic_read(&tcon->stats.cifs_stats.num_closes),
664 atomic_read(&tcon->stats.cifs_stats.num_deletes));
665 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
666 atomic_read(&tcon->stats.cifs_stats.num_posixopens),
667 atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
668 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
669 atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
670 atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
671 seq_printf(m, "\nRenames: %d T2 Renames %d",
672 atomic_read(&tcon->stats.cifs_stats.num_renames),
673 atomic_read(&tcon->stats.cifs_stats.num_t2renames));
674 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
675 atomic_read(&tcon->stats.cifs_stats.num_ffirst),
676 atomic_read(&tcon->stats.cifs_stats.num_fnext),
677 atomic_read(&tcon->stats.cifs_stats.num_fclose));
678 }
679
680 static void
cifs_mkdir_setinfo(struct inode * inode,const char * full_path,struct cifs_sb_info * cifs_sb,struct cifs_tcon * tcon,const unsigned int xid)681 cifs_mkdir_setinfo(struct inode *inode, const char *full_path,
682 struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon,
683 const unsigned int xid)
684 {
685 FILE_BASIC_INFO info;
686 struct cifsInodeInfo *cifsInode;
687 u32 dosattrs;
688 int rc;
689
690 memset(&info, 0, sizeof(info));
691 cifsInode = CIFS_I(inode);
692 dosattrs = cifsInode->cifsAttrs|ATTR_READONLY;
693 info.Attributes = cpu_to_le32(dosattrs);
694 rc = CIFSSMBSetPathInfo(xid, tcon, full_path, &info, cifs_sb->local_nls,
695 cifs_sb);
696 if (rc == 0)
697 cifsInode->cifsAttrs = dosattrs;
698 }
699
cifs_open_file(const unsigned int xid,struct cifs_open_parms * oparms,__u32 * oplock,void * buf)700 static int cifs_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32 *oplock,
701 void *buf)
702 {
703 struct cifs_open_info_data *data = buf;
704 FILE_ALL_INFO fi = {};
705 int rc;
706
707 if (!(oparms->tcon->ses->capabilities & CAP_NT_SMBS))
708 rc = SMBLegacyOpen(xid, oparms->tcon, oparms->path,
709 oparms->disposition,
710 oparms->desired_access,
711 oparms->create_options,
712 &oparms->fid->netfid, oplock, &fi,
713 oparms->cifs_sb->local_nls,
714 cifs_remap(oparms->cifs_sb));
715 else
716 rc = CIFS_open(xid, oparms, oplock, &fi);
717
718 if (!rc && data)
719 move_cifs_info_to_smb2(&data->fi, &fi);
720
721 return rc;
722 }
723
724 static void
cifs_set_fid(struct cifsFileInfo * cfile,struct cifs_fid * fid,__u32 oplock)725 cifs_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
726 {
727 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
728 cfile->fid.netfid = fid->netfid;
729 cifs_set_oplock_level(cinode, oplock);
730 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
731 }
732
733 static int
cifs_close_file(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_fid * fid)734 cifs_close_file(const unsigned int xid, struct cifs_tcon *tcon,
735 struct cifs_fid *fid)
736 {
737 return CIFSSMBClose(xid, tcon, fid->netfid);
738 }
739
740 static int
cifs_flush_file(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_fid * fid)741 cifs_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
742 struct cifs_fid *fid)
743 {
744 return CIFSSMBFlush(xid, tcon, fid->netfid);
745 }
746
747 static int
cifs_sync_read(const unsigned int xid,struct cifs_fid * pfid,struct cifs_io_parms * parms,unsigned int * bytes_read,char ** buf,int * buf_type)748 cifs_sync_read(const unsigned int xid, struct cifs_fid *pfid,
749 struct cifs_io_parms *parms, unsigned int *bytes_read,
750 char **buf, int *buf_type)
751 {
752 parms->netfid = pfid->netfid;
753 return CIFSSMBRead(xid, parms, bytes_read, buf, buf_type);
754 }
755
756 static int
cifs_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)757 cifs_sync_write(const unsigned int xid, struct cifs_fid *pfid,
758 struct cifs_io_parms *parms, unsigned int *written,
759 struct kvec *iov, unsigned long nr_segs)
760 {
761
762 parms->netfid = pfid->netfid;
763 return CIFSSMBWrite2(xid, parms, written, iov, nr_segs);
764 }
765
766 static int
smb_set_file_info(struct inode * inode,const char * full_path,FILE_BASIC_INFO * buf,const unsigned int xid)767 smb_set_file_info(struct inode *inode, const char *full_path,
768 FILE_BASIC_INFO *buf, const unsigned int xid)
769 {
770 int oplock = 0;
771 int rc;
772 __u32 netpid;
773 struct cifs_fid fid;
774 struct cifs_open_parms oparms;
775 struct cifsFileInfo *open_file;
776 struct cifsInodeInfo *cinode = CIFS_I(inode);
777 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
778 struct tcon_link *tlink = NULL;
779 struct cifs_tcon *tcon;
780
781 /* if the file is already open for write, just use that fileid */
782 open_file = find_writable_file(cinode, FIND_WR_FSUID_ONLY);
783 if (open_file) {
784 fid.netfid = open_file->fid.netfid;
785 netpid = open_file->pid;
786 tcon = tlink_tcon(open_file->tlink);
787 goto set_via_filehandle;
788 }
789
790 tlink = cifs_sb_tlink(cifs_sb);
791 if (IS_ERR(tlink)) {
792 rc = PTR_ERR(tlink);
793 tlink = NULL;
794 goto out;
795 }
796 tcon = tlink_tcon(tlink);
797
798 rc = CIFSSMBSetPathInfo(xid, tcon, full_path, buf, cifs_sb->local_nls,
799 cifs_sb);
800 if (rc == 0) {
801 cinode->cifsAttrs = le32_to_cpu(buf->Attributes);
802 goto out;
803 } else if (rc != -EOPNOTSUPP && rc != -EINVAL) {
804 goto out;
805 }
806
807 oparms = (struct cifs_open_parms) {
808 .tcon = tcon,
809 .cifs_sb = cifs_sb,
810 .desired_access = SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
811 .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR),
812 .disposition = FILE_OPEN,
813 .path = full_path,
814 .fid = &fid,
815 };
816
817 cifs_dbg(FYI, "calling SetFileInfo since SetPathInfo for times not supported by this server\n");
818 rc = CIFS_open(xid, &oparms, &oplock, NULL);
819 if (rc != 0) {
820 if (rc == -EIO)
821 rc = -EINVAL;
822 goto out;
823 }
824
825 netpid = current->tgid;
826
827 set_via_filehandle:
828 rc = CIFSSMBSetFileInfo(xid, tcon, buf, fid.netfid, netpid);
829 if (!rc)
830 cinode->cifsAttrs = le32_to_cpu(buf->Attributes);
831
832 if (open_file == NULL)
833 CIFSSMBClose(xid, tcon, fid.netfid);
834 else
835 cifsFileInfo_put(open_file);
836 out:
837 if (tlink != NULL)
838 cifs_put_tlink(tlink);
839 return rc;
840 }
841
842 static int
cifs_set_compression(const unsigned int xid,struct cifs_tcon * tcon,struct cifsFileInfo * cfile)843 cifs_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
844 struct cifsFileInfo *cfile)
845 {
846 return CIFSSMB_set_compression(xid, tcon, cfile->fid.netfid);
847 }
848
849 static int
cifs_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)850 cifs_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
851 const char *path, struct cifs_sb_info *cifs_sb,
852 struct cifs_fid *fid, __u16 search_flags,
853 struct cifs_search_info *srch_inf)
854 {
855 int rc;
856
857 rc = CIFSFindFirst(xid, tcon, path, cifs_sb,
858 &fid->netfid, search_flags, srch_inf, true);
859 if (rc)
860 cifs_dbg(FYI, "find first failed=%d\n", rc);
861 return rc;
862 }
863
864 static int
cifs_query_dir_next(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_fid * fid,__u16 search_flags,struct cifs_search_info * srch_inf)865 cifs_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
866 struct cifs_fid *fid, __u16 search_flags,
867 struct cifs_search_info *srch_inf)
868 {
869 return CIFSFindNext(xid, tcon, fid->netfid, search_flags, srch_inf);
870 }
871
872 static int
cifs_close_dir(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_fid * fid)873 cifs_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
874 struct cifs_fid *fid)
875 {
876 return CIFSFindClose(xid, tcon, fid->netfid);
877 }
878
879 static int
cifs_oplock_response(struct cifs_tcon * tcon,__u64 persistent_fid,__u64 volatile_fid,__u16 net_fid,struct cifsInodeInfo * cinode)880 cifs_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
881 __u64 volatile_fid, __u16 net_fid, struct cifsInodeInfo *cinode)
882 {
883 return CIFSSMBLock(0, tcon, net_fid, current->tgid, 0, 0, 0, 0,
884 LOCKING_ANDX_OPLOCK_RELEASE, false, CIFS_CACHE_READ(cinode) ? 1 : 0);
885 }
886
887 static int
cifs_queryfs(const unsigned int xid,struct cifs_tcon * tcon,const char * path,struct cifs_sb_info * cifs_sb,struct kstatfs * buf)888 cifs_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
889 const char *path, struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
890 {
891 int rc = -EOPNOTSUPP;
892
893 buf->f_type = CIFS_SUPER_MAGIC;
894
895 /*
896 * We could add a second check for a QFS Unix capability bit
897 */
898 if ((tcon->ses->capabilities & CAP_UNIX) &&
899 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
900 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
901
902 /*
903 * Only need to call the old QFSInfo if failed on newer one,
904 * e.g. by OS/2.
905 **/
906 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
907 rc = CIFSSMBQFSInfo(xid, tcon, buf);
908
909 /*
910 * Some old Windows servers also do not support level 103, retry with
911 * older level one if old server failed the previous call or we
912 * bypassed it because we detected that this was an older LANMAN sess
913 */
914 if (rc)
915 rc = SMBOldQFSInfo(xid, tcon, buf);
916 return rc;
917 }
918
919 static int
cifs_mand_lock(const unsigned int xid,struct cifsFileInfo * cfile,__u64 offset,__u64 length,__u32 type,int lock,int unlock,bool wait)920 cifs_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
921 __u64 length, __u32 type, int lock, int unlock, bool wait)
922 {
923 return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->fid.netfid,
924 current->tgid, length, offset, unlock, lock,
925 (__u8)type, wait, 0);
926 }
927
928 static int
cifs_unix_dfs_readlink(const unsigned int xid,struct cifs_tcon * tcon,const unsigned char * searchName,char ** symlinkinfo,const struct nls_table * nls_codepage)929 cifs_unix_dfs_readlink(const unsigned int xid, struct cifs_tcon *tcon,
930 const unsigned char *searchName, char **symlinkinfo,
931 const struct nls_table *nls_codepage)
932 {
933 #ifdef CONFIG_CIFS_DFS_UPCALL
934 int rc;
935 struct dfs_info3_param referral = {0};
936
937 rc = get_dfs_path(xid, tcon->ses, searchName, nls_codepage, &referral,
938 0);
939
940 if (!rc) {
941 *symlinkinfo = kstrdup(referral.node_name, GFP_KERNEL);
942 free_dfs_info_param(&referral);
943 if (!*symlinkinfo)
944 rc = -ENOMEM;
945 }
946 return rc;
947 #else /* No DFS support */
948 return -EREMOTE;
949 #endif
950 }
951
cifs_query_symlink(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_sb_info * cifs_sb,const char * full_path,char ** target_path)952 static int cifs_query_symlink(const unsigned int xid,
953 struct cifs_tcon *tcon,
954 struct cifs_sb_info *cifs_sb,
955 const char *full_path,
956 char **target_path)
957 {
958 int rc;
959
960 cifs_tcon_dbg(FYI, "%s: path=%s\n", __func__, full_path);
961
962 if (!cap_unix(tcon->ses))
963 return -EOPNOTSUPP;
964
965 rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, target_path,
966 cifs_sb->local_nls, cifs_remap(cifs_sb));
967 if (rc == -EREMOTE)
968 rc = cifs_unix_dfs_readlink(xid, tcon, full_path,
969 target_path, cifs_sb->local_nls);
970 return rc;
971 }
972
cifs_parse_reparse_point(struct cifs_sb_info * cifs_sb,const char * full_path,struct kvec * rsp_iov,struct cifs_open_info_data * data)973 static int cifs_parse_reparse_point(struct cifs_sb_info *cifs_sb,
974 const char *full_path,
975 struct kvec *rsp_iov,
976 struct cifs_open_info_data *data)
977 {
978 struct reparse_data_buffer *buf;
979 TRANSACT_IOCTL_RSP *io = rsp_iov->iov_base;
980 u32 plen = le16_to_cpu(io->ByteCount);
981
982 buf = (struct reparse_data_buffer *)((__u8 *)&io->hdr.Protocol +
983 le32_to_cpu(io->DataOffset));
984 return parse_reparse_point(buf, plen, cifs_sb, full_path, data);
985 }
986
987 static bool
cifs_is_read_op(__u32 oplock)988 cifs_is_read_op(__u32 oplock)
989 {
990 return oplock == OPLOCK_READ;
991 }
992
993 static unsigned int
cifs_wp_retry_size(struct inode * inode)994 cifs_wp_retry_size(struct inode *inode)
995 {
996 return CIFS_SB(inode->i_sb)->ctx->wsize;
997 }
998
999 static bool
cifs_dir_needs_close(struct cifsFileInfo * cfile)1000 cifs_dir_needs_close(struct cifsFileInfo *cfile)
1001 {
1002 return !cfile->srch_inf.endOfSearch && !cfile->invalidHandle;
1003 }
1004
1005 static bool
cifs_can_echo(struct TCP_Server_Info * server)1006 cifs_can_echo(struct TCP_Server_Info *server)
1007 {
1008 if (server->tcpStatus == CifsGood)
1009 return true;
1010
1011 return false;
1012 }
1013
1014 static int
cifs_make_node(unsigned int xid,struct inode * inode,struct dentry * dentry,struct cifs_tcon * tcon,const char * full_path,umode_t mode,dev_t dev)1015 cifs_make_node(unsigned int xid, struct inode *inode,
1016 struct dentry *dentry, struct cifs_tcon *tcon,
1017 const char *full_path, umode_t mode, dev_t dev)
1018 {
1019 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1020 struct inode *newinode = NULL;
1021 int rc;
1022
1023 if (tcon->unix_ext) {
1024 /*
1025 * SMB1 Unix Extensions: requires server support but
1026 * works with all special files
1027 */
1028 struct cifs_unix_set_info_args args = {
1029 .mode = mode & ~current_umask(),
1030 .ctime = NO_CHANGE_64,
1031 .atime = NO_CHANGE_64,
1032 .mtime = NO_CHANGE_64,
1033 .device = dev,
1034 };
1035 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
1036 args.uid = current_fsuid();
1037 args.gid = current_fsgid();
1038 } else {
1039 args.uid = INVALID_UID; /* no change */
1040 args.gid = INVALID_GID; /* no change */
1041 }
1042 rc = CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args,
1043 cifs_sb->local_nls,
1044 cifs_remap(cifs_sb));
1045 if (rc)
1046 return rc;
1047
1048 rc = cifs_get_inode_info_unix(&newinode, full_path,
1049 inode->i_sb, xid);
1050
1051 if (rc == 0)
1052 d_instantiate(dentry, newinode);
1053 return rc;
1054 }
1055 /*
1056 * Check if mounted with mount parm 'sfu' mount parm.
1057 * SFU emulation should work with all servers, but only
1058 * supports block and char device, socket & fifo,
1059 * and was used by default in earlier versions of Windows
1060 */
1061 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
1062 return -EPERM;
1063 return cifs_sfu_make_node(xid, inode, dentry, tcon,
1064 full_path, mode, dev);
1065 }
1066
1067 static bool
cifs_is_network_name_deleted(char * buf,struct TCP_Server_Info * server)1068 cifs_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
1069 {
1070 struct smb_hdr *shdr = (struct smb_hdr *)buf;
1071 struct TCP_Server_Info *pserver;
1072 struct cifs_ses *ses;
1073 struct cifs_tcon *tcon;
1074
1075 if (shdr->Flags2 & SMBFLG2_ERR_STATUS) {
1076 if (shdr->Status.CifsError != cpu_to_le32(NT_STATUS_NETWORK_NAME_DELETED))
1077 return false;
1078 } else {
1079 if (shdr->Status.DosError.ErrorClass != ERRSRV ||
1080 shdr->Status.DosError.Error != cpu_to_le16(ERRinvtid))
1081 return false;
1082 }
1083
1084 /* If server is a channel, select the primary channel */
1085 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
1086
1087 spin_lock(&cifs_tcp_ses_lock);
1088 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
1089 if (cifs_ses_exiting(ses))
1090 continue;
1091 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
1092 if (tcon->tid == shdr->Tid) {
1093 spin_lock(&tcon->tc_lock);
1094 tcon->need_reconnect = true;
1095 spin_unlock(&tcon->tc_lock);
1096 spin_unlock(&cifs_tcp_ses_lock);
1097 pr_warn_once("Server share %s deleted.\n",
1098 tcon->tree_name);
1099 return true;
1100 }
1101 }
1102 }
1103 spin_unlock(&cifs_tcp_ses_lock);
1104
1105 return false;
1106 }
1107
1108 struct smb_version_operations smb1_operations = {
1109 .send_cancel = send_nt_cancel,
1110 .compare_fids = cifs_compare_fids,
1111 .setup_request = cifs_setup_request,
1112 .setup_async_request = cifs_setup_async_request,
1113 .check_receive = cifs_check_receive,
1114 .add_credits = cifs_add_credits,
1115 .set_credits = cifs_set_credits,
1116 .get_credits_field = cifs_get_credits_field,
1117 .get_credits = cifs_get_credits,
1118 .wait_mtu_credits = cifs_wait_mtu_credits,
1119 .get_next_mid = cifs_get_next_mid,
1120 .read_data_offset = cifs_read_data_offset,
1121 .read_data_length = cifs_read_data_length,
1122 .map_error = map_smb_to_linux_error,
1123 .find_mid = cifs_find_mid,
1124 .check_message = checkSMB,
1125 .dump_detail = cifs_dump_detail,
1126 .clear_stats = cifs_clear_stats,
1127 .print_stats = cifs_print_stats,
1128 .is_oplock_break = is_valid_oplock_break,
1129 .downgrade_oplock = cifs_downgrade_oplock,
1130 .check_trans2 = cifs_check_trans2,
1131 .need_neg = cifs_need_neg,
1132 .negotiate = cifs_negotiate,
1133 .negotiate_wsize = cifs_negotiate_wsize,
1134 .negotiate_rsize = cifs_negotiate_rsize,
1135 .sess_setup = CIFS_SessSetup,
1136 .logoff = CIFSSMBLogoff,
1137 .tree_connect = CIFSTCon,
1138 .tree_disconnect = CIFSSMBTDis,
1139 .get_dfs_refer = CIFSGetDFSRefer,
1140 .qfs_tcon = cifs_qfs_tcon,
1141 .is_path_accessible = cifs_is_path_accessible,
1142 .can_echo = cifs_can_echo,
1143 .query_path_info = cifs_query_path_info,
1144 .query_reparse_point = cifs_query_reparse_point,
1145 .query_file_info = cifs_query_file_info,
1146 .get_srv_inum = cifs_get_srv_inum,
1147 .set_path_size = CIFSSMBSetEOF,
1148 .set_file_size = CIFSSMBSetFileSize,
1149 .set_file_info = smb_set_file_info,
1150 .set_compression = cifs_set_compression,
1151 .echo = CIFSSMBEcho,
1152 .mkdir = CIFSSMBMkDir,
1153 .mkdir_setinfo = cifs_mkdir_setinfo,
1154 .rmdir = CIFSSMBRmDir,
1155 .unlink = CIFSSMBDelFile,
1156 .rename_pending_delete = cifs_rename_pending_delete,
1157 .rename = CIFSSMBRename,
1158 .create_hardlink = CIFSCreateHardLink,
1159 .query_symlink = cifs_query_symlink,
1160 .parse_reparse_point = cifs_parse_reparse_point,
1161 .open = cifs_open_file,
1162 .set_fid = cifs_set_fid,
1163 .close = cifs_close_file,
1164 .flush = cifs_flush_file,
1165 .async_readv = cifs_async_readv,
1166 .async_writev = cifs_async_writev,
1167 .sync_read = cifs_sync_read,
1168 .sync_write = cifs_sync_write,
1169 .query_dir_first = cifs_query_dir_first,
1170 .query_dir_next = cifs_query_dir_next,
1171 .close_dir = cifs_close_dir,
1172 .calc_smb_size = smbCalcSize,
1173 .oplock_response = cifs_oplock_response,
1174 .queryfs = cifs_queryfs,
1175 .mand_lock = cifs_mand_lock,
1176 .mand_unlock_range = cifs_unlock_range,
1177 .push_mand_locks = cifs_push_mandatory_locks,
1178 .query_mf_symlink = cifs_query_mf_symlink,
1179 .create_mf_symlink = cifs_create_mf_symlink,
1180 .is_read_op = cifs_is_read_op,
1181 .wp_retry_size = cifs_wp_retry_size,
1182 .dir_needs_close = cifs_dir_needs_close,
1183 .select_sectype = cifs_select_sectype,
1184 #ifdef CONFIG_CIFS_XATTR
1185 .query_all_EAs = CIFSSMBQAllEAs,
1186 .set_EA = CIFSSMBSetEA,
1187 #endif /* CIFS_XATTR */
1188 .get_acl = get_cifs_acl,
1189 .get_acl_by_fid = get_cifs_acl_by_fid,
1190 .set_acl = set_cifs_acl,
1191 .make_node = cifs_make_node,
1192 .is_network_name_deleted = cifs_is_network_name_deleted,
1193 };
1194
1195 struct smb_version_values smb1_values = {
1196 .version_string = SMB1_VERSION_STRING,
1197 .protocol_id = SMB10_PROT_ID,
1198 .large_lock_type = LOCKING_ANDX_LARGE_FILES,
1199 .exclusive_lock_type = 0,
1200 .shared_lock_type = LOCKING_ANDX_SHARED_LOCK,
1201 .unlock_lock_type = 0,
1202 .header_preamble_size = 4,
1203 .header_size = sizeof(struct smb_hdr),
1204 .max_header_size = MAX_CIFS_HDR_SIZE,
1205 .read_rsp_size = sizeof(READ_RSP),
1206 .lock_cmd = cpu_to_le16(SMB_COM_LOCKING_ANDX),
1207 .cap_unix = CAP_UNIX,
1208 .cap_nt_find = CAP_NT_SMBS | CAP_NT_FIND,
1209 .cap_large_files = CAP_LARGE_FILES,
1210 .cap_unicode = CAP_UNICODE,
1211 .signing_enabled = SECMODE_SIGN_ENABLED,
1212 .signing_required = SECMODE_SIGN_REQUIRED,
1213 };
1214