smb2ops.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. /*
  2. * SMB2 version specific operations
  3. *
  4. * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
  5. *
  6. * This library is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License v2 as published
  8. * by the Free Software Foundation.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/pagemap.h>
  20. #include <linux/vfs.h>
  21. #include "cifsglob.h"
  22. #include "smb2pdu.h"
  23. #include "smb2proto.h"
  24. #include "cifsproto.h"
  25. #include "cifs_debug.h"
  26. #include "cifs_unicode.h"
  27. #include "smb2status.h"
  28. #include "smb2glob.h"
  29. static int
  30. change_conf(struct TCP_Server_Info *server)
  31. {
  32. server->credits += server->echo_credits + server->oplock_credits;
  33. server->oplock_credits = server->echo_credits = 0;
  34. switch (server->credits) {
  35. case 0:
  36. return -1;
  37. case 1:
  38. server->echoes = false;
  39. server->oplocks = false;
  40. cifs_dbg(VFS, "disabling echoes and oplocks\n");
  41. break;
  42. case 2:
  43. server->echoes = true;
  44. server->oplocks = false;
  45. server->echo_credits = 1;
  46. cifs_dbg(FYI, "disabling oplocks\n");
  47. break;
  48. default:
  49. server->echoes = true;
  50. server->oplocks = true;
  51. server->echo_credits = 1;
  52. server->oplock_credits = 1;
  53. }
  54. server->credits -= server->echo_credits + server->oplock_credits;
  55. return 0;
  56. }
  57. static void
  58. smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
  59. const int optype)
  60. {
  61. int *val, rc = 0;
  62. spin_lock(&server->req_lock);
  63. val = server->ops->get_credits_field(server, optype);
  64. *val += add;
  65. server->in_flight--;
  66. if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
  67. rc = change_conf(server);
  68. /*
  69. * Sometimes server returns 0 credits on oplock break ack - we need to
  70. * rebalance credits in this case.
  71. */
  72. else if (server->in_flight > 0 && server->oplock_credits == 0 &&
  73. server->oplocks) {
  74. if (server->credits > 1) {
  75. server->credits--;
  76. server->oplock_credits++;
  77. }
  78. }
  79. spin_unlock(&server->req_lock);
  80. wake_up(&server->request_q);
  81. if (rc)
  82. cifs_reconnect(server);
  83. }
  84. static void
  85. smb2_set_credits(struct TCP_Server_Info *server, const int val)
  86. {
  87. spin_lock(&server->req_lock);
  88. server->credits = val;
  89. spin_unlock(&server->req_lock);
  90. }
  91. static int *
  92. smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
  93. {
  94. switch (optype) {
  95. case CIFS_ECHO_OP:
  96. return &server->echo_credits;
  97. case CIFS_OBREAK_OP:
  98. return &server->oplock_credits;
  99. default:
  100. return &server->credits;
  101. }
  102. }
  103. static unsigned int
  104. smb2_get_credits(struct mid_q_entry *mid)
  105. {
  106. return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
  107. }
  108. static __u64
  109. smb2_get_next_mid(struct TCP_Server_Info *server)
  110. {
  111. __u64 mid;
  112. /* for SMB2 we need the current value */
  113. spin_lock(&GlobalMid_Lock);
  114. mid = server->CurrentMid++;
  115. spin_unlock(&GlobalMid_Lock);
  116. return mid;
  117. }
  118. static struct mid_q_entry *
  119. smb2_find_mid(struct TCP_Server_Info *server, char *buf)
  120. {
  121. struct mid_q_entry *mid;
  122. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  123. spin_lock(&GlobalMid_Lock);
  124. list_for_each_entry(mid, &server->pending_mid_q, qhead) {
  125. if ((mid->mid == hdr->MessageId) &&
  126. (mid->mid_state == MID_REQUEST_SUBMITTED) &&
  127. (mid->command == hdr->Command)) {
  128. spin_unlock(&GlobalMid_Lock);
  129. return mid;
  130. }
  131. }
  132. spin_unlock(&GlobalMid_Lock);
  133. return NULL;
  134. }
  135. static void
  136. smb2_dump_detail(void *buf)
  137. {
  138. #ifdef CONFIG_CIFS_DEBUG2
  139. struct smb2_hdr *smb = (struct smb2_hdr *)buf;
  140. cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
  141. smb->Command, smb->Status, smb->Flags, smb->MessageId,
  142. smb->ProcessId);
  143. cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
  144. #endif
  145. }
  146. static bool
  147. smb2_need_neg(struct TCP_Server_Info *server)
  148. {
  149. return server->max_read == 0;
  150. }
  151. static int
  152. smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
  153. {
  154. int rc;
  155. ses->server->CurrentMid = 0;
  156. rc = SMB2_negotiate(xid, ses);
  157. /* BB we probably don't need to retry with modern servers */
  158. if (rc == -EAGAIN)
  159. rc = -EHOSTDOWN;
  160. return rc;
  161. }
  162. static unsigned int
  163. smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  164. {
  165. struct TCP_Server_Info *server = tcon->ses->server;
  166. unsigned int wsize;
  167. /* start with specified wsize, or default */
  168. wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
  169. wsize = min_t(unsigned int, wsize, server->max_write);
  170. /*
  171. * limit write size to 2 ** 16, because we don't support multicredit
  172. * requests now.
  173. */
  174. wsize = min_t(unsigned int, wsize, 2 << 15);
  175. return wsize;
  176. }
  177. static unsigned int
  178. smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  179. {
  180. struct TCP_Server_Info *server = tcon->ses->server;
  181. unsigned int rsize;
  182. /* start with specified rsize, or default */
  183. rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
  184. rsize = min_t(unsigned int, rsize, server->max_read);
  185. /*
  186. * limit write size to 2 ** 16, because we don't support multicredit
  187. * requests now.
  188. */
  189. rsize = min_t(unsigned int, rsize, 2 << 15);
  190. return rsize;
  191. }
  192. #ifdef CONFIG_CIFS_STATS2
  193. static int
  194. SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
  195. {
  196. int rc;
  197. unsigned int ret_data_len = 0;
  198. struct network_interface_info_ioctl_rsp *out_buf;
  199. rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
  200. FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
  201. NULL /* no data input */, 0 /* no data input */,
  202. (char **)&out_buf, &ret_data_len);
  203. if ((rc == 0) && (ret_data_len > 0)) {
  204. /* Dump info on first interface */
  205. cifs_dbg(FYI, "Adapter Capability 0x%x\t",
  206. le32_to_cpu(out_buf->Capability));
  207. cifs_dbg(FYI, "Link Speed %lld\n",
  208. le64_to_cpu(out_buf->LinkSpeed));
  209. } else
  210. cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
  211. return rc;
  212. }
  213. #endif /* STATS2 */
  214. static void
  215. smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  216. {
  217. int rc;
  218. __le16 srch_path = 0; /* Null - open root of share */
  219. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  220. struct cifs_open_parms oparms;
  221. struct cifs_fid fid;
  222. oparms.tcon = tcon;
  223. oparms.desired_access = FILE_READ_ATTRIBUTES;
  224. oparms.disposition = FILE_OPEN;
  225. oparms.create_options = 0;
  226. oparms.fid = &fid;
  227. oparms.reconnect = false;
  228. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  229. if (rc)
  230. return;
  231. #ifdef CONFIG_CIFS_STATS2
  232. SMB3_request_interfaces(xid, tcon);
  233. #endif /* STATS2 */
  234. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  235. FS_ATTRIBUTE_INFORMATION);
  236. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  237. FS_DEVICE_INFORMATION);
  238. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  239. FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
  240. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  241. return;
  242. }
  243. static void
  244. smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  245. {
  246. int rc;
  247. __le16 srch_path = 0; /* Null - open root of share */
  248. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  249. struct cifs_open_parms oparms;
  250. struct cifs_fid fid;
  251. oparms.tcon = tcon;
  252. oparms.desired_access = FILE_READ_ATTRIBUTES;
  253. oparms.disposition = FILE_OPEN;
  254. oparms.create_options = 0;
  255. oparms.fid = &fid;
  256. oparms.reconnect = false;
  257. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  258. if (rc)
  259. return;
  260. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  261. FS_ATTRIBUTE_INFORMATION);
  262. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  263. FS_DEVICE_INFORMATION);
  264. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  265. return;
  266. }
  267. static int
  268. smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
  269. struct cifs_sb_info *cifs_sb, const char *full_path)
  270. {
  271. int rc;
  272. __le16 *utf16_path;
  273. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  274. struct cifs_open_parms oparms;
  275. struct cifs_fid fid;
  276. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  277. if (!utf16_path)
  278. return -ENOMEM;
  279. oparms.tcon = tcon;
  280. oparms.desired_access = FILE_READ_ATTRIBUTES;
  281. oparms.disposition = FILE_OPEN;
  282. oparms.create_options = 0;
  283. oparms.fid = &fid;
  284. oparms.reconnect = false;
  285. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  286. if (rc) {
  287. kfree(utf16_path);
  288. return rc;
  289. }
  290. rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  291. kfree(utf16_path);
  292. return rc;
  293. }
  294. static int
  295. smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
  296. struct cifs_sb_info *cifs_sb, const char *full_path,
  297. u64 *uniqueid, FILE_ALL_INFO *data)
  298. {
  299. *uniqueid = le64_to_cpu(data->IndexNumber);
  300. return 0;
  301. }
  302. static int
  303. smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
  304. struct cifs_fid *fid, FILE_ALL_INFO *data)
  305. {
  306. int rc;
  307. struct smb2_file_all_info *smb2_data;
  308. smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
  309. GFP_KERNEL);
  310. if (smb2_data == NULL)
  311. return -ENOMEM;
  312. rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
  313. smb2_data);
  314. if (!rc)
  315. move_smb2_info_to_cifs(data, smb2_data);
  316. kfree(smb2_data);
  317. return rc;
  318. }
  319. static bool
  320. smb2_can_echo(struct TCP_Server_Info *server)
  321. {
  322. return server->echoes;
  323. }
  324. static void
  325. smb2_clear_stats(struct cifs_tcon *tcon)
  326. {
  327. #ifdef CONFIG_CIFS_STATS
  328. int i;
  329. for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
  330. atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
  331. atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
  332. }
  333. #endif
  334. }
  335. static void
  336. smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
  337. {
  338. seq_puts(m, "\n\tShare Capabilities:");
  339. if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
  340. seq_puts(m, " DFS,");
  341. if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
  342. seq_puts(m, " CONTINUOUS AVAILABILITY,");
  343. if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
  344. seq_puts(m, " SCALEOUT,");
  345. if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
  346. seq_puts(m, " CLUSTER,");
  347. if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
  348. seq_puts(m, " ASYMMETRIC,");
  349. if (tcon->capabilities == 0)
  350. seq_puts(m, " None");
  351. if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
  352. seq_puts(m, " Aligned,");
  353. if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
  354. seq_puts(m, " Partition Aligned,");
  355. if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
  356. seq_puts(m, " SSD,");
  357. if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
  358. seq_puts(m, " TRIM-support,");
  359. seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
  360. if (tcon->perf_sector_size)
  361. seq_printf(m, "\tOptimal sector size: 0x%x",
  362. tcon->perf_sector_size);
  363. }
  364. static void
  365. smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
  366. {
  367. #ifdef CONFIG_CIFS_STATS
  368. atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
  369. atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
  370. seq_printf(m, "\nNegotiates: %d sent %d failed",
  371. atomic_read(&sent[SMB2_NEGOTIATE_HE]),
  372. atomic_read(&failed[SMB2_NEGOTIATE_HE]));
  373. seq_printf(m, "\nSessionSetups: %d sent %d failed",
  374. atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
  375. atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
  376. seq_printf(m, "\nLogoffs: %d sent %d failed",
  377. atomic_read(&sent[SMB2_LOGOFF_HE]),
  378. atomic_read(&failed[SMB2_LOGOFF_HE]));
  379. seq_printf(m, "\nTreeConnects: %d sent %d failed",
  380. atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
  381. atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
  382. seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
  383. atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
  384. atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
  385. seq_printf(m, "\nCreates: %d sent %d failed",
  386. atomic_read(&sent[SMB2_CREATE_HE]),
  387. atomic_read(&failed[SMB2_CREATE_HE]));
  388. seq_printf(m, "\nCloses: %d sent %d failed",
  389. atomic_read(&sent[SMB2_CLOSE_HE]),
  390. atomic_read(&failed[SMB2_CLOSE_HE]));
  391. seq_printf(m, "\nFlushes: %d sent %d failed",
  392. atomic_read(&sent[SMB2_FLUSH_HE]),
  393. atomic_read(&failed[SMB2_FLUSH_HE]));
  394. seq_printf(m, "\nReads: %d sent %d failed",
  395. atomic_read(&sent[SMB2_READ_HE]),
  396. atomic_read(&failed[SMB2_READ_HE]));
  397. seq_printf(m, "\nWrites: %d sent %d failed",
  398. atomic_read(&sent[SMB2_WRITE_HE]),
  399. atomic_read(&failed[SMB2_WRITE_HE]));
  400. seq_printf(m, "\nLocks: %d sent %d failed",
  401. atomic_read(&sent[SMB2_LOCK_HE]),
  402. atomic_read(&failed[SMB2_LOCK_HE]));
  403. seq_printf(m, "\nIOCTLs: %d sent %d failed",
  404. atomic_read(&sent[SMB2_IOCTL_HE]),
  405. atomic_read(&failed[SMB2_IOCTL_HE]));
  406. seq_printf(m, "\nCancels: %d sent %d failed",
  407. atomic_read(&sent[SMB2_CANCEL_HE]),
  408. atomic_read(&failed[SMB2_CANCEL_HE]));
  409. seq_printf(m, "\nEchos: %d sent %d failed",
  410. atomic_read(&sent[SMB2_ECHO_HE]),
  411. atomic_read(&failed[SMB2_ECHO_HE]));
  412. seq_printf(m, "\nQueryDirectories: %d sent %d failed",
  413. atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
  414. atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
  415. seq_printf(m, "\nChangeNotifies: %d sent %d failed",
  416. atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
  417. atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
  418. seq_printf(m, "\nQueryInfos: %d sent %d failed",
  419. atomic_read(&sent[SMB2_QUERY_INFO_HE]),
  420. atomic_read(&failed[SMB2_QUERY_INFO_HE]));
  421. seq_printf(m, "\nSetInfos: %d sent %d failed",
  422. atomic_read(&sent[SMB2_SET_INFO_HE]),
  423. atomic_read(&failed[SMB2_SET_INFO_HE]));
  424. seq_printf(m, "\nOplockBreaks: %d sent %d failed",
  425. atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
  426. atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
  427. #endif
  428. }
  429. static void
  430. smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
  431. {
  432. struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
  433. struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
  434. cfile->fid.persistent_fid = fid->persistent_fid;
  435. cfile->fid.volatile_fid = fid->volatile_fid;
  436. server->ops->set_oplock_level(cinode, oplock, fid->epoch,
  437. &fid->purge_cache);
  438. cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
  439. }
  440. static void
  441. smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
  442. struct cifs_fid *fid)
  443. {
  444. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  445. }
  446. static int
  447. SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
  448. u64 persistent_fid, u64 volatile_fid,
  449. struct copychunk_ioctl *pcchunk)
  450. {
  451. int rc;
  452. unsigned int ret_data_len;
  453. struct resume_key_req *res_key;
  454. rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
  455. FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
  456. NULL, 0 /* no input */,
  457. (char **)&res_key, &ret_data_len);
  458. if (rc) {
  459. cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
  460. goto req_res_key_exit;
  461. }
  462. if (ret_data_len < sizeof(struct resume_key_req)) {
  463. cifs_dbg(VFS, "Invalid refcopy resume key length\n");
  464. rc = -EINVAL;
  465. goto req_res_key_exit;
  466. }
  467. memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
  468. req_res_key_exit:
  469. kfree(res_key);
  470. return rc;
  471. }
  472. static int
  473. smb2_clone_range(const unsigned int xid,
  474. struct cifsFileInfo *srcfile,
  475. struct cifsFileInfo *trgtfile, u64 src_off,
  476. u64 len, u64 dest_off)
  477. {
  478. int rc;
  479. unsigned int ret_data_len;
  480. struct copychunk_ioctl *pcchunk;
  481. char *retbuf = NULL;
  482. pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
  483. if (pcchunk == NULL)
  484. return -ENOMEM;
  485. cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
  486. /* Request a key from the server to identify the source of the copy */
  487. rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
  488. srcfile->fid.persistent_fid,
  489. srcfile->fid.volatile_fid, pcchunk);
  490. /* Note: request_res_key sets res_key null only if rc !=0 */
  491. if (rc)
  492. return rc;
  493. /* For now array only one chunk long, will make more flexible later */
  494. pcchunk->ChunkCount = __constant_cpu_to_le32(1);
  495. pcchunk->Reserved = 0;
  496. pcchunk->SourceOffset = cpu_to_le64(src_off);
  497. pcchunk->TargetOffset = cpu_to_le64(dest_off);
  498. pcchunk->Length = cpu_to_le32(len);
  499. pcchunk->Reserved2 = 0;
  500. /* Request that server copy to target from src file identified by key */
  501. rc = SMB2_ioctl(xid, tlink_tcon(trgtfile->tlink),
  502. trgtfile->fid.persistent_fid,
  503. trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
  504. true /* is_fsctl */, (char *)pcchunk,
  505. sizeof(struct copychunk_ioctl), &retbuf, &ret_data_len);
  506. /* BB need to special case rc = EINVAL to alter chunk size */
  507. cifs_dbg(FYI, "rc %d data length out %d\n", rc, ret_data_len);
  508. kfree(pcchunk);
  509. return rc;
  510. }
  511. static int
  512. smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
  513. struct cifs_fid *fid)
  514. {
  515. return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  516. }
  517. static unsigned int
  518. smb2_read_data_offset(char *buf)
  519. {
  520. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  521. return rsp->DataOffset;
  522. }
  523. static unsigned int
  524. smb2_read_data_length(char *buf)
  525. {
  526. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  527. return le32_to_cpu(rsp->DataLength);
  528. }
  529. static int
  530. smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
  531. struct cifs_io_parms *parms, unsigned int *bytes_read,
  532. char **buf, int *buf_type)
  533. {
  534. parms->persistent_fid = cfile->fid.persistent_fid;
  535. parms->volatile_fid = cfile->fid.volatile_fid;
  536. return SMB2_read(xid, parms, bytes_read, buf, buf_type);
  537. }
  538. static int
  539. smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
  540. struct cifs_io_parms *parms, unsigned int *written,
  541. struct kvec *iov, unsigned long nr_segs)
  542. {
  543. parms->persistent_fid = cfile->fid.persistent_fid;
  544. parms->volatile_fid = cfile->fid.volatile_fid;
  545. return SMB2_write(xid, parms, written, iov, nr_segs);
  546. }
  547. static int
  548. smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
  549. struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
  550. {
  551. __le64 eof = cpu_to_le64(size);
  552. return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
  553. cfile->fid.volatile_fid, cfile->pid, &eof);
  554. }
  555. static int
  556. smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
  557. struct cifsFileInfo *cfile)
  558. {
  559. return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
  560. cfile->fid.volatile_fid);
  561. }
  562. static int
  563. smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
  564. const char *path, struct cifs_sb_info *cifs_sb,
  565. struct cifs_fid *fid, __u16 search_flags,
  566. struct cifs_search_info *srch_inf)
  567. {
  568. __le16 *utf16_path;
  569. int rc;
  570. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  571. struct cifs_open_parms oparms;
  572. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  573. if (!utf16_path)
  574. return -ENOMEM;
  575. oparms.tcon = tcon;
  576. oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
  577. oparms.disposition = FILE_OPEN;
  578. oparms.create_options = 0;
  579. oparms.fid = fid;
  580. oparms.reconnect = false;
  581. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  582. kfree(utf16_path);
  583. if (rc) {
  584. cifs_dbg(VFS, "open dir failed\n");
  585. return rc;
  586. }
  587. srch_inf->entries_in_buffer = 0;
  588. srch_inf->index_of_last_entry = 0;
  589. rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
  590. fid->volatile_fid, 0, srch_inf);
  591. if (rc) {
  592. cifs_dbg(VFS, "query directory failed\n");
  593. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  594. }
  595. return rc;
  596. }
  597. static int
  598. smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
  599. struct cifs_fid *fid, __u16 search_flags,
  600. struct cifs_search_info *srch_inf)
  601. {
  602. return SMB2_query_directory(xid, tcon, fid->persistent_fid,
  603. fid->volatile_fid, 0, srch_inf);
  604. }
  605. static int
  606. smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
  607. struct cifs_fid *fid)
  608. {
  609. return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  610. }
  611. /*
  612. * If we negotiate SMB2 protocol and get STATUS_PENDING - update
  613. * the number of credits and return true. Otherwise - return false.
  614. */
  615. static bool
  616. smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
  617. {
  618. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  619. if (hdr->Status != STATUS_PENDING)
  620. return false;
  621. if (!length) {
  622. spin_lock(&server->req_lock);
  623. server->credits += le16_to_cpu(hdr->CreditRequest);
  624. spin_unlock(&server->req_lock);
  625. wake_up(&server->request_q);
  626. }
  627. return true;
  628. }
  629. static int
  630. smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
  631. struct cifsInodeInfo *cinode)
  632. {
  633. if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
  634. return SMB2_lease_break(0, tcon, cinode->lease_key,
  635. smb2_get_lease_state(cinode));
  636. return SMB2_oplock_break(0, tcon, fid->persistent_fid,
  637. fid->volatile_fid,
  638. CIFS_CACHE_READ(cinode) ? 1 : 0);
  639. }
  640. static int
  641. smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
  642. struct kstatfs *buf)
  643. {
  644. int rc;
  645. __le16 srch_path = 0; /* Null - open root of share */
  646. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  647. struct cifs_open_parms oparms;
  648. struct cifs_fid fid;
  649. oparms.tcon = tcon;
  650. oparms.desired_access = FILE_READ_ATTRIBUTES;
  651. oparms.disposition = FILE_OPEN;
  652. oparms.create_options = 0;
  653. oparms.fid = &fid;
  654. oparms.reconnect = false;
  655. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  656. if (rc)
  657. return rc;
  658. buf->f_type = SMB2_MAGIC_NUMBER;
  659. rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  660. buf);
  661. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  662. return rc;
  663. }
  664. static bool
  665. smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  666. {
  667. return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
  668. ob1->fid.volatile_fid == ob2->fid.volatile_fid;
  669. }
  670. static int
  671. smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
  672. __u64 length, __u32 type, int lock, int unlock, bool wait)
  673. {
  674. if (unlock && !lock)
  675. type = SMB2_LOCKFLAG_UNLOCK;
  676. return SMB2_lock(xid, tlink_tcon(cfile->tlink),
  677. cfile->fid.persistent_fid, cfile->fid.volatile_fid,
  678. current->tgid, length, offset, type, wait);
  679. }
  680. static void
  681. smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
  682. {
  683. memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
  684. }
  685. static void
  686. smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
  687. {
  688. memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
  689. }
  690. static void
  691. smb2_new_lease_key(struct cifs_fid *fid)
  692. {
  693. get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
  694. }
  695. static int
  696. smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
  697. const char *full_path, char **target_path,
  698. struct cifs_sb_info *cifs_sb)
  699. {
  700. int rc;
  701. __le16 *utf16_path;
  702. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  703. struct cifs_open_parms oparms;
  704. struct cifs_fid fid;
  705. struct smb2_err_rsp *err_buf = NULL;
  706. struct smb2_symlink_err_rsp *symlink;
  707. unsigned int sub_len, sub_offset;
  708. cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
  709. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  710. if (!utf16_path)
  711. return -ENOMEM;
  712. oparms.tcon = tcon;
  713. oparms.desired_access = FILE_READ_ATTRIBUTES;
  714. oparms.disposition = FILE_OPEN;
  715. oparms.create_options = 0;
  716. oparms.fid = &fid;
  717. oparms.reconnect = false;
  718. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
  719. if (!rc || !err_buf) {
  720. kfree(utf16_path);
  721. return -ENOENT;
  722. }
  723. /* open must fail on symlink - reset rc */
  724. rc = 0;
  725. symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
  726. sub_len = le16_to_cpu(symlink->SubstituteNameLength);
  727. sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
  728. *target_path = cifs_strndup_from_utf16(
  729. (char *)symlink->PathBuffer + sub_offset,
  730. sub_len, true, cifs_sb->local_nls);
  731. if (!(*target_path)) {
  732. kfree(utf16_path);
  733. return -ENOMEM;
  734. }
  735. convert_delimiter(*target_path, '/');
  736. cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
  737. kfree(utf16_path);
  738. return rc;
  739. }
  740. static void
  741. smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  742. unsigned int epoch, bool *purge_cache)
  743. {
  744. oplock &= 0xFF;
  745. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  746. return;
  747. if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
  748. cinode->oplock = CIFS_CACHE_RHW_FLG;
  749. cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
  750. &cinode->vfs_inode);
  751. } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
  752. cinode->oplock = CIFS_CACHE_RW_FLG;
  753. cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
  754. &cinode->vfs_inode);
  755. } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
  756. cinode->oplock = CIFS_CACHE_READ_FLG;
  757. cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
  758. &cinode->vfs_inode);
  759. } else
  760. cinode->oplock = 0;
  761. }
  762. static void
  763. smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  764. unsigned int epoch, bool *purge_cache)
  765. {
  766. char message[5] = {0};
  767. oplock &= 0xFF;
  768. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  769. return;
  770. cinode->oplock = 0;
  771. if (oplock & SMB2_LEASE_READ_CACHING_HE) {
  772. cinode->oplock |= CIFS_CACHE_READ_FLG;
  773. strcat(message, "R");
  774. }
  775. if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
  776. cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
  777. strcat(message, "H");
  778. }
  779. if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
  780. cinode->oplock |= CIFS_CACHE_WRITE_FLG;
  781. strcat(message, "W");
  782. }
  783. if (!cinode->oplock)
  784. strcat(message, "None");
  785. cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
  786. &cinode->vfs_inode);
  787. }
  788. static void
  789. smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  790. unsigned int epoch, bool *purge_cache)
  791. {
  792. unsigned int old_oplock = cinode->oplock;
  793. smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
  794. if (purge_cache) {
  795. *purge_cache = false;
  796. if (old_oplock == CIFS_CACHE_READ_FLG) {
  797. if (cinode->oplock == CIFS_CACHE_READ_FLG &&
  798. (epoch - cinode->epoch > 0))
  799. *purge_cache = true;
  800. else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  801. (epoch - cinode->epoch > 1))
  802. *purge_cache = true;
  803. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  804. (epoch - cinode->epoch > 1))
  805. *purge_cache = true;
  806. else if (cinode->oplock == 0 &&
  807. (epoch - cinode->epoch > 0))
  808. *purge_cache = true;
  809. } else if (old_oplock == CIFS_CACHE_RH_FLG) {
  810. if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  811. (epoch - cinode->epoch > 0))
  812. *purge_cache = true;
  813. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  814. (epoch - cinode->epoch > 1))
  815. *purge_cache = true;
  816. }
  817. cinode->epoch = epoch;
  818. }
  819. }
  820. static bool
  821. smb2_is_read_op(__u32 oplock)
  822. {
  823. return oplock == SMB2_OPLOCK_LEVEL_II;
  824. }
  825. static bool
  826. smb21_is_read_op(__u32 oplock)
  827. {
  828. return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
  829. !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
  830. }
  831. static __le32
  832. map_oplock_to_lease(u8 oplock)
  833. {
  834. if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
  835. return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
  836. else if (oplock == SMB2_OPLOCK_LEVEL_II)
  837. return SMB2_LEASE_READ_CACHING;
  838. else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
  839. return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
  840. SMB2_LEASE_WRITE_CACHING;
  841. return 0;
  842. }
  843. static char *
  844. smb2_create_lease_buf(u8 *lease_key, u8 oplock)
  845. {
  846. struct create_lease *buf;
  847. buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
  848. if (!buf)
  849. return NULL;
  850. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  851. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  852. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  853. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  854. (struct create_lease, lcontext));
  855. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
  856. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  857. (struct create_lease, Name));
  858. buf->ccontext.NameLength = cpu_to_le16(4);
  859. buf->Name[0] = 'R';
  860. buf->Name[1] = 'q';
  861. buf->Name[2] = 'L';
  862. buf->Name[3] = 's';
  863. return (char *)buf;
  864. }
  865. static char *
  866. smb3_create_lease_buf(u8 *lease_key, u8 oplock)
  867. {
  868. struct create_lease_v2 *buf;
  869. buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
  870. if (!buf)
  871. return NULL;
  872. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  873. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  874. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  875. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  876. (struct create_lease_v2, lcontext));
  877. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
  878. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  879. (struct create_lease_v2, Name));
  880. buf->ccontext.NameLength = cpu_to_le16(4);
  881. buf->Name[0] = 'R';
  882. buf->Name[1] = 'q';
  883. buf->Name[2] = 'L';
  884. buf->Name[3] = 's';
  885. return (char *)buf;
  886. }
  887. static __u8
  888. smb2_parse_lease_buf(void *buf, unsigned int *epoch)
  889. {
  890. struct create_lease *lc = (struct create_lease *)buf;
  891. *epoch = 0; /* not used */
  892. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  893. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  894. return le32_to_cpu(lc->lcontext.LeaseState);
  895. }
  896. static __u8
  897. smb3_parse_lease_buf(void *buf, unsigned int *epoch)
  898. {
  899. struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
  900. *epoch = le16_to_cpu(lc->lcontext.Epoch);
  901. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  902. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  903. return le32_to_cpu(lc->lcontext.LeaseState);
  904. }
  905. struct smb_version_operations smb20_operations = {
  906. .compare_fids = smb2_compare_fids,
  907. .setup_request = smb2_setup_request,
  908. .setup_async_request = smb2_setup_async_request,
  909. .check_receive = smb2_check_receive,
  910. .add_credits = smb2_add_credits,
  911. .set_credits = smb2_set_credits,
  912. .get_credits_field = smb2_get_credits_field,
  913. .get_credits = smb2_get_credits,
  914. .get_next_mid = smb2_get_next_mid,
  915. .read_data_offset = smb2_read_data_offset,
  916. .read_data_length = smb2_read_data_length,
  917. .map_error = map_smb2_to_linux_error,
  918. .find_mid = smb2_find_mid,
  919. .check_message = smb2_check_message,
  920. .dump_detail = smb2_dump_detail,
  921. .clear_stats = smb2_clear_stats,
  922. .print_stats = smb2_print_stats,
  923. .is_oplock_break = smb2_is_valid_oplock_break,
  924. .need_neg = smb2_need_neg,
  925. .negotiate = smb2_negotiate,
  926. .negotiate_wsize = smb2_negotiate_wsize,
  927. .negotiate_rsize = smb2_negotiate_rsize,
  928. .sess_setup = SMB2_sess_setup,
  929. .logoff = SMB2_logoff,
  930. .tree_connect = SMB2_tcon,
  931. .tree_disconnect = SMB2_tdis,
  932. .qfs_tcon = smb2_qfs_tcon,
  933. .is_path_accessible = smb2_is_path_accessible,
  934. .can_echo = smb2_can_echo,
  935. .echo = SMB2_echo,
  936. .query_path_info = smb2_query_path_info,
  937. .get_srv_inum = smb2_get_srv_inum,
  938. .query_file_info = smb2_query_file_info,
  939. .set_path_size = smb2_set_path_size,
  940. .set_file_size = smb2_set_file_size,
  941. .set_file_info = smb2_set_file_info,
  942. .set_compression = smb2_set_compression,
  943. .mkdir = smb2_mkdir,
  944. .mkdir_setinfo = smb2_mkdir_setinfo,
  945. .rmdir = smb2_rmdir,
  946. .unlink = smb2_unlink,
  947. .rename = smb2_rename_path,
  948. .create_hardlink = smb2_create_hardlink,
  949. .query_symlink = smb2_query_symlink,
  950. .open = smb2_open_file,
  951. .set_fid = smb2_set_fid,
  952. .close = smb2_close_file,
  953. .flush = smb2_flush_file,
  954. .async_readv = smb2_async_readv,
  955. .async_writev = smb2_async_writev,
  956. .sync_read = smb2_sync_read,
  957. .sync_write = smb2_sync_write,
  958. .query_dir_first = smb2_query_dir_first,
  959. .query_dir_next = smb2_query_dir_next,
  960. .close_dir = smb2_close_dir,
  961. .calc_smb_size = smb2_calc_size,
  962. .is_status_pending = smb2_is_status_pending,
  963. .oplock_response = smb2_oplock_response,
  964. .queryfs = smb2_queryfs,
  965. .mand_lock = smb2_mand_lock,
  966. .mand_unlock_range = smb2_unlock_range,
  967. .push_mand_locks = smb2_push_mandatory_locks,
  968. .get_lease_key = smb2_get_lease_key,
  969. .set_lease_key = smb2_set_lease_key,
  970. .new_lease_key = smb2_new_lease_key,
  971. .calc_signature = smb2_calc_signature,
  972. .is_read_op = smb2_is_read_op,
  973. .set_oplock_level = smb2_set_oplock_level,
  974. .create_lease_buf = smb2_create_lease_buf,
  975. .parse_lease_buf = smb2_parse_lease_buf,
  976. .clone_range = smb2_clone_range,
  977. };
  978. struct smb_version_operations smb21_operations = {
  979. .compare_fids = smb2_compare_fids,
  980. .setup_request = smb2_setup_request,
  981. .setup_async_request = smb2_setup_async_request,
  982. .check_receive = smb2_check_receive,
  983. .add_credits = smb2_add_credits,
  984. .set_credits = smb2_set_credits,
  985. .get_credits_field = smb2_get_credits_field,
  986. .get_credits = smb2_get_credits,
  987. .get_next_mid = smb2_get_next_mid,
  988. .read_data_offset = smb2_read_data_offset,
  989. .read_data_length = smb2_read_data_length,
  990. .map_error = map_smb2_to_linux_error,
  991. .find_mid = smb2_find_mid,
  992. .check_message = smb2_check_message,
  993. .dump_detail = smb2_dump_detail,
  994. .clear_stats = smb2_clear_stats,
  995. .print_stats = smb2_print_stats,
  996. .is_oplock_break = smb2_is_valid_oplock_break,
  997. .need_neg = smb2_need_neg,
  998. .negotiate = smb2_negotiate,
  999. .negotiate_wsize = smb2_negotiate_wsize,
  1000. .negotiate_rsize = smb2_negotiate_rsize,
  1001. .sess_setup = SMB2_sess_setup,
  1002. .logoff = SMB2_logoff,
  1003. .tree_connect = SMB2_tcon,
  1004. .tree_disconnect = SMB2_tdis,
  1005. .qfs_tcon = smb2_qfs_tcon,
  1006. .is_path_accessible = smb2_is_path_accessible,
  1007. .can_echo = smb2_can_echo,
  1008. .echo = SMB2_echo,
  1009. .query_path_info = smb2_query_path_info,
  1010. .get_srv_inum = smb2_get_srv_inum,
  1011. .query_file_info = smb2_query_file_info,
  1012. .set_path_size = smb2_set_path_size,
  1013. .set_file_size = smb2_set_file_size,
  1014. .set_file_info = smb2_set_file_info,
  1015. .set_compression = smb2_set_compression,
  1016. .mkdir = smb2_mkdir,
  1017. .mkdir_setinfo = smb2_mkdir_setinfo,
  1018. .rmdir = smb2_rmdir,
  1019. .unlink = smb2_unlink,
  1020. .rename = smb2_rename_path,
  1021. .create_hardlink = smb2_create_hardlink,
  1022. .query_symlink = smb2_query_symlink,
  1023. .open = smb2_open_file,
  1024. .set_fid = smb2_set_fid,
  1025. .close = smb2_close_file,
  1026. .flush = smb2_flush_file,
  1027. .async_readv = smb2_async_readv,
  1028. .async_writev = smb2_async_writev,
  1029. .sync_read = smb2_sync_read,
  1030. .sync_write = smb2_sync_write,
  1031. .query_dir_first = smb2_query_dir_first,
  1032. .query_dir_next = smb2_query_dir_next,
  1033. .close_dir = smb2_close_dir,
  1034. .calc_smb_size = smb2_calc_size,
  1035. .is_status_pending = smb2_is_status_pending,
  1036. .oplock_response = smb2_oplock_response,
  1037. .queryfs = smb2_queryfs,
  1038. .mand_lock = smb2_mand_lock,
  1039. .mand_unlock_range = smb2_unlock_range,
  1040. .push_mand_locks = smb2_push_mandatory_locks,
  1041. .get_lease_key = smb2_get_lease_key,
  1042. .set_lease_key = smb2_set_lease_key,
  1043. .new_lease_key = smb2_new_lease_key,
  1044. .calc_signature = smb2_calc_signature,
  1045. .is_read_op = smb21_is_read_op,
  1046. .set_oplock_level = smb21_set_oplock_level,
  1047. .create_lease_buf = smb2_create_lease_buf,
  1048. .parse_lease_buf = smb2_parse_lease_buf,
  1049. .clone_range = smb2_clone_range,
  1050. };
  1051. struct smb_version_operations smb30_operations = {
  1052. .compare_fids = smb2_compare_fids,
  1053. .setup_request = smb2_setup_request,
  1054. .setup_async_request = smb2_setup_async_request,
  1055. .check_receive = smb2_check_receive,
  1056. .add_credits = smb2_add_credits,
  1057. .set_credits = smb2_set_credits,
  1058. .get_credits_field = smb2_get_credits_field,
  1059. .get_credits = smb2_get_credits,
  1060. .get_next_mid = smb2_get_next_mid,
  1061. .read_data_offset = smb2_read_data_offset,
  1062. .read_data_length = smb2_read_data_length,
  1063. .map_error = map_smb2_to_linux_error,
  1064. .find_mid = smb2_find_mid,
  1065. .check_message = smb2_check_message,
  1066. .dump_detail = smb2_dump_detail,
  1067. .clear_stats = smb2_clear_stats,
  1068. .print_stats = smb2_print_stats,
  1069. .dump_share_caps = smb2_dump_share_caps,
  1070. .is_oplock_break = smb2_is_valid_oplock_break,
  1071. .need_neg = smb2_need_neg,
  1072. .negotiate = smb2_negotiate,
  1073. .negotiate_wsize = smb2_negotiate_wsize,
  1074. .negotiate_rsize = smb2_negotiate_rsize,
  1075. .sess_setup = SMB2_sess_setup,
  1076. .logoff = SMB2_logoff,
  1077. .tree_connect = SMB2_tcon,
  1078. .tree_disconnect = SMB2_tdis,
  1079. .qfs_tcon = smb3_qfs_tcon,
  1080. .is_path_accessible = smb2_is_path_accessible,
  1081. .can_echo = smb2_can_echo,
  1082. .echo = SMB2_echo,
  1083. .query_path_info = smb2_query_path_info,
  1084. .get_srv_inum = smb2_get_srv_inum,
  1085. .query_file_info = smb2_query_file_info,
  1086. .set_path_size = smb2_set_path_size,
  1087. .set_file_size = smb2_set_file_size,
  1088. .set_file_info = smb2_set_file_info,
  1089. .set_compression = smb2_set_compression,
  1090. .mkdir = smb2_mkdir,
  1091. .mkdir_setinfo = smb2_mkdir_setinfo,
  1092. .rmdir = smb2_rmdir,
  1093. .unlink = smb2_unlink,
  1094. .rename = smb2_rename_path,
  1095. .create_hardlink = smb2_create_hardlink,
  1096. .query_symlink = smb2_query_symlink,
  1097. .open = smb2_open_file,
  1098. .set_fid = smb2_set_fid,
  1099. .close = smb2_close_file,
  1100. .flush = smb2_flush_file,
  1101. .async_readv = smb2_async_readv,
  1102. .async_writev = smb2_async_writev,
  1103. .sync_read = smb2_sync_read,
  1104. .sync_write = smb2_sync_write,
  1105. .query_dir_first = smb2_query_dir_first,
  1106. .query_dir_next = smb2_query_dir_next,
  1107. .close_dir = smb2_close_dir,
  1108. .calc_smb_size = smb2_calc_size,
  1109. .is_status_pending = smb2_is_status_pending,
  1110. .oplock_response = smb2_oplock_response,
  1111. .queryfs = smb2_queryfs,
  1112. .mand_lock = smb2_mand_lock,
  1113. .mand_unlock_range = smb2_unlock_range,
  1114. .push_mand_locks = smb2_push_mandatory_locks,
  1115. .get_lease_key = smb2_get_lease_key,
  1116. .set_lease_key = smb2_set_lease_key,
  1117. .new_lease_key = smb2_new_lease_key,
  1118. .generate_signingkey = generate_smb3signingkey,
  1119. .calc_signature = smb3_calc_signature,
  1120. .is_read_op = smb21_is_read_op,
  1121. .set_oplock_level = smb3_set_oplock_level,
  1122. .create_lease_buf = smb3_create_lease_buf,
  1123. .parse_lease_buf = smb3_parse_lease_buf,
  1124. .clone_range = smb2_clone_range,
  1125. };
  1126. struct smb_version_values smb20_values = {
  1127. .version_string = SMB20_VERSION_STRING,
  1128. .protocol_id = SMB20_PROT_ID,
  1129. .req_capabilities = 0, /* MBZ */
  1130. .large_lock_type = 0,
  1131. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1132. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1133. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1134. .header_size = sizeof(struct smb2_hdr),
  1135. .max_header_size = MAX_SMB2_HDR_SIZE,
  1136. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1137. .lock_cmd = SMB2_LOCK,
  1138. .cap_unix = 0,
  1139. .cap_nt_find = SMB2_NT_FIND,
  1140. .cap_large_files = SMB2_LARGE_FILES,
  1141. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1142. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1143. .create_lease_size = sizeof(struct create_lease),
  1144. };
  1145. struct smb_version_values smb21_values = {
  1146. .version_string = SMB21_VERSION_STRING,
  1147. .protocol_id = SMB21_PROT_ID,
  1148. .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
  1149. .large_lock_type = 0,
  1150. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1151. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1152. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1153. .header_size = sizeof(struct smb2_hdr),
  1154. .max_header_size = MAX_SMB2_HDR_SIZE,
  1155. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1156. .lock_cmd = SMB2_LOCK,
  1157. .cap_unix = 0,
  1158. .cap_nt_find = SMB2_NT_FIND,
  1159. .cap_large_files = SMB2_LARGE_FILES,
  1160. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1161. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1162. .create_lease_size = sizeof(struct create_lease),
  1163. };
  1164. struct smb_version_values smb30_values = {
  1165. .version_string = SMB30_VERSION_STRING,
  1166. .protocol_id = SMB30_PROT_ID,
  1167. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1168. .large_lock_type = 0,
  1169. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1170. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1171. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1172. .header_size = sizeof(struct smb2_hdr),
  1173. .max_header_size = MAX_SMB2_HDR_SIZE,
  1174. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1175. .lock_cmd = SMB2_LOCK,
  1176. .cap_unix = 0,
  1177. .cap_nt_find = SMB2_NT_FIND,
  1178. .cap_large_files = SMB2_LARGE_FILES,
  1179. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1180. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1181. .create_lease_size = sizeof(struct create_lease_v2),
  1182. };
  1183. struct smb_version_values smb302_values = {
  1184. .version_string = SMB302_VERSION_STRING,
  1185. .protocol_id = SMB302_PROT_ID,
  1186. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1187. .large_lock_type = 0,
  1188. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1189. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1190. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1191. .header_size = sizeof(struct smb2_hdr),
  1192. .max_header_size = MAX_SMB2_HDR_SIZE,
  1193. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1194. .lock_cmd = SMB2_LOCK,
  1195. .cap_unix = 0,
  1196. .cap_nt_find = SMB2_NT_FIND,
  1197. .cap_large_files = SMB2_LARGE_FILES,
  1198. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1199. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1200. .create_lease_size = sizeof(struct create_lease_v2),
  1201. };