smb2ops.c 34 KB

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