smb1ops.c 35 KB

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