smb1ops.c 36 KB

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