smb2ops.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  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_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
  448. struct cifs_fid *fid)
  449. {
  450. return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  451. }
  452. static unsigned int
  453. smb2_read_data_offset(char *buf)
  454. {
  455. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  456. return rsp->DataOffset;
  457. }
  458. static unsigned int
  459. smb2_read_data_length(char *buf)
  460. {
  461. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  462. return le32_to_cpu(rsp->DataLength);
  463. }
  464. static int
  465. smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
  466. struct cifs_io_parms *parms, unsigned int *bytes_read,
  467. char **buf, int *buf_type)
  468. {
  469. parms->persistent_fid = cfile->fid.persistent_fid;
  470. parms->volatile_fid = cfile->fid.volatile_fid;
  471. return SMB2_read(xid, parms, bytes_read, buf, buf_type);
  472. }
  473. static int
  474. smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
  475. struct cifs_io_parms *parms, unsigned int *written,
  476. struct kvec *iov, unsigned long nr_segs)
  477. {
  478. parms->persistent_fid = cfile->fid.persistent_fid;
  479. parms->volatile_fid = cfile->fid.volatile_fid;
  480. return SMB2_write(xid, parms, written, iov, nr_segs);
  481. }
  482. static int
  483. smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
  484. struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
  485. {
  486. __le64 eof = cpu_to_le64(size);
  487. return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
  488. cfile->fid.volatile_fid, cfile->pid, &eof);
  489. }
  490. static int
  491. smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
  492. struct cifsFileInfo *cfile)
  493. {
  494. return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
  495. cfile->fid.volatile_fid);
  496. }
  497. static int
  498. smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
  499. const char *path, struct cifs_sb_info *cifs_sb,
  500. struct cifs_fid *fid, __u16 search_flags,
  501. struct cifs_search_info *srch_inf)
  502. {
  503. __le16 *utf16_path;
  504. int rc;
  505. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  506. struct cifs_open_parms oparms;
  507. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  508. if (!utf16_path)
  509. return -ENOMEM;
  510. oparms.tcon = tcon;
  511. oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
  512. oparms.disposition = FILE_OPEN;
  513. oparms.create_options = 0;
  514. oparms.fid = fid;
  515. oparms.reconnect = false;
  516. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  517. kfree(utf16_path);
  518. if (rc) {
  519. cifs_dbg(VFS, "open dir failed\n");
  520. return rc;
  521. }
  522. srch_inf->entries_in_buffer = 0;
  523. srch_inf->index_of_last_entry = 0;
  524. rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
  525. fid->volatile_fid, 0, srch_inf);
  526. if (rc) {
  527. cifs_dbg(VFS, "query directory failed\n");
  528. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  529. }
  530. return rc;
  531. }
  532. static int
  533. smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
  534. struct cifs_fid *fid, __u16 search_flags,
  535. struct cifs_search_info *srch_inf)
  536. {
  537. return SMB2_query_directory(xid, tcon, fid->persistent_fid,
  538. fid->volatile_fid, 0, srch_inf);
  539. }
  540. static int
  541. smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
  542. struct cifs_fid *fid)
  543. {
  544. return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  545. }
  546. /*
  547. * If we negotiate SMB2 protocol and get STATUS_PENDING - update
  548. * the number of credits and return true. Otherwise - return false.
  549. */
  550. static bool
  551. smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
  552. {
  553. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  554. if (hdr->Status != STATUS_PENDING)
  555. return false;
  556. if (!length) {
  557. spin_lock(&server->req_lock);
  558. server->credits += le16_to_cpu(hdr->CreditRequest);
  559. spin_unlock(&server->req_lock);
  560. wake_up(&server->request_q);
  561. }
  562. return true;
  563. }
  564. static int
  565. smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
  566. struct cifsInodeInfo *cinode)
  567. {
  568. if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
  569. return SMB2_lease_break(0, tcon, cinode->lease_key,
  570. smb2_get_lease_state(cinode));
  571. return SMB2_oplock_break(0, tcon, fid->persistent_fid,
  572. fid->volatile_fid,
  573. CIFS_CACHE_READ(cinode) ? 1 : 0);
  574. }
  575. static int
  576. smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
  577. struct kstatfs *buf)
  578. {
  579. int rc;
  580. __le16 srch_path = 0; /* Null - open root of share */
  581. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  582. struct cifs_open_parms oparms;
  583. struct cifs_fid fid;
  584. oparms.tcon = tcon;
  585. oparms.desired_access = FILE_READ_ATTRIBUTES;
  586. oparms.disposition = FILE_OPEN;
  587. oparms.create_options = 0;
  588. oparms.fid = &fid;
  589. oparms.reconnect = false;
  590. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  591. if (rc)
  592. return rc;
  593. buf->f_type = SMB2_MAGIC_NUMBER;
  594. rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  595. buf);
  596. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  597. return rc;
  598. }
  599. static bool
  600. smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  601. {
  602. return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
  603. ob1->fid.volatile_fid == ob2->fid.volatile_fid;
  604. }
  605. static int
  606. smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
  607. __u64 length, __u32 type, int lock, int unlock, bool wait)
  608. {
  609. if (unlock && !lock)
  610. type = SMB2_LOCKFLAG_UNLOCK;
  611. return SMB2_lock(xid, tlink_tcon(cfile->tlink),
  612. cfile->fid.persistent_fid, cfile->fid.volatile_fid,
  613. current->tgid, length, offset, type, wait);
  614. }
  615. static void
  616. smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
  617. {
  618. memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
  619. }
  620. static void
  621. smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
  622. {
  623. memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
  624. }
  625. static void
  626. smb2_new_lease_key(struct cifs_fid *fid)
  627. {
  628. get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
  629. }
  630. static int
  631. smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
  632. const char *full_path, char **target_path,
  633. struct cifs_sb_info *cifs_sb)
  634. {
  635. int rc;
  636. __le16 *utf16_path;
  637. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  638. struct cifs_open_parms oparms;
  639. struct cifs_fid fid;
  640. struct smb2_err_rsp *err_buf = NULL;
  641. struct smb2_symlink_err_rsp *symlink;
  642. unsigned int sub_len, sub_offset;
  643. cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
  644. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  645. if (!utf16_path)
  646. return -ENOMEM;
  647. oparms.tcon = tcon;
  648. oparms.desired_access = FILE_READ_ATTRIBUTES;
  649. oparms.disposition = FILE_OPEN;
  650. oparms.create_options = 0;
  651. oparms.fid = &fid;
  652. oparms.reconnect = false;
  653. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
  654. if (!rc || !err_buf) {
  655. kfree(utf16_path);
  656. return -ENOENT;
  657. }
  658. /* open must fail on symlink - reset rc */
  659. rc = 0;
  660. symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
  661. sub_len = le16_to_cpu(symlink->SubstituteNameLength);
  662. sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
  663. *target_path = cifs_strndup_from_utf16(
  664. (char *)symlink->PathBuffer + sub_offset,
  665. sub_len, true, cifs_sb->local_nls);
  666. if (!(*target_path)) {
  667. kfree(utf16_path);
  668. return -ENOMEM;
  669. }
  670. convert_delimiter(*target_path, '/');
  671. cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
  672. kfree(utf16_path);
  673. return rc;
  674. }
  675. static void
  676. smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  677. unsigned int epoch, bool *purge_cache)
  678. {
  679. oplock &= 0xFF;
  680. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  681. return;
  682. if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
  683. cinode->oplock = CIFS_CACHE_RHW_FLG;
  684. cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
  685. &cinode->vfs_inode);
  686. } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
  687. cinode->oplock = CIFS_CACHE_RW_FLG;
  688. cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
  689. &cinode->vfs_inode);
  690. } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
  691. cinode->oplock = CIFS_CACHE_READ_FLG;
  692. cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
  693. &cinode->vfs_inode);
  694. } else
  695. cinode->oplock = 0;
  696. }
  697. static void
  698. smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  699. unsigned int epoch, bool *purge_cache)
  700. {
  701. char message[5] = {0};
  702. oplock &= 0xFF;
  703. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  704. return;
  705. cinode->oplock = 0;
  706. if (oplock & SMB2_LEASE_READ_CACHING_HE) {
  707. cinode->oplock |= CIFS_CACHE_READ_FLG;
  708. strcat(message, "R");
  709. }
  710. if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
  711. cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
  712. strcat(message, "H");
  713. }
  714. if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
  715. cinode->oplock |= CIFS_CACHE_WRITE_FLG;
  716. strcat(message, "W");
  717. }
  718. if (!cinode->oplock)
  719. strcat(message, "None");
  720. cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
  721. &cinode->vfs_inode);
  722. }
  723. static void
  724. smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  725. unsigned int epoch, bool *purge_cache)
  726. {
  727. unsigned int old_oplock = cinode->oplock;
  728. smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
  729. if (purge_cache) {
  730. *purge_cache = false;
  731. if (old_oplock == CIFS_CACHE_READ_FLG) {
  732. if (cinode->oplock == CIFS_CACHE_READ_FLG &&
  733. (epoch - cinode->epoch > 0))
  734. *purge_cache = true;
  735. else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  736. (epoch - cinode->epoch > 1))
  737. *purge_cache = true;
  738. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  739. (epoch - cinode->epoch > 1))
  740. *purge_cache = true;
  741. else if (cinode->oplock == 0 &&
  742. (epoch - cinode->epoch > 0))
  743. *purge_cache = true;
  744. } else if (old_oplock == CIFS_CACHE_RH_FLG) {
  745. if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  746. (epoch - cinode->epoch > 0))
  747. *purge_cache = true;
  748. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  749. (epoch - cinode->epoch > 1))
  750. *purge_cache = true;
  751. }
  752. cinode->epoch = epoch;
  753. }
  754. }
  755. static bool
  756. smb2_is_read_op(__u32 oplock)
  757. {
  758. return oplock == SMB2_OPLOCK_LEVEL_II;
  759. }
  760. static bool
  761. smb21_is_read_op(__u32 oplock)
  762. {
  763. return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
  764. !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
  765. }
  766. static __le32
  767. map_oplock_to_lease(u8 oplock)
  768. {
  769. if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
  770. return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
  771. else if (oplock == SMB2_OPLOCK_LEVEL_II)
  772. return SMB2_LEASE_READ_CACHING;
  773. else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
  774. return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
  775. SMB2_LEASE_WRITE_CACHING;
  776. return 0;
  777. }
  778. static char *
  779. smb2_create_lease_buf(u8 *lease_key, u8 oplock)
  780. {
  781. struct create_lease *buf;
  782. buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
  783. if (!buf)
  784. return NULL;
  785. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  786. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  787. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  788. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  789. (struct create_lease, lcontext));
  790. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
  791. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  792. (struct create_lease, Name));
  793. buf->ccontext.NameLength = cpu_to_le16(4);
  794. buf->Name[0] = 'R';
  795. buf->Name[1] = 'q';
  796. buf->Name[2] = 'L';
  797. buf->Name[3] = 's';
  798. return (char *)buf;
  799. }
  800. static char *
  801. smb3_create_lease_buf(u8 *lease_key, u8 oplock)
  802. {
  803. struct create_lease_v2 *buf;
  804. buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
  805. if (!buf)
  806. return NULL;
  807. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  808. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  809. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  810. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  811. (struct create_lease_v2, lcontext));
  812. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
  813. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  814. (struct create_lease_v2, Name));
  815. buf->ccontext.NameLength = cpu_to_le16(4);
  816. buf->Name[0] = 'R';
  817. buf->Name[1] = 'q';
  818. buf->Name[2] = 'L';
  819. buf->Name[3] = 's';
  820. return (char *)buf;
  821. }
  822. static __u8
  823. smb2_parse_lease_buf(void *buf, unsigned int *epoch)
  824. {
  825. struct create_lease *lc = (struct create_lease *)buf;
  826. *epoch = 0; /* not used */
  827. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  828. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  829. return le32_to_cpu(lc->lcontext.LeaseState);
  830. }
  831. static __u8
  832. smb3_parse_lease_buf(void *buf, unsigned int *epoch)
  833. {
  834. struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
  835. *epoch = le16_to_cpu(lc->lcontext.Epoch);
  836. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  837. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  838. return le32_to_cpu(lc->lcontext.LeaseState);
  839. }
  840. struct smb_version_operations smb20_operations = {
  841. .compare_fids = smb2_compare_fids,
  842. .setup_request = smb2_setup_request,
  843. .setup_async_request = smb2_setup_async_request,
  844. .check_receive = smb2_check_receive,
  845. .add_credits = smb2_add_credits,
  846. .set_credits = smb2_set_credits,
  847. .get_credits_field = smb2_get_credits_field,
  848. .get_credits = smb2_get_credits,
  849. .get_next_mid = smb2_get_next_mid,
  850. .read_data_offset = smb2_read_data_offset,
  851. .read_data_length = smb2_read_data_length,
  852. .map_error = map_smb2_to_linux_error,
  853. .find_mid = smb2_find_mid,
  854. .check_message = smb2_check_message,
  855. .dump_detail = smb2_dump_detail,
  856. .clear_stats = smb2_clear_stats,
  857. .print_stats = smb2_print_stats,
  858. .is_oplock_break = smb2_is_valid_oplock_break,
  859. .need_neg = smb2_need_neg,
  860. .negotiate = smb2_negotiate,
  861. .negotiate_wsize = smb2_negotiate_wsize,
  862. .negotiate_rsize = smb2_negotiate_rsize,
  863. .sess_setup = SMB2_sess_setup,
  864. .logoff = SMB2_logoff,
  865. .tree_connect = SMB2_tcon,
  866. .tree_disconnect = SMB2_tdis,
  867. .qfs_tcon = smb2_qfs_tcon,
  868. .is_path_accessible = smb2_is_path_accessible,
  869. .can_echo = smb2_can_echo,
  870. .echo = SMB2_echo,
  871. .query_path_info = smb2_query_path_info,
  872. .get_srv_inum = smb2_get_srv_inum,
  873. .query_file_info = smb2_query_file_info,
  874. .set_path_size = smb2_set_path_size,
  875. .set_file_size = smb2_set_file_size,
  876. .set_file_info = smb2_set_file_info,
  877. .set_compression = smb2_set_compression,
  878. .mkdir = smb2_mkdir,
  879. .mkdir_setinfo = smb2_mkdir_setinfo,
  880. .rmdir = smb2_rmdir,
  881. .unlink = smb2_unlink,
  882. .rename = smb2_rename_path,
  883. .create_hardlink = smb2_create_hardlink,
  884. .query_symlink = smb2_query_symlink,
  885. .open = smb2_open_file,
  886. .set_fid = smb2_set_fid,
  887. .close = smb2_close_file,
  888. .flush = smb2_flush_file,
  889. .async_readv = smb2_async_readv,
  890. .async_writev = smb2_async_writev,
  891. .sync_read = smb2_sync_read,
  892. .sync_write = smb2_sync_write,
  893. .query_dir_first = smb2_query_dir_first,
  894. .query_dir_next = smb2_query_dir_next,
  895. .close_dir = smb2_close_dir,
  896. .calc_smb_size = smb2_calc_size,
  897. .is_status_pending = smb2_is_status_pending,
  898. .oplock_response = smb2_oplock_response,
  899. .queryfs = smb2_queryfs,
  900. .mand_lock = smb2_mand_lock,
  901. .mand_unlock_range = smb2_unlock_range,
  902. .push_mand_locks = smb2_push_mandatory_locks,
  903. .get_lease_key = smb2_get_lease_key,
  904. .set_lease_key = smb2_set_lease_key,
  905. .new_lease_key = smb2_new_lease_key,
  906. .calc_signature = smb2_calc_signature,
  907. .is_read_op = smb2_is_read_op,
  908. .set_oplock_level = smb2_set_oplock_level,
  909. .create_lease_buf = smb2_create_lease_buf,
  910. .parse_lease_buf = smb2_parse_lease_buf,
  911. };
  912. struct smb_version_operations smb21_operations = {
  913. .compare_fids = smb2_compare_fids,
  914. .setup_request = smb2_setup_request,
  915. .setup_async_request = smb2_setup_async_request,
  916. .check_receive = smb2_check_receive,
  917. .add_credits = smb2_add_credits,
  918. .set_credits = smb2_set_credits,
  919. .get_credits_field = smb2_get_credits_field,
  920. .get_credits = smb2_get_credits,
  921. .get_next_mid = smb2_get_next_mid,
  922. .read_data_offset = smb2_read_data_offset,
  923. .read_data_length = smb2_read_data_length,
  924. .map_error = map_smb2_to_linux_error,
  925. .find_mid = smb2_find_mid,
  926. .check_message = smb2_check_message,
  927. .dump_detail = smb2_dump_detail,
  928. .clear_stats = smb2_clear_stats,
  929. .print_stats = smb2_print_stats,
  930. .is_oplock_break = smb2_is_valid_oplock_break,
  931. .need_neg = smb2_need_neg,
  932. .negotiate = smb2_negotiate,
  933. .negotiate_wsize = smb2_negotiate_wsize,
  934. .negotiate_rsize = smb2_negotiate_rsize,
  935. .sess_setup = SMB2_sess_setup,
  936. .logoff = SMB2_logoff,
  937. .tree_connect = SMB2_tcon,
  938. .tree_disconnect = SMB2_tdis,
  939. .qfs_tcon = smb2_qfs_tcon,
  940. .is_path_accessible = smb2_is_path_accessible,
  941. .can_echo = smb2_can_echo,
  942. .echo = SMB2_echo,
  943. .query_path_info = smb2_query_path_info,
  944. .get_srv_inum = smb2_get_srv_inum,
  945. .query_file_info = smb2_query_file_info,
  946. .set_path_size = smb2_set_path_size,
  947. .set_file_size = smb2_set_file_size,
  948. .set_file_info = smb2_set_file_info,
  949. .set_compression = smb2_set_compression,
  950. .mkdir = smb2_mkdir,
  951. .mkdir_setinfo = smb2_mkdir_setinfo,
  952. .rmdir = smb2_rmdir,
  953. .unlink = smb2_unlink,
  954. .rename = smb2_rename_path,
  955. .create_hardlink = smb2_create_hardlink,
  956. .query_symlink = smb2_query_symlink,
  957. .open = smb2_open_file,
  958. .set_fid = smb2_set_fid,
  959. .close = smb2_close_file,
  960. .flush = smb2_flush_file,
  961. .async_readv = smb2_async_readv,
  962. .async_writev = smb2_async_writev,
  963. .sync_read = smb2_sync_read,
  964. .sync_write = smb2_sync_write,
  965. .query_dir_first = smb2_query_dir_first,
  966. .query_dir_next = smb2_query_dir_next,
  967. .close_dir = smb2_close_dir,
  968. .calc_smb_size = smb2_calc_size,
  969. .is_status_pending = smb2_is_status_pending,
  970. .oplock_response = smb2_oplock_response,
  971. .queryfs = smb2_queryfs,
  972. .mand_lock = smb2_mand_lock,
  973. .mand_unlock_range = smb2_unlock_range,
  974. .push_mand_locks = smb2_push_mandatory_locks,
  975. .get_lease_key = smb2_get_lease_key,
  976. .set_lease_key = smb2_set_lease_key,
  977. .new_lease_key = smb2_new_lease_key,
  978. .calc_signature = smb2_calc_signature,
  979. .is_read_op = smb21_is_read_op,
  980. .set_oplock_level = smb21_set_oplock_level,
  981. .create_lease_buf = smb2_create_lease_buf,
  982. .parse_lease_buf = smb2_parse_lease_buf,
  983. };
  984. struct smb_version_operations smb30_operations = {
  985. .compare_fids = smb2_compare_fids,
  986. .setup_request = smb2_setup_request,
  987. .setup_async_request = smb2_setup_async_request,
  988. .check_receive = smb2_check_receive,
  989. .add_credits = smb2_add_credits,
  990. .set_credits = smb2_set_credits,
  991. .get_credits_field = smb2_get_credits_field,
  992. .get_credits = smb2_get_credits,
  993. .get_next_mid = smb2_get_next_mid,
  994. .read_data_offset = smb2_read_data_offset,
  995. .read_data_length = smb2_read_data_length,
  996. .map_error = map_smb2_to_linux_error,
  997. .find_mid = smb2_find_mid,
  998. .check_message = smb2_check_message,
  999. .dump_detail = smb2_dump_detail,
  1000. .clear_stats = smb2_clear_stats,
  1001. .print_stats = smb2_print_stats,
  1002. .dump_share_caps = smb2_dump_share_caps,
  1003. .is_oplock_break = smb2_is_valid_oplock_break,
  1004. .need_neg = smb2_need_neg,
  1005. .negotiate = smb2_negotiate,
  1006. .negotiate_wsize = smb2_negotiate_wsize,
  1007. .negotiate_rsize = smb2_negotiate_rsize,
  1008. .sess_setup = SMB2_sess_setup,
  1009. .logoff = SMB2_logoff,
  1010. .tree_connect = SMB2_tcon,
  1011. .tree_disconnect = SMB2_tdis,
  1012. .qfs_tcon = smb3_qfs_tcon,
  1013. .is_path_accessible = smb2_is_path_accessible,
  1014. .can_echo = smb2_can_echo,
  1015. .echo = SMB2_echo,
  1016. .query_path_info = smb2_query_path_info,
  1017. .get_srv_inum = smb2_get_srv_inum,
  1018. .query_file_info = smb2_query_file_info,
  1019. .set_path_size = smb2_set_path_size,
  1020. .set_file_size = smb2_set_file_size,
  1021. .set_file_info = smb2_set_file_info,
  1022. .set_compression = smb2_set_compression,
  1023. .mkdir = smb2_mkdir,
  1024. .mkdir_setinfo = smb2_mkdir_setinfo,
  1025. .rmdir = smb2_rmdir,
  1026. .unlink = smb2_unlink,
  1027. .rename = smb2_rename_path,
  1028. .create_hardlink = smb2_create_hardlink,
  1029. .query_symlink = smb2_query_symlink,
  1030. .open = smb2_open_file,
  1031. .set_fid = smb2_set_fid,
  1032. .close = smb2_close_file,
  1033. .flush = smb2_flush_file,
  1034. .async_readv = smb2_async_readv,
  1035. .async_writev = smb2_async_writev,
  1036. .sync_read = smb2_sync_read,
  1037. .sync_write = smb2_sync_write,
  1038. .query_dir_first = smb2_query_dir_first,
  1039. .query_dir_next = smb2_query_dir_next,
  1040. .close_dir = smb2_close_dir,
  1041. .calc_smb_size = smb2_calc_size,
  1042. .is_status_pending = smb2_is_status_pending,
  1043. .oplock_response = smb2_oplock_response,
  1044. .queryfs = smb2_queryfs,
  1045. .mand_lock = smb2_mand_lock,
  1046. .mand_unlock_range = smb2_unlock_range,
  1047. .push_mand_locks = smb2_push_mandatory_locks,
  1048. .get_lease_key = smb2_get_lease_key,
  1049. .set_lease_key = smb2_set_lease_key,
  1050. .new_lease_key = smb2_new_lease_key,
  1051. .generate_signingkey = generate_smb3signingkey,
  1052. .calc_signature = smb3_calc_signature,
  1053. .is_read_op = smb21_is_read_op,
  1054. .set_oplock_level = smb3_set_oplock_level,
  1055. .create_lease_buf = smb3_create_lease_buf,
  1056. .parse_lease_buf = smb3_parse_lease_buf,
  1057. };
  1058. struct smb_version_values smb20_values = {
  1059. .version_string = SMB20_VERSION_STRING,
  1060. .protocol_id = SMB20_PROT_ID,
  1061. .req_capabilities = 0, /* MBZ */
  1062. .large_lock_type = 0,
  1063. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1064. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1065. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1066. .header_size = sizeof(struct smb2_hdr),
  1067. .max_header_size = MAX_SMB2_HDR_SIZE,
  1068. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1069. .lock_cmd = SMB2_LOCK,
  1070. .cap_unix = 0,
  1071. .cap_nt_find = SMB2_NT_FIND,
  1072. .cap_large_files = SMB2_LARGE_FILES,
  1073. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1074. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1075. .create_lease_size = sizeof(struct create_lease),
  1076. };
  1077. struct smb_version_values smb21_values = {
  1078. .version_string = SMB21_VERSION_STRING,
  1079. .protocol_id = SMB21_PROT_ID,
  1080. .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
  1081. .large_lock_type = 0,
  1082. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1083. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1084. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1085. .header_size = sizeof(struct smb2_hdr),
  1086. .max_header_size = MAX_SMB2_HDR_SIZE,
  1087. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1088. .lock_cmd = SMB2_LOCK,
  1089. .cap_unix = 0,
  1090. .cap_nt_find = SMB2_NT_FIND,
  1091. .cap_large_files = SMB2_LARGE_FILES,
  1092. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1093. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1094. .create_lease_size = sizeof(struct create_lease),
  1095. };
  1096. struct smb_version_values smb30_values = {
  1097. .version_string = SMB30_VERSION_STRING,
  1098. .protocol_id = SMB30_PROT_ID,
  1099. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1100. .large_lock_type = 0,
  1101. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1102. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1103. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1104. .header_size = sizeof(struct smb2_hdr),
  1105. .max_header_size = MAX_SMB2_HDR_SIZE,
  1106. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1107. .lock_cmd = SMB2_LOCK,
  1108. .cap_unix = 0,
  1109. .cap_nt_find = SMB2_NT_FIND,
  1110. .cap_large_files = SMB2_LARGE_FILES,
  1111. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1112. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1113. .create_lease_size = sizeof(struct create_lease_v2),
  1114. };
  1115. struct smb_version_values smb302_values = {
  1116. .version_string = SMB302_VERSION_STRING,
  1117. .protocol_id = SMB302_PROT_ID,
  1118. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1119. .large_lock_type = 0,
  1120. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1121. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1122. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1123. .header_size = sizeof(struct smb2_hdr),
  1124. .max_header_size = MAX_SMB2_HDR_SIZE,
  1125. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1126. .lock_cmd = SMB2_LOCK,
  1127. .cap_unix = 0,
  1128. .cap_nt_find = SMB2_NT_FIND,
  1129. .cap_large_files = SMB2_LARGE_FILES,
  1130. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1131. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1132. .create_lease_size = sizeof(struct create_lease_v2),
  1133. };