smb2ops.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  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. static void
  193. smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  194. {
  195. int rc;
  196. __le16 srch_path = 0; /* Null - open root of share */
  197. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  198. struct cifs_open_parms oparms;
  199. struct cifs_fid fid;
  200. oparms.tcon = tcon;
  201. oparms.desired_access = FILE_READ_ATTRIBUTES;
  202. oparms.disposition = FILE_OPEN;
  203. oparms.create_options = 0;
  204. oparms.fid = &fid;
  205. oparms.reconnect = false;
  206. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  207. if (rc)
  208. return;
  209. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  210. FS_ATTRIBUTE_INFORMATION);
  211. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  212. FS_DEVICE_INFORMATION);
  213. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  214. return;
  215. }
  216. static int
  217. smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
  218. struct cifs_sb_info *cifs_sb, const char *full_path)
  219. {
  220. int rc;
  221. __le16 *utf16_path;
  222. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  223. struct cifs_open_parms oparms;
  224. struct cifs_fid fid;
  225. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  226. if (!utf16_path)
  227. return -ENOMEM;
  228. oparms.tcon = tcon;
  229. oparms.desired_access = FILE_READ_ATTRIBUTES;
  230. oparms.disposition = FILE_OPEN;
  231. oparms.create_options = 0;
  232. oparms.fid = &fid;
  233. oparms.reconnect = false;
  234. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  235. if (rc) {
  236. kfree(utf16_path);
  237. return rc;
  238. }
  239. rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  240. kfree(utf16_path);
  241. return rc;
  242. }
  243. static int
  244. smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
  245. struct cifs_sb_info *cifs_sb, const char *full_path,
  246. u64 *uniqueid, FILE_ALL_INFO *data)
  247. {
  248. *uniqueid = le64_to_cpu(data->IndexNumber);
  249. return 0;
  250. }
  251. static int
  252. smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
  253. struct cifs_fid *fid, FILE_ALL_INFO *data)
  254. {
  255. int rc;
  256. struct smb2_file_all_info *smb2_data;
  257. smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
  258. GFP_KERNEL);
  259. if (smb2_data == NULL)
  260. return -ENOMEM;
  261. rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
  262. smb2_data);
  263. if (!rc)
  264. move_smb2_info_to_cifs(data, smb2_data);
  265. kfree(smb2_data);
  266. return rc;
  267. }
  268. static bool
  269. smb2_can_echo(struct TCP_Server_Info *server)
  270. {
  271. return server->echoes;
  272. }
  273. static void
  274. smb2_clear_stats(struct cifs_tcon *tcon)
  275. {
  276. #ifdef CONFIG_CIFS_STATS
  277. int i;
  278. for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
  279. atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
  280. atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
  281. }
  282. #endif
  283. }
  284. static void
  285. smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
  286. {
  287. seq_puts(m, "\n\tShare Capabilities:");
  288. if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
  289. seq_puts(m, " DFS,");
  290. if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
  291. seq_puts(m, " CONTINUOUS AVAILABILITY,");
  292. if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
  293. seq_puts(m, " SCALEOUT,");
  294. if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
  295. seq_puts(m, " CLUSTER,");
  296. if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
  297. seq_puts(m, " ASYMMETRIC,");
  298. if (tcon->capabilities == 0)
  299. seq_puts(m, " None");
  300. seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
  301. }
  302. static void
  303. smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
  304. {
  305. #ifdef CONFIG_CIFS_STATS
  306. atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
  307. atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
  308. seq_printf(m, "\nNegotiates: %d sent %d failed",
  309. atomic_read(&sent[SMB2_NEGOTIATE_HE]),
  310. atomic_read(&failed[SMB2_NEGOTIATE_HE]));
  311. seq_printf(m, "\nSessionSetups: %d sent %d failed",
  312. atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
  313. atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
  314. seq_printf(m, "\nLogoffs: %d sent %d failed",
  315. atomic_read(&sent[SMB2_LOGOFF_HE]),
  316. atomic_read(&failed[SMB2_LOGOFF_HE]));
  317. seq_printf(m, "\nTreeConnects: %d sent %d failed",
  318. atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
  319. atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
  320. seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
  321. atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
  322. atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
  323. seq_printf(m, "\nCreates: %d sent %d failed",
  324. atomic_read(&sent[SMB2_CREATE_HE]),
  325. atomic_read(&failed[SMB2_CREATE_HE]));
  326. seq_printf(m, "\nCloses: %d sent %d failed",
  327. atomic_read(&sent[SMB2_CLOSE_HE]),
  328. atomic_read(&failed[SMB2_CLOSE_HE]));
  329. seq_printf(m, "\nFlushes: %d sent %d failed",
  330. atomic_read(&sent[SMB2_FLUSH_HE]),
  331. atomic_read(&failed[SMB2_FLUSH_HE]));
  332. seq_printf(m, "\nReads: %d sent %d failed",
  333. atomic_read(&sent[SMB2_READ_HE]),
  334. atomic_read(&failed[SMB2_READ_HE]));
  335. seq_printf(m, "\nWrites: %d sent %d failed",
  336. atomic_read(&sent[SMB2_WRITE_HE]),
  337. atomic_read(&failed[SMB2_WRITE_HE]));
  338. seq_printf(m, "\nLocks: %d sent %d failed",
  339. atomic_read(&sent[SMB2_LOCK_HE]),
  340. atomic_read(&failed[SMB2_LOCK_HE]));
  341. seq_printf(m, "\nIOCTLs: %d sent %d failed",
  342. atomic_read(&sent[SMB2_IOCTL_HE]),
  343. atomic_read(&failed[SMB2_IOCTL_HE]));
  344. seq_printf(m, "\nCancels: %d sent %d failed",
  345. atomic_read(&sent[SMB2_CANCEL_HE]),
  346. atomic_read(&failed[SMB2_CANCEL_HE]));
  347. seq_printf(m, "\nEchos: %d sent %d failed",
  348. atomic_read(&sent[SMB2_ECHO_HE]),
  349. atomic_read(&failed[SMB2_ECHO_HE]));
  350. seq_printf(m, "\nQueryDirectories: %d sent %d failed",
  351. atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
  352. atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
  353. seq_printf(m, "\nChangeNotifies: %d sent %d failed",
  354. atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
  355. atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
  356. seq_printf(m, "\nQueryInfos: %d sent %d failed",
  357. atomic_read(&sent[SMB2_QUERY_INFO_HE]),
  358. atomic_read(&failed[SMB2_QUERY_INFO_HE]));
  359. seq_printf(m, "\nSetInfos: %d sent %d failed",
  360. atomic_read(&sent[SMB2_SET_INFO_HE]),
  361. atomic_read(&failed[SMB2_SET_INFO_HE]));
  362. seq_printf(m, "\nOplockBreaks: %d sent %d failed",
  363. atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
  364. atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
  365. #endif
  366. }
  367. static void
  368. smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
  369. {
  370. struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
  371. struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
  372. cfile->fid.persistent_fid = fid->persistent_fid;
  373. cfile->fid.volatile_fid = fid->volatile_fid;
  374. server->ops->set_oplock_level(cinode, oplock, fid->epoch,
  375. &fid->purge_cache);
  376. cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
  377. }
  378. static void
  379. smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
  380. struct cifs_fid *fid)
  381. {
  382. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  383. }
  384. static int
  385. smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
  386. struct cifs_fid *fid)
  387. {
  388. return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  389. }
  390. static unsigned int
  391. smb2_read_data_offset(char *buf)
  392. {
  393. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  394. return rsp->DataOffset;
  395. }
  396. static unsigned int
  397. smb2_read_data_length(char *buf)
  398. {
  399. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  400. return le32_to_cpu(rsp->DataLength);
  401. }
  402. static int
  403. smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
  404. struct cifs_io_parms *parms, unsigned int *bytes_read,
  405. char **buf, int *buf_type)
  406. {
  407. parms->persistent_fid = cfile->fid.persistent_fid;
  408. parms->volatile_fid = cfile->fid.volatile_fid;
  409. return SMB2_read(xid, parms, bytes_read, buf, buf_type);
  410. }
  411. static int
  412. smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
  413. struct cifs_io_parms *parms, unsigned int *written,
  414. struct kvec *iov, unsigned long nr_segs)
  415. {
  416. parms->persistent_fid = cfile->fid.persistent_fid;
  417. parms->volatile_fid = cfile->fid.volatile_fid;
  418. return SMB2_write(xid, parms, written, iov, nr_segs);
  419. }
  420. static int
  421. smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
  422. struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
  423. {
  424. __le64 eof = cpu_to_le64(size);
  425. return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
  426. cfile->fid.volatile_fid, cfile->pid, &eof);
  427. }
  428. static int
  429. smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
  430. struct cifsFileInfo *cfile)
  431. {
  432. return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
  433. cfile->fid.volatile_fid);
  434. }
  435. static int
  436. smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
  437. const char *path, struct cifs_sb_info *cifs_sb,
  438. struct cifs_fid *fid, __u16 search_flags,
  439. struct cifs_search_info *srch_inf)
  440. {
  441. __le16 *utf16_path;
  442. int rc;
  443. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  444. struct cifs_open_parms oparms;
  445. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  446. if (!utf16_path)
  447. return -ENOMEM;
  448. oparms.tcon = tcon;
  449. oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
  450. oparms.disposition = FILE_OPEN;
  451. oparms.create_options = 0;
  452. oparms.fid = fid;
  453. oparms.reconnect = false;
  454. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  455. kfree(utf16_path);
  456. if (rc) {
  457. cifs_dbg(VFS, "open dir failed\n");
  458. return rc;
  459. }
  460. srch_inf->entries_in_buffer = 0;
  461. srch_inf->index_of_last_entry = 0;
  462. rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
  463. fid->volatile_fid, 0, srch_inf);
  464. if (rc) {
  465. cifs_dbg(VFS, "query directory failed\n");
  466. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  467. }
  468. return rc;
  469. }
  470. static int
  471. smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
  472. struct cifs_fid *fid, __u16 search_flags,
  473. struct cifs_search_info *srch_inf)
  474. {
  475. return SMB2_query_directory(xid, tcon, fid->persistent_fid,
  476. fid->volatile_fid, 0, srch_inf);
  477. }
  478. static int
  479. smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
  480. struct cifs_fid *fid)
  481. {
  482. return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  483. }
  484. /*
  485. * If we negotiate SMB2 protocol and get STATUS_PENDING - update
  486. * the number of credits and return true. Otherwise - return false.
  487. */
  488. static bool
  489. smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
  490. {
  491. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  492. if (hdr->Status != STATUS_PENDING)
  493. return false;
  494. if (!length) {
  495. spin_lock(&server->req_lock);
  496. server->credits += le16_to_cpu(hdr->CreditRequest);
  497. spin_unlock(&server->req_lock);
  498. wake_up(&server->request_q);
  499. }
  500. return true;
  501. }
  502. static int
  503. smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
  504. struct cifsInodeInfo *cinode)
  505. {
  506. if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
  507. return SMB2_lease_break(0, tcon, cinode->lease_key,
  508. smb2_get_lease_state(cinode));
  509. return SMB2_oplock_break(0, tcon, fid->persistent_fid,
  510. fid->volatile_fid,
  511. CIFS_CACHE_READ(cinode) ? 1 : 0);
  512. }
  513. static int
  514. smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
  515. struct kstatfs *buf)
  516. {
  517. int rc;
  518. __le16 srch_path = 0; /* Null - open root of share */
  519. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  520. struct cifs_open_parms oparms;
  521. struct cifs_fid fid;
  522. oparms.tcon = tcon;
  523. oparms.desired_access = FILE_READ_ATTRIBUTES;
  524. oparms.disposition = FILE_OPEN;
  525. oparms.create_options = 0;
  526. oparms.fid = &fid;
  527. oparms.reconnect = false;
  528. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  529. if (rc)
  530. return rc;
  531. buf->f_type = SMB2_MAGIC_NUMBER;
  532. rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  533. buf);
  534. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  535. return rc;
  536. }
  537. static bool
  538. smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  539. {
  540. return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
  541. ob1->fid.volatile_fid == ob2->fid.volatile_fid;
  542. }
  543. static int
  544. smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
  545. __u64 length, __u32 type, int lock, int unlock, bool wait)
  546. {
  547. if (unlock && !lock)
  548. type = SMB2_LOCKFLAG_UNLOCK;
  549. return SMB2_lock(xid, tlink_tcon(cfile->tlink),
  550. cfile->fid.persistent_fid, cfile->fid.volatile_fid,
  551. current->tgid, length, offset, type, wait);
  552. }
  553. static void
  554. smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
  555. {
  556. memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
  557. }
  558. static void
  559. smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
  560. {
  561. memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
  562. }
  563. static void
  564. smb2_new_lease_key(struct cifs_fid *fid)
  565. {
  566. get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
  567. }
  568. static int
  569. smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
  570. const char *full_path, char **target_path,
  571. struct cifs_sb_info *cifs_sb)
  572. {
  573. int rc;
  574. __le16 *utf16_path;
  575. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  576. struct cifs_open_parms oparms;
  577. struct cifs_fid fid;
  578. struct smb2_err_rsp *err_buf = NULL;
  579. struct smb2_symlink_err_rsp *symlink;
  580. unsigned int sub_len, sub_offset;
  581. cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
  582. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  583. if (!utf16_path)
  584. return -ENOMEM;
  585. oparms.tcon = tcon;
  586. oparms.desired_access = FILE_READ_ATTRIBUTES;
  587. oparms.disposition = FILE_OPEN;
  588. oparms.create_options = 0;
  589. oparms.fid = &fid;
  590. oparms.reconnect = false;
  591. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
  592. if (!rc || !err_buf) {
  593. kfree(utf16_path);
  594. return -ENOENT;
  595. }
  596. /* open must fail on symlink - reset rc */
  597. rc = 0;
  598. symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
  599. sub_len = le16_to_cpu(symlink->SubstituteNameLength);
  600. sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
  601. *target_path = cifs_strndup_from_utf16(
  602. (char *)symlink->PathBuffer + sub_offset,
  603. sub_len, true, cifs_sb->local_nls);
  604. if (!(*target_path)) {
  605. kfree(utf16_path);
  606. return -ENOMEM;
  607. }
  608. convert_delimiter(*target_path, '/');
  609. cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
  610. kfree(utf16_path);
  611. return rc;
  612. }
  613. static void
  614. smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  615. unsigned int epoch, bool *purge_cache)
  616. {
  617. oplock &= 0xFF;
  618. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  619. return;
  620. if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
  621. cinode->oplock = CIFS_CACHE_RHW_FLG;
  622. cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
  623. &cinode->vfs_inode);
  624. } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
  625. cinode->oplock = CIFS_CACHE_RW_FLG;
  626. cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
  627. &cinode->vfs_inode);
  628. } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
  629. cinode->oplock = CIFS_CACHE_READ_FLG;
  630. cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
  631. &cinode->vfs_inode);
  632. } else
  633. cinode->oplock = 0;
  634. }
  635. static void
  636. smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  637. unsigned int epoch, bool *purge_cache)
  638. {
  639. char message[5] = {0};
  640. oplock &= 0xFF;
  641. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  642. return;
  643. cinode->oplock = 0;
  644. if (oplock & SMB2_LEASE_READ_CACHING_HE) {
  645. cinode->oplock |= CIFS_CACHE_READ_FLG;
  646. strcat(message, "R");
  647. }
  648. if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
  649. cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
  650. strcat(message, "H");
  651. }
  652. if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
  653. cinode->oplock |= CIFS_CACHE_WRITE_FLG;
  654. strcat(message, "W");
  655. }
  656. if (!cinode->oplock)
  657. strcat(message, "None");
  658. cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
  659. &cinode->vfs_inode);
  660. }
  661. static void
  662. smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  663. unsigned int epoch, bool *purge_cache)
  664. {
  665. unsigned int old_oplock = cinode->oplock;
  666. smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
  667. if (purge_cache) {
  668. *purge_cache = false;
  669. if (old_oplock == CIFS_CACHE_READ_FLG) {
  670. if (cinode->oplock == CIFS_CACHE_READ_FLG &&
  671. (epoch - cinode->epoch > 0))
  672. *purge_cache = true;
  673. else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  674. (epoch - cinode->epoch > 1))
  675. *purge_cache = true;
  676. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  677. (epoch - cinode->epoch > 1))
  678. *purge_cache = true;
  679. else if (cinode->oplock == 0 &&
  680. (epoch - cinode->epoch > 0))
  681. *purge_cache = true;
  682. } else if (old_oplock == CIFS_CACHE_RH_FLG) {
  683. if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  684. (epoch - cinode->epoch > 0))
  685. *purge_cache = true;
  686. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  687. (epoch - cinode->epoch > 1))
  688. *purge_cache = true;
  689. }
  690. cinode->epoch = epoch;
  691. }
  692. }
  693. static bool
  694. smb2_is_read_op(__u32 oplock)
  695. {
  696. return oplock == SMB2_OPLOCK_LEVEL_II;
  697. }
  698. static bool
  699. smb21_is_read_op(__u32 oplock)
  700. {
  701. return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
  702. !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
  703. }
  704. static __le32
  705. map_oplock_to_lease(u8 oplock)
  706. {
  707. if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
  708. return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
  709. else if (oplock == SMB2_OPLOCK_LEVEL_II)
  710. return SMB2_LEASE_READ_CACHING;
  711. else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
  712. return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
  713. SMB2_LEASE_WRITE_CACHING;
  714. return 0;
  715. }
  716. static char *
  717. smb2_create_lease_buf(u8 *lease_key, u8 oplock)
  718. {
  719. struct create_lease *buf;
  720. buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
  721. if (!buf)
  722. return NULL;
  723. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  724. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  725. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  726. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  727. (struct create_lease, lcontext));
  728. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
  729. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  730. (struct create_lease, Name));
  731. buf->ccontext.NameLength = cpu_to_le16(4);
  732. buf->Name[0] = 'R';
  733. buf->Name[1] = 'q';
  734. buf->Name[2] = 'L';
  735. buf->Name[3] = 's';
  736. return (char *)buf;
  737. }
  738. static char *
  739. smb3_create_lease_buf(u8 *lease_key, u8 oplock)
  740. {
  741. struct create_lease_v2 *buf;
  742. buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
  743. if (!buf)
  744. return NULL;
  745. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  746. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  747. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  748. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  749. (struct create_lease_v2, lcontext));
  750. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
  751. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  752. (struct create_lease_v2, Name));
  753. buf->ccontext.NameLength = cpu_to_le16(4);
  754. buf->Name[0] = 'R';
  755. buf->Name[1] = 'q';
  756. buf->Name[2] = 'L';
  757. buf->Name[3] = 's';
  758. return (char *)buf;
  759. }
  760. static __u8
  761. smb2_parse_lease_buf(void *buf, unsigned int *epoch)
  762. {
  763. struct create_lease *lc = (struct create_lease *)buf;
  764. *epoch = 0; /* not used */
  765. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  766. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  767. return le32_to_cpu(lc->lcontext.LeaseState);
  768. }
  769. static __u8
  770. smb3_parse_lease_buf(void *buf, unsigned int *epoch)
  771. {
  772. struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
  773. *epoch = le16_to_cpu(lc->lcontext.Epoch);
  774. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  775. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  776. return le32_to_cpu(lc->lcontext.LeaseState);
  777. }
  778. struct smb_version_operations smb20_operations = {
  779. .compare_fids = smb2_compare_fids,
  780. .setup_request = smb2_setup_request,
  781. .setup_async_request = smb2_setup_async_request,
  782. .check_receive = smb2_check_receive,
  783. .add_credits = smb2_add_credits,
  784. .set_credits = smb2_set_credits,
  785. .get_credits_field = smb2_get_credits_field,
  786. .get_credits = smb2_get_credits,
  787. .get_next_mid = smb2_get_next_mid,
  788. .read_data_offset = smb2_read_data_offset,
  789. .read_data_length = smb2_read_data_length,
  790. .map_error = map_smb2_to_linux_error,
  791. .find_mid = smb2_find_mid,
  792. .check_message = smb2_check_message,
  793. .dump_detail = smb2_dump_detail,
  794. .clear_stats = smb2_clear_stats,
  795. .print_stats = smb2_print_stats,
  796. .is_oplock_break = smb2_is_valid_oplock_break,
  797. .need_neg = smb2_need_neg,
  798. .negotiate = smb2_negotiate,
  799. .negotiate_wsize = smb2_negotiate_wsize,
  800. .negotiate_rsize = smb2_negotiate_rsize,
  801. .sess_setup = SMB2_sess_setup,
  802. .logoff = SMB2_logoff,
  803. .tree_connect = SMB2_tcon,
  804. .tree_disconnect = SMB2_tdis,
  805. .qfs_tcon = smb2_qfs_tcon,
  806. .is_path_accessible = smb2_is_path_accessible,
  807. .can_echo = smb2_can_echo,
  808. .echo = SMB2_echo,
  809. .query_path_info = smb2_query_path_info,
  810. .get_srv_inum = smb2_get_srv_inum,
  811. .query_file_info = smb2_query_file_info,
  812. .set_path_size = smb2_set_path_size,
  813. .set_file_size = smb2_set_file_size,
  814. .set_file_info = smb2_set_file_info,
  815. .set_compression = smb2_set_compression,
  816. .mkdir = smb2_mkdir,
  817. .mkdir_setinfo = smb2_mkdir_setinfo,
  818. .rmdir = smb2_rmdir,
  819. .unlink = smb2_unlink,
  820. .rename = smb2_rename_path,
  821. .create_hardlink = smb2_create_hardlink,
  822. .query_symlink = smb2_query_symlink,
  823. .open = smb2_open_file,
  824. .set_fid = smb2_set_fid,
  825. .close = smb2_close_file,
  826. .flush = smb2_flush_file,
  827. .async_readv = smb2_async_readv,
  828. .async_writev = smb2_async_writev,
  829. .sync_read = smb2_sync_read,
  830. .sync_write = smb2_sync_write,
  831. .query_dir_first = smb2_query_dir_first,
  832. .query_dir_next = smb2_query_dir_next,
  833. .close_dir = smb2_close_dir,
  834. .calc_smb_size = smb2_calc_size,
  835. .is_status_pending = smb2_is_status_pending,
  836. .oplock_response = smb2_oplock_response,
  837. .queryfs = smb2_queryfs,
  838. .mand_lock = smb2_mand_lock,
  839. .mand_unlock_range = smb2_unlock_range,
  840. .push_mand_locks = smb2_push_mandatory_locks,
  841. .get_lease_key = smb2_get_lease_key,
  842. .set_lease_key = smb2_set_lease_key,
  843. .new_lease_key = smb2_new_lease_key,
  844. .calc_signature = smb2_calc_signature,
  845. .is_read_op = smb2_is_read_op,
  846. .set_oplock_level = smb2_set_oplock_level,
  847. .create_lease_buf = smb2_create_lease_buf,
  848. .parse_lease_buf = smb2_parse_lease_buf,
  849. };
  850. struct smb_version_operations smb21_operations = {
  851. .compare_fids = smb2_compare_fids,
  852. .setup_request = smb2_setup_request,
  853. .setup_async_request = smb2_setup_async_request,
  854. .check_receive = smb2_check_receive,
  855. .add_credits = smb2_add_credits,
  856. .set_credits = smb2_set_credits,
  857. .get_credits_field = smb2_get_credits_field,
  858. .get_credits = smb2_get_credits,
  859. .get_next_mid = smb2_get_next_mid,
  860. .read_data_offset = smb2_read_data_offset,
  861. .read_data_length = smb2_read_data_length,
  862. .map_error = map_smb2_to_linux_error,
  863. .find_mid = smb2_find_mid,
  864. .check_message = smb2_check_message,
  865. .dump_detail = smb2_dump_detail,
  866. .clear_stats = smb2_clear_stats,
  867. .print_stats = smb2_print_stats,
  868. .is_oplock_break = smb2_is_valid_oplock_break,
  869. .need_neg = smb2_need_neg,
  870. .negotiate = smb2_negotiate,
  871. .negotiate_wsize = smb2_negotiate_wsize,
  872. .negotiate_rsize = smb2_negotiate_rsize,
  873. .sess_setup = SMB2_sess_setup,
  874. .logoff = SMB2_logoff,
  875. .tree_connect = SMB2_tcon,
  876. .tree_disconnect = SMB2_tdis,
  877. .qfs_tcon = smb2_qfs_tcon,
  878. .is_path_accessible = smb2_is_path_accessible,
  879. .can_echo = smb2_can_echo,
  880. .echo = SMB2_echo,
  881. .query_path_info = smb2_query_path_info,
  882. .get_srv_inum = smb2_get_srv_inum,
  883. .query_file_info = smb2_query_file_info,
  884. .set_path_size = smb2_set_path_size,
  885. .set_file_size = smb2_set_file_size,
  886. .set_file_info = smb2_set_file_info,
  887. .set_compression = smb2_set_compression,
  888. .mkdir = smb2_mkdir,
  889. .mkdir_setinfo = smb2_mkdir_setinfo,
  890. .rmdir = smb2_rmdir,
  891. .unlink = smb2_unlink,
  892. .rename = smb2_rename_path,
  893. .create_hardlink = smb2_create_hardlink,
  894. .query_symlink = smb2_query_symlink,
  895. .open = smb2_open_file,
  896. .set_fid = smb2_set_fid,
  897. .close = smb2_close_file,
  898. .flush = smb2_flush_file,
  899. .async_readv = smb2_async_readv,
  900. .async_writev = smb2_async_writev,
  901. .sync_read = smb2_sync_read,
  902. .sync_write = smb2_sync_write,
  903. .query_dir_first = smb2_query_dir_first,
  904. .query_dir_next = smb2_query_dir_next,
  905. .close_dir = smb2_close_dir,
  906. .calc_smb_size = smb2_calc_size,
  907. .is_status_pending = smb2_is_status_pending,
  908. .oplock_response = smb2_oplock_response,
  909. .queryfs = smb2_queryfs,
  910. .mand_lock = smb2_mand_lock,
  911. .mand_unlock_range = smb2_unlock_range,
  912. .push_mand_locks = smb2_push_mandatory_locks,
  913. .get_lease_key = smb2_get_lease_key,
  914. .set_lease_key = smb2_set_lease_key,
  915. .new_lease_key = smb2_new_lease_key,
  916. .calc_signature = smb2_calc_signature,
  917. .is_read_op = smb21_is_read_op,
  918. .set_oplock_level = smb21_set_oplock_level,
  919. .create_lease_buf = smb2_create_lease_buf,
  920. .parse_lease_buf = smb2_parse_lease_buf,
  921. };
  922. struct smb_version_operations smb30_operations = {
  923. .compare_fids = smb2_compare_fids,
  924. .setup_request = smb2_setup_request,
  925. .setup_async_request = smb2_setup_async_request,
  926. .check_receive = smb2_check_receive,
  927. .add_credits = smb2_add_credits,
  928. .set_credits = smb2_set_credits,
  929. .get_credits_field = smb2_get_credits_field,
  930. .get_credits = smb2_get_credits,
  931. .get_next_mid = smb2_get_next_mid,
  932. .read_data_offset = smb2_read_data_offset,
  933. .read_data_length = smb2_read_data_length,
  934. .map_error = map_smb2_to_linux_error,
  935. .find_mid = smb2_find_mid,
  936. .check_message = smb2_check_message,
  937. .dump_detail = smb2_dump_detail,
  938. .clear_stats = smb2_clear_stats,
  939. .print_stats = smb2_print_stats,
  940. .dump_share_caps = smb2_dump_share_caps,
  941. .is_oplock_break = smb2_is_valid_oplock_break,
  942. .need_neg = smb2_need_neg,
  943. .negotiate = smb2_negotiate,
  944. .negotiate_wsize = smb2_negotiate_wsize,
  945. .negotiate_rsize = smb2_negotiate_rsize,
  946. .sess_setup = SMB2_sess_setup,
  947. .logoff = SMB2_logoff,
  948. .tree_connect = SMB2_tcon,
  949. .tree_disconnect = SMB2_tdis,
  950. .qfs_tcon = smb2_qfs_tcon,
  951. .is_path_accessible = smb2_is_path_accessible,
  952. .can_echo = smb2_can_echo,
  953. .echo = SMB2_echo,
  954. .query_path_info = smb2_query_path_info,
  955. .get_srv_inum = smb2_get_srv_inum,
  956. .query_file_info = smb2_query_file_info,
  957. .set_path_size = smb2_set_path_size,
  958. .set_file_size = smb2_set_file_size,
  959. .set_file_info = smb2_set_file_info,
  960. .set_compression = smb2_set_compression,
  961. .mkdir = smb2_mkdir,
  962. .mkdir_setinfo = smb2_mkdir_setinfo,
  963. .rmdir = smb2_rmdir,
  964. .unlink = smb2_unlink,
  965. .rename = smb2_rename_path,
  966. .create_hardlink = smb2_create_hardlink,
  967. .query_symlink = smb2_query_symlink,
  968. .open = smb2_open_file,
  969. .set_fid = smb2_set_fid,
  970. .close = smb2_close_file,
  971. .flush = smb2_flush_file,
  972. .async_readv = smb2_async_readv,
  973. .async_writev = smb2_async_writev,
  974. .sync_read = smb2_sync_read,
  975. .sync_write = smb2_sync_write,
  976. .query_dir_first = smb2_query_dir_first,
  977. .query_dir_next = smb2_query_dir_next,
  978. .close_dir = smb2_close_dir,
  979. .calc_smb_size = smb2_calc_size,
  980. .is_status_pending = smb2_is_status_pending,
  981. .oplock_response = smb2_oplock_response,
  982. .queryfs = smb2_queryfs,
  983. .mand_lock = smb2_mand_lock,
  984. .mand_unlock_range = smb2_unlock_range,
  985. .push_mand_locks = smb2_push_mandatory_locks,
  986. .get_lease_key = smb2_get_lease_key,
  987. .set_lease_key = smb2_set_lease_key,
  988. .new_lease_key = smb2_new_lease_key,
  989. .generate_signingkey = generate_smb3signingkey,
  990. .calc_signature = smb3_calc_signature,
  991. .is_read_op = smb21_is_read_op,
  992. .set_oplock_level = smb3_set_oplock_level,
  993. .create_lease_buf = smb3_create_lease_buf,
  994. .parse_lease_buf = smb3_parse_lease_buf,
  995. };
  996. struct smb_version_values smb20_values = {
  997. .version_string = SMB20_VERSION_STRING,
  998. .protocol_id = SMB20_PROT_ID,
  999. .req_capabilities = 0, /* MBZ */
  1000. .large_lock_type = 0,
  1001. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1002. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1003. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1004. .header_size = sizeof(struct smb2_hdr),
  1005. .max_header_size = MAX_SMB2_HDR_SIZE,
  1006. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1007. .lock_cmd = SMB2_LOCK,
  1008. .cap_unix = 0,
  1009. .cap_nt_find = SMB2_NT_FIND,
  1010. .cap_large_files = SMB2_LARGE_FILES,
  1011. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1012. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1013. .create_lease_size = sizeof(struct create_lease),
  1014. };
  1015. struct smb_version_values smb21_values = {
  1016. .version_string = SMB21_VERSION_STRING,
  1017. .protocol_id = SMB21_PROT_ID,
  1018. .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
  1019. .large_lock_type = 0,
  1020. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1021. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1022. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1023. .header_size = sizeof(struct smb2_hdr),
  1024. .max_header_size = MAX_SMB2_HDR_SIZE,
  1025. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1026. .lock_cmd = SMB2_LOCK,
  1027. .cap_unix = 0,
  1028. .cap_nt_find = SMB2_NT_FIND,
  1029. .cap_large_files = SMB2_LARGE_FILES,
  1030. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1031. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1032. .create_lease_size = sizeof(struct create_lease),
  1033. };
  1034. struct smb_version_values smb30_values = {
  1035. .version_string = SMB30_VERSION_STRING,
  1036. .protocol_id = SMB30_PROT_ID,
  1037. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1038. .large_lock_type = 0,
  1039. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1040. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1041. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1042. .header_size = sizeof(struct smb2_hdr),
  1043. .max_header_size = MAX_SMB2_HDR_SIZE,
  1044. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1045. .lock_cmd = SMB2_LOCK,
  1046. .cap_unix = 0,
  1047. .cap_nt_find = SMB2_NT_FIND,
  1048. .cap_large_files = SMB2_LARGE_FILES,
  1049. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1050. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1051. .create_lease_size = sizeof(struct create_lease_v2),
  1052. };
  1053. struct smb_version_values smb302_values = {
  1054. .version_string = SMB302_VERSION_STRING,
  1055. .protocol_id = SMB302_PROT_ID,
  1056. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1057. .large_lock_type = 0,
  1058. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1059. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1060. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1061. .header_size = sizeof(struct smb2_hdr),
  1062. .max_header_size = MAX_SMB2_HDR_SIZE,
  1063. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1064. .lock_cmd = SMB2_LOCK,
  1065. .cap_unix = 0,
  1066. .cap_nt_find = SMB2_NT_FIND,
  1067. .cap_large_files = SMB2_LARGE_FILES,
  1068. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1069. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1070. .create_lease_size = sizeof(struct create_lease_v2),
  1071. };