smb2ops.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  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 <linux/falloc.h>
  22. #include "cifsglob.h"
  23. #include "smb2pdu.h"
  24. #include "smb2proto.h"
  25. #include "cifsproto.h"
  26. #include "cifs_debug.h"
  27. #include "cifs_unicode.h"
  28. #include "smb2status.h"
  29. #include "smb2glob.h"
  30. static int
  31. change_conf(struct TCP_Server_Info *server)
  32. {
  33. server->credits += server->echo_credits + server->oplock_credits;
  34. server->oplock_credits = server->echo_credits = 0;
  35. switch (server->credits) {
  36. case 0:
  37. return -1;
  38. case 1:
  39. server->echoes = false;
  40. server->oplocks = false;
  41. cifs_dbg(VFS, "disabling echoes and oplocks\n");
  42. break;
  43. case 2:
  44. server->echoes = true;
  45. server->oplocks = false;
  46. server->echo_credits = 1;
  47. cifs_dbg(FYI, "disabling oplocks\n");
  48. break;
  49. default:
  50. server->echoes = true;
  51. server->oplocks = true;
  52. server->echo_credits = 1;
  53. server->oplock_credits = 1;
  54. }
  55. server->credits -= server->echo_credits + server->oplock_credits;
  56. return 0;
  57. }
  58. static void
  59. smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
  60. const int optype)
  61. {
  62. int *val, rc = 0;
  63. spin_lock(&server->req_lock);
  64. val = server->ops->get_credits_field(server, optype);
  65. *val += add;
  66. server->in_flight--;
  67. if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
  68. rc = change_conf(server);
  69. /*
  70. * Sometimes server returns 0 credits on oplock break ack - we need to
  71. * rebalance credits in this case.
  72. */
  73. else if (server->in_flight > 0 && server->oplock_credits == 0 &&
  74. server->oplocks) {
  75. if (server->credits > 1) {
  76. server->credits--;
  77. server->oplock_credits++;
  78. }
  79. }
  80. spin_unlock(&server->req_lock);
  81. wake_up(&server->request_q);
  82. if (rc)
  83. cifs_reconnect(server);
  84. }
  85. static void
  86. smb2_set_credits(struct TCP_Server_Info *server, const int val)
  87. {
  88. spin_lock(&server->req_lock);
  89. server->credits = val;
  90. spin_unlock(&server->req_lock);
  91. }
  92. static int *
  93. smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
  94. {
  95. switch (optype) {
  96. case CIFS_ECHO_OP:
  97. return &server->echo_credits;
  98. case CIFS_OBREAK_OP:
  99. return &server->oplock_credits;
  100. default:
  101. return &server->credits;
  102. }
  103. }
  104. static unsigned int
  105. smb2_get_credits(struct mid_q_entry *mid)
  106. {
  107. return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
  108. }
  109. static int
  110. smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
  111. unsigned int *num, unsigned int *credits)
  112. {
  113. int rc = 0;
  114. unsigned int scredits;
  115. spin_lock(&server->req_lock);
  116. while (1) {
  117. if (server->credits <= 0) {
  118. spin_unlock(&server->req_lock);
  119. cifs_num_waiters_inc(server);
  120. rc = wait_event_killable(server->request_q,
  121. has_credits(server, &server->credits));
  122. cifs_num_waiters_dec(server);
  123. if (rc)
  124. return rc;
  125. spin_lock(&server->req_lock);
  126. } else {
  127. if (server->tcpStatus == CifsExiting) {
  128. spin_unlock(&server->req_lock);
  129. return -ENOENT;
  130. }
  131. scredits = server->credits;
  132. /* can deadlock with reopen */
  133. if (scredits == 1) {
  134. *num = SMB2_MAX_BUFFER_SIZE;
  135. *credits = 0;
  136. break;
  137. }
  138. /* leave one credit for a possible reopen */
  139. scredits--;
  140. *num = min_t(unsigned int, size,
  141. scredits * SMB2_MAX_BUFFER_SIZE);
  142. *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
  143. server->credits -= *credits;
  144. server->in_flight++;
  145. break;
  146. }
  147. }
  148. spin_unlock(&server->req_lock);
  149. return rc;
  150. }
  151. static __u64
  152. smb2_get_next_mid(struct TCP_Server_Info *server)
  153. {
  154. __u64 mid;
  155. /* for SMB2 we need the current value */
  156. spin_lock(&GlobalMid_Lock);
  157. mid = server->CurrentMid++;
  158. spin_unlock(&GlobalMid_Lock);
  159. return mid;
  160. }
  161. static struct mid_q_entry *
  162. smb2_find_mid(struct TCP_Server_Info *server, char *buf)
  163. {
  164. struct mid_q_entry *mid;
  165. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  166. spin_lock(&GlobalMid_Lock);
  167. list_for_each_entry(mid, &server->pending_mid_q, qhead) {
  168. if ((mid->mid == hdr->MessageId) &&
  169. (mid->mid_state == MID_REQUEST_SUBMITTED) &&
  170. (mid->command == hdr->Command)) {
  171. spin_unlock(&GlobalMid_Lock);
  172. return mid;
  173. }
  174. }
  175. spin_unlock(&GlobalMid_Lock);
  176. return NULL;
  177. }
  178. static void
  179. smb2_dump_detail(void *buf)
  180. {
  181. #ifdef CONFIG_CIFS_DEBUG2
  182. struct smb2_hdr *smb = (struct smb2_hdr *)buf;
  183. cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
  184. smb->Command, smb->Status, smb->Flags, smb->MessageId,
  185. smb->ProcessId);
  186. cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
  187. #endif
  188. }
  189. static bool
  190. smb2_need_neg(struct TCP_Server_Info *server)
  191. {
  192. return server->max_read == 0;
  193. }
  194. static int
  195. smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
  196. {
  197. int rc;
  198. ses->server->CurrentMid = 0;
  199. rc = SMB2_negotiate(xid, ses);
  200. /* BB we probably don't need to retry with modern servers */
  201. if (rc == -EAGAIN)
  202. rc = -EHOSTDOWN;
  203. return rc;
  204. }
  205. static unsigned int
  206. smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  207. {
  208. struct TCP_Server_Info *server = tcon->ses->server;
  209. unsigned int wsize;
  210. /* start with specified wsize, or default */
  211. wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
  212. wsize = min_t(unsigned int, wsize, server->max_write);
  213. if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
  214. wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
  215. return wsize;
  216. }
  217. static unsigned int
  218. smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  219. {
  220. struct TCP_Server_Info *server = tcon->ses->server;
  221. unsigned int rsize;
  222. /* start with specified rsize, or default */
  223. rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
  224. rsize = min_t(unsigned int, rsize, server->max_read);
  225. if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
  226. rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
  227. return rsize;
  228. }
  229. #ifdef CONFIG_CIFS_STATS2
  230. static int
  231. SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
  232. {
  233. int rc;
  234. unsigned int ret_data_len = 0;
  235. struct network_interface_info_ioctl_rsp *out_buf;
  236. rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
  237. FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
  238. NULL /* no data input */, 0 /* no data input */,
  239. (char **)&out_buf, &ret_data_len);
  240. if (rc != 0)
  241. cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
  242. else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
  243. cifs_dbg(VFS, "server returned bad net interface info buf\n");
  244. rc = -EINVAL;
  245. } else {
  246. /* Dump info on first interface */
  247. cifs_dbg(FYI, "Adapter Capability 0x%x\t",
  248. le32_to_cpu(out_buf->Capability));
  249. cifs_dbg(FYI, "Link Speed %lld\n",
  250. le64_to_cpu(out_buf->LinkSpeed));
  251. }
  252. return rc;
  253. }
  254. #endif /* STATS2 */
  255. static void
  256. smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  257. {
  258. int rc;
  259. __le16 srch_path = 0; /* Null - open root of share */
  260. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  261. struct cifs_open_parms oparms;
  262. struct cifs_fid fid;
  263. oparms.tcon = tcon;
  264. oparms.desired_access = FILE_READ_ATTRIBUTES;
  265. oparms.disposition = FILE_OPEN;
  266. oparms.create_options = 0;
  267. oparms.fid = &fid;
  268. oparms.reconnect = false;
  269. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  270. if (rc)
  271. return;
  272. #ifdef CONFIG_CIFS_STATS2
  273. SMB3_request_interfaces(xid, tcon);
  274. #endif /* STATS2 */
  275. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  276. FS_ATTRIBUTE_INFORMATION);
  277. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  278. FS_DEVICE_INFORMATION);
  279. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  280. FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
  281. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  282. return;
  283. }
  284. static void
  285. smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  286. {
  287. int rc;
  288. __le16 srch_path = 0; /* Null - open root of share */
  289. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  290. struct cifs_open_parms oparms;
  291. struct cifs_fid fid;
  292. oparms.tcon = tcon;
  293. oparms.desired_access = FILE_READ_ATTRIBUTES;
  294. oparms.disposition = FILE_OPEN;
  295. oparms.create_options = 0;
  296. oparms.fid = &fid;
  297. oparms.reconnect = false;
  298. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  299. if (rc)
  300. return;
  301. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  302. FS_ATTRIBUTE_INFORMATION);
  303. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  304. FS_DEVICE_INFORMATION);
  305. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  306. return;
  307. }
  308. static int
  309. smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
  310. struct cifs_sb_info *cifs_sb, const char *full_path)
  311. {
  312. int rc;
  313. __le16 *utf16_path;
  314. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  315. struct cifs_open_parms oparms;
  316. struct cifs_fid fid;
  317. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  318. if (!utf16_path)
  319. return -ENOMEM;
  320. oparms.tcon = tcon;
  321. oparms.desired_access = FILE_READ_ATTRIBUTES;
  322. oparms.disposition = FILE_OPEN;
  323. oparms.create_options = 0;
  324. oparms.fid = &fid;
  325. oparms.reconnect = false;
  326. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  327. if (rc) {
  328. kfree(utf16_path);
  329. return rc;
  330. }
  331. rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  332. kfree(utf16_path);
  333. return rc;
  334. }
  335. static int
  336. smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
  337. struct cifs_sb_info *cifs_sb, const char *full_path,
  338. u64 *uniqueid, FILE_ALL_INFO *data)
  339. {
  340. *uniqueid = le64_to_cpu(data->IndexNumber);
  341. return 0;
  342. }
  343. static int
  344. smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
  345. struct cifs_fid *fid, FILE_ALL_INFO *data)
  346. {
  347. int rc;
  348. struct smb2_file_all_info *smb2_data;
  349. smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
  350. GFP_KERNEL);
  351. if (smb2_data == NULL)
  352. return -ENOMEM;
  353. rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
  354. smb2_data);
  355. if (!rc)
  356. move_smb2_info_to_cifs(data, smb2_data);
  357. kfree(smb2_data);
  358. return rc;
  359. }
  360. static bool
  361. smb2_can_echo(struct TCP_Server_Info *server)
  362. {
  363. return server->echoes;
  364. }
  365. static void
  366. smb2_clear_stats(struct cifs_tcon *tcon)
  367. {
  368. #ifdef CONFIG_CIFS_STATS
  369. int i;
  370. for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
  371. atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
  372. atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
  373. }
  374. #endif
  375. }
  376. static void
  377. smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
  378. {
  379. seq_puts(m, "\n\tShare Capabilities:");
  380. if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
  381. seq_puts(m, " DFS,");
  382. if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
  383. seq_puts(m, " CONTINUOUS AVAILABILITY,");
  384. if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
  385. seq_puts(m, " SCALEOUT,");
  386. if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
  387. seq_puts(m, " CLUSTER,");
  388. if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
  389. seq_puts(m, " ASYMMETRIC,");
  390. if (tcon->capabilities == 0)
  391. seq_puts(m, " None");
  392. if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
  393. seq_puts(m, " Aligned,");
  394. if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
  395. seq_puts(m, " Partition Aligned,");
  396. if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
  397. seq_puts(m, " SSD,");
  398. if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
  399. seq_puts(m, " TRIM-support,");
  400. seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
  401. if (tcon->perf_sector_size)
  402. seq_printf(m, "\tOptimal sector size: 0x%x",
  403. tcon->perf_sector_size);
  404. }
  405. static void
  406. smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
  407. {
  408. #ifdef CONFIG_CIFS_STATS
  409. atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
  410. atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
  411. seq_printf(m, "\nNegotiates: %d sent %d failed",
  412. atomic_read(&sent[SMB2_NEGOTIATE_HE]),
  413. atomic_read(&failed[SMB2_NEGOTIATE_HE]));
  414. seq_printf(m, "\nSessionSetups: %d sent %d failed",
  415. atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
  416. atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
  417. seq_printf(m, "\nLogoffs: %d sent %d failed",
  418. atomic_read(&sent[SMB2_LOGOFF_HE]),
  419. atomic_read(&failed[SMB2_LOGOFF_HE]));
  420. seq_printf(m, "\nTreeConnects: %d sent %d failed",
  421. atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
  422. atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
  423. seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
  424. atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
  425. atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
  426. seq_printf(m, "\nCreates: %d sent %d failed",
  427. atomic_read(&sent[SMB2_CREATE_HE]),
  428. atomic_read(&failed[SMB2_CREATE_HE]));
  429. seq_printf(m, "\nCloses: %d sent %d failed",
  430. atomic_read(&sent[SMB2_CLOSE_HE]),
  431. atomic_read(&failed[SMB2_CLOSE_HE]));
  432. seq_printf(m, "\nFlushes: %d sent %d failed",
  433. atomic_read(&sent[SMB2_FLUSH_HE]),
  434. atomic_read(&failed[SMB2_FLUSH_HE]));
  435. seq_printf(m, "\nReads: %d sent %d failed",
  436. atomic_read(&sent[SMB2_READ_HE]),
  437. atomic_read(&failed[SMB2_READ_HE]));
  438. seq_printf(m, "\nWrites: %d sent %d failed",
  439. atomic_read(&sent[SMB2_WRITE_HE]),
  440. atomic_read(&failed[SMB2_WRITE_HE]));
  441. seq_printf(m, "\nLocks: %d sent %d failed",
  442. atomic_read(&sent[SMB2_LOCK_HE]),
  443. atomic_read(&failed[SMB2_LOCK_HE]));
  444. seq_printf(m, "\nIOCTLs: %d sent %d failed",
  445. atomic_read(&sent[SMB2_IOCTL_HE]),
  446. atomic_read(&failed[SMB2_IOCTL_HE]));
  447. seq_printf(m, "\nCancels: %d sent %d failed",
  448. atomic_read(&sent[SMB2_CANCEL_HE]),
  449. atomic_read(&failed[SMB2_CANCEL_HE]));
  450. seq_printf(m, "\nEchos: %d sent %d failed",
  451. atomic_read(&sent[SMB2_ECHO_HE]),
  452. atomic_read(&failed[SMB2_ECHO_HE]));
  453. seq_printf(m, "\nQueryDirectories: %d sent %d failed",
  454. atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
  455. atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
  456. seq_printf(m, "\nChangeNotifies: %d sent %d failed",
  457. atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
  458. atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
  459. seq_printf(m, "\nQueryInfos: %d sent %d failed",
  460. atomic_read(&sent[SMB2_QUERY_INFO_HE]),
  461. atomic_read(&failed[SMB2_QUERY_INFO_HE]));
  462. seq_printf(m, "\nSetInfos: %d sent %d failed",
  463. atomic_read(&sent[SMB2_SET_INFO_HE]),
  464. atomic_read(&failed[SMB2_SET_INFO_HE]));
  465. seq_printf(m, "\nOplockBreaks: %d sent %d failed",
  466. atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
  467. atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
  468. #endif
  469. }
  470. static void
  471. smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
  472. {
  473. struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
  474. struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
  475. cfile->fid.persistent_fid = fid->persistent_fid;
  476. cfile->fid.volatile_fid = fid->volatile_fid;
  477. server->ops->set_oplock_level(cinode, oplock, fid->epoch,
  478. &fid->purge_cache);
  479. cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
  480. }
  481. static void
  482. smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
  483. struct cifs_fid *fid)
  484. {
  485. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  486. }
  487. static int
  488. SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
  489. u64 persistent_fid, u64 volatile_fid,
  490. struct copychunk_ioctl *pcchunk)
  491. {
  492. int rc;
  493. unsigned int ret_data_len;
  494. struct resume_key_req *res_key;
  495. rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
  496. FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
  497. NULL, 0 /* no input */,
  498. (char **)&res_key, &ret_data_len);
  499. if (rc) {
  500. cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
  501. goto req_res_key_exit;
  502. }
  503. if (ret_data_len < sizeof(struct resume_key_req)) {
  504. cifs_dbg(VFS, "Invalid refcopy resume key length\n");
  505. rc = -EINVAL;
  506. goto req_res_key_exit;
  507. }
  508. memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
  509. req_res_key_exit:
  510. kfree(res_key);
  511. return rc;
  512. }
  513. static int
  514. smb2_clone_range(const unsigned int xid,
  515. struct cifsFileInfo *srcfile,
  516. struct cifsFileInfo *trgtfile, u64 src_off,
  517. u64 len, u64 dest_off)
  518. {
  519. int rc;
  520. unsigned int ret_data_len;
  521. struct copychunk_ioctl *pcchunk;
  522. struct copychunk_ioctl_rsp *retbuf = NULL;
  523. struct cifs_tcon *tcon;
  524. int chunks_copied = 0;
  525. bool chunk_sizes_updated = false;
  526. pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
  527. if (pcchunk == NULL)
  528. return -ENOMEM;
  529. cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
  530. /* Request a key from the server to identify the source of the copy */
  531. rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
  532. srcfile->fid.persistent_fid,
  533. srcfile->fid.volatile_fid, pcchunk);
  534. /* Note: request_res_key sets res_key null only if rc !=0 */
  535. if (rc)
  536. goto cchunk_out;
  537. /* For now array only one chunk long, will make more flexible later */
  538. pcchunk->ChunkCount = __constant_cpu_to_le32(1);
  539. pcchunk->Reserved = 0;
  540. pcchunk->Reserved2 = 0;
  541. tcon = tlink_tcon(trgtfile->tlink);
  542. while (len > 0) {
  543. pcchunk->SourceOffset = cpu_to_le64(src_off);
  544. pcchunk->TargetOffset = cpu_to_le64(dest_off);
  545. pcchunk->Length =
  546. cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
  547. /* Request server copy to target from src identified by key */
  548. rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
  549. trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
  550. true /* is_fsctl */, (char *)pcchunk,
  551. sizeof(struct copychunk_ioctl), (char **)&retbuf,
  552. &ret_data_len);
  553. if (rc == 0) {
  554. if (ret_data_len !=
  555. sizeof(struct copychunk_ioctl_rsp)) {
  556. cifs_dbg(VFS, "invalid cchunk response size\n");
  557. rc = -EIO;
  558. goto cchunk_out;
  559. }
  560. if (retbuf->TotalBytesWritten == 0) {
  561. cifs_dbg(FYI, "no bytes copied\n");
  562. rc = -EIO;
  563. goto cchunk_out;
  564. }
  565. /*
  566. * Check if server claimed to write more than we asked
  567. */
  568. if (le32_to_cpu(retbuf->TotalBytesWritten) >
  569. le32_to_cpu(pcchunk->Length)) {
  570. cifs_dbg(VFS, "invalid copy chunk response\n");
  571. rc = -EIO;
  572. goto cchunk_out;
  573. }
  574. if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
  575. cifs_dbg(VFS, "invalid num chunks written\n");
  576. rc = -EIO;
  577. goto cchunk_out;
  578. }
  579. chunks_copied++;
  580. src_off += le32_to_cpu(retbuf->TotalBytesWritten);
  581. dest_off += le32_to_cpu(retbuf->TotalBytesWritten);
  582. len -= le32_to_cpu(retbuf->TotalBytesWritten);
  583. cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n",
  584. le32_to_cpu(retbuf->ChunksWritten),
  585. le32_to_cpu(retbuf->ChunkBytesWritten),
  586. le32_to_cpu(retbuf->TotalBytesWritten));
  587. } else if (rc == -EINVAL) {
  588. if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
  589. goto cchunk_out;
  590. cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
  591. le32_to_cpu(retbuf->ChunksWritten),
  592. le32_to_cpu(retbuf->ChunkBytesWritten),
  593. le32_to_cpu(retbuf->TotalBytesWritten));
  594. /*
  595. * Check if this is the first request using these sizes,
  596. * (ie check if copy succeed once with original sizes
  597. * and check if the server gave us different sizes after
  598. * we already updated max sizes on previous request).
  599. * if not then why is the server returning an error now
  600. */
  601. if ((chunks_copied != 0) || chunk_sizes_updated)
  602. goto cchunk_out;
  603. /* Check that server is not asking us to grow size */
  604. if (le32_to_cpu(retbuf->ChunkBytesWritten) <
  605. tcon->max_bytes_chunk)
  606. tcon->max_bytes_chunk =
  607. le32_to_cpu(retbuf->ChunkBytesWritten);
  608. else
  609. goto cchunk_out; /* server gave us bogus size */
  610. /* No need to change MaxChunks since already set to 1 */
  611. chunk_sizes_updated = true;
  612. } else
  613. goto cchunk_out;
  614. }
  615. cchunk_out:
  616. kfree(pcchunk);
  617. return rc;
  618. }
  619. static int
  620. smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
  621. struct cifs_fid *fid)
  622. {
  623. return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  624. }
  625. static unsigned int
  626. smb2_read_data_offset(char *buf)
  627. {
  628. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  629. return rsp->DataOffset;
  630. }
  631. static unsigned int
  632. smb2_read_data_length(char *buf)
  633. {
  634. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  635. return le32_to_cpu(rsp->DataLength);
  636. }
  637. static int
  638. smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
  639. struct cifs_io_parms *parms, unsigned int *bytes_read,
  640. char **buf, int *buf_type)
  641. {
  642. parms->persistent_fid = pfid->persistent_fid;
  643. parms->volatile_fid = pfid->volatile_fid;
  644. return SMB2_read(xid, parms, bytes_read, buf, buf_type);
  645. }
  646. static int
  647. smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
  648. struct cifs_io_parms *parms, unsigned int *written,
  649. struct kvec *iov, unsigned long nr_segs)
  650. {
  651. parms->persistent_fid = pfid->persistent_fid;
  652. parms->volatile_fid = pfid->volatile_fid;
  653. return SMB2_write(xid, parms, written, iov, nr_segs);
  654. }
  655. /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
  656. static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
  657. struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
  658. {
  659. struct cifsInodeInfo *cifsi;
  660. int rc;
  661. cifsi = CIFS_I(inode);
  662. /* if file already sparse don't bother setting sparse again */
  663. if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
  664. return true; /* already sparse */
  665. if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
  666. return true; /* already not sparse */
  667. /*
  668. * Can't check for sparse support on share the usual way via the
  669. * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
  670. * since Samba server doesn't set the flag on the share, yet
  671. * supports the set sparse FSCTL and returns sparse correctly
  672. * in the file attributes. If we fail setting sparse though we
  673. * mark that server does not support sparse files for this share
  674. * to avoid repeatedly sending the unsupported fsctl to server
  675. * if the file is repeatedly extended.
  676. */
  677. if (tcon->broken_sparse_sup)
  678. return false;
  679. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  680. cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
  681. true /* is_fctl */, &setsparse, 1, NULL, NULL);
  682. if (rc) {
  683. tcon->broken_sparse_sup = true;
  684. cifs_dbg(FYI, "set sparse rc = %d\n", rc);
  685. return false;
  686. }
  687. if (setsparse)
  688. cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
  689. else
  690. cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
  691. return true;
  692. }
  693. static int
  694. smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
  695. struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
  696. {
  697. __le64 eof = cpu_to_le64(size);
  698. struct inode *inode;
  699. /*
  700. * If extending file more than one page make sparse. Many Linux fs
  701. * make files sparse by default when extending via ftruncate
  702. */
  703. inode = cfile->dentry->d_inode;
  704. if (!set_alloc && (size > inode->i_size + 8192)) {
  705. __u8 set_sparse = 1;
  706. /* whether set sparse succeeds or not, extend the file */
  707. smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
  708. }
  709. return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
  710. cfile->fid.volatile_fid, cfile->pid, &eof, false);
  711. }
  712. static int
  713. smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
  714. struct cifsFileInfo *cfile)
  715. {
  716. return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
  717. cfile->fid.volatile_fid);
  718. }
  719. static int
  720. smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
  721. const char *path, struct cifs_sb_info *cifs_sb,
  722. struct cifs_fid *fid, __u16 search_flags,
  723. struct cifs_search_info *srch_inf)
  724. {
  725. __le16 *utf16_path;
  726. int rc;
  727. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  728. struct cifs_open_parms oparms;
  729. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  730. if (!utf16_path)
  731. return -ENOMEM;
  732. oparms.tcon = tcon;
  733. oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
  734. oparms.disposition = FILE_OPEN;
  735. oparms.create_options = 0;
  736. oparms.fid = fid;
  737. oparms.reconnect = false;
  738. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  739. kfree(utf16_path);
  740. if (rc) {
  741. cifs_dbg(VFS, "open dir failed\n");
  742. return rc;
  743. }
  744. srch_inf->entries_in_buffer = 0;
  745. srch_inf->index_of_last_entry = 0;
  746. rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
  747. fid->volatile_fid, 0, srch_inf);
  748. if (rc) {
  749. cifs_dbg(VFS, "query directory failed\n");
  750. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  751. }
  752. return rc;
  753. }
  754. static int
  755. smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
  756. struct cifs_fid *fid, __u16 search_flags,
  757. struct cifs_search_info *srch_inf)
  758. {
  759. return SMB2_query_directory(xid, tcon, fid->persistent_fid,
  760. fid->volatile_fid, 0, srch_inf);
  761. }
  762. static int
  763. smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
  764. struct cifs_fid *fid)
  765. {
  766. return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  767. }
  768. /*
  769. * If we negotiate SMB2 protocol and get STATUS_PENDING - update
  770. * the number of credits and return true. Otherwise - return false.
  771. */
  772. static bool
  773. smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
  774. {
  775. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  776. if (hdr->Status != STATUS_PENDING)
  777. return false;
  778. if (!length) {
  779. spin_lock(&server->req_lock);
  780. server->credits += le16_to_cpu(hdr->CreditRequest);
  781. spin_unlock(&server->req_lock);
  782. wake_up(&server->request_q);
  783. }
  784. return true;
  785. }
  786. static int
  787. smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
  788. struct cifsInodeInfo *cinode)
  789. {
  790. if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
  791. return SMB2_lease_break(0, tcon, cinode->lease_key,
  792. smb2_get_lease_state(cinode));
  793. return SMB2_oplock_break(0, tcon, fid->persistent_fid,
  794. fid->volatile_fid,
  795. CIFS_CACHE_READ(cinode) ? 1 : 0);
  796. }
  797. static int
  798. smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
  799. struct kstatfs *buf)
  800. {
  801. int rc;
  802. __le16 srch_path = 0; /* Null - open root of share */
  803. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  804. struct cifs_open_parms oparms;
  805. struct cifs_fid fid;
  806. oparms.tcon = tcon;
  807. oparms.desired_access = FILE_READ_ATTRIBUTES;
  808. oparms.disposition = FILE_OPEN;
  809. oparms.create_options = 0;
  810. oparms.fid = &fid;
  811. oparms.reconnect = false;
  812. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  813. if (rc)
  814. return rc;
  815. buf->f_type = SMB2_MAGIC_NUMBER;
  816. rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  817. buf);
  818. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  819. return rc;
  820. }
  821. static bool
  822. smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  823. {
  824. return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
  825. ob1->fid.volatile_fid == ob2->fid.volatile_fid;
  826. }
  827. static int
  828. smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
  829. __u64 length, __u32 type, int lock, int unlock, bool wait)
  830. {
  831. if (unlock && !lock)
  832. type = SMB2_LOCKFLAG_UNLOCK;
  833. return SMB2_lock(xid, tlink_tcon(cfile->tlink),
  834. cfile->fid.persistent_fid, cfile->fid.volatile_fid,
  835. current->tgid, length, offset, type, wait);
  836. }
  837. static void
  838. smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
  839. {
  840. memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
  841. }
  842. static void
  843. smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
  844. {
  845. memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
  846. }
  847. static void
  848. smb2_new_lease_key(struct cifs_fid *fid)
  849. {
  850. get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
  851. }
  852. static int
  853. smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
  854. const char *full_path, char **target_path,
  855. struct cifs_sb_info *cifs_sb)
  856. {
  857. int rc;
  858. __le16 *utf16_path;
  859. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  860. struct cifs_open_parms oparms;
  861. struct cifs_fid fid;
  862. struct smb2_err_rsp *err_buf = NULL;
  863. struct smb2_symlink_err_rsp *symlink;
  864. unsigned int sub_len, sub_offset;
  865. cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
  866. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  867. if (!utf16_path)
  868. return -ENOMEM;
  869. oparms.tcon = tcon;
  870. oparms.desired_access = FILE_READ_ATTRIBUTES;
  871. oparms.disposition = FILE_OPEN;
  872. oparms.create_options = 0;
  873. oparms.fid = &fid;
  874. oparms.reconnect = false;
  875. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
  876. if (!rc || !err_buf) {
  877. kfree(utf16_path);
  878. return -ENOENT;
  879. }
  880. /* open must fail on symlink - reset rc */
  881. rc = 0;
  882. symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
  883. sub_len = le16_to_cpu(symlink->SubstituteNameLength);
  884. sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
  885. *target_path = cifs_strndup_from_utf16(
  886. (char *)symlink->PathBuffer + sub_offset,
  887. sub_len, true, cifs_sb->local_nls);
  888. if (!(*target_path)) {
  889. kfree(utf16_path);
  890. return -ENOMEM;
  891. }
  892. convert_delimiter(*target_path, '/');
  893. cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
  894. kfree(utf16_path);
  895. return rc;
  896. }
  897. static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
  898. loff_t offset, loff_t len, bool keep_size)
  899. {
  900. struct inode *inode;
  901. struct cifsInodeInfo *cifsi;
  902. struct cifsFileInfo *cfile = file->private_data;
  903. struct file_zero_data_information fsctl_buf;
  904. long rc;
  905. unsigned int xid;
  906. xid = get_xid();
  907. inode = cfile->dentry->d_inode;
  908. cifsi = CIFS_I(inode);
  909. /* if file not oplocked can't be sure whether asking to extend size */
  910. if (!CIFS_CACHE_READ(cifsi))
  911. if (keep_size == false)
  912. return -EOPNOTSUPP;
  913. /*
  914. * Must check if file sparse since fallocate -z (zero range) assumes
  915. * non-sparse allocation
  916. */
  917. if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
  918. return -EOPNOTSUPP;
  919. /*
  920. * need to make sure we are not asked to extend the file since the SMB3
  921. * fsctl does not change the file size. In the future we could change
  922. * this to zero the first part of the range then set the file size
  923. * which for a non sparse file would zero the newly extended range
  924. */
  925. if (keep_size == false)
  926. if (i_size_read(inode) < offset + len)
  927. return -EOPNOTSUPP;
  928. cifs_dbg(FYI, "offset %lld len %lld", offset, len);
  929. fsctl_buf.FileOffset = cpu_to_le64(offset);
  930. fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
  931. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  932. cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
  933. true /* is_fctl */, (char *)&fsctl_buf,
  934. sizeof(struct file_zero_data_information), NULL, NULL);
  935. free_xid(xid);
  936. return rc;
  937. }
  938. static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
  939. loff_t offset, loff_t len)
  940. {
  941. struct inode *inode;
  942. struct cifsInodeInfo *cifsi;
  943. struct cifsFileInfo *cfile = file->private_data;
  944. struct file_zero_data_information fsctl_buf;
  945. long rc;
  946. unsigned int xid;
  947. __u8 set_sparse = 1;
  948. xid = get_xid();
  949. inode = cfile->dentry->d_inode;
  950. cifsi = CIFS_I(inode);
  951. /* Need to make file sparse, if not already, before freeing range. */
  952. /* Consider adding equivalent for compressed since it could also work */
  953. if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
  954. return -EOPNOTSUPP;
  955. cifs_dbg(FYI, "offset %lld len %lld", offset, len);
  956. fsctl_buf.FileOffset = cpu_to_le64(offset);
  957. fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
  958. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  959. cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
  960. true /* is_fctl */, (char *)&fsctl_buf,
  961. sizeof(struct file_zero_data_information), NULL, NULL);
  962. free_xid(xid);
  963. return rc;
  964. }
  965. static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
  966. loff_t off, loff_t len)
  967. {
  968. /* KEEP_SIZE already checked for by do_fallocate */
  969. if (mode & FALLOC_FL_PUNCH_HOLE)
  970. return smb3_punch_hole(file, tcon, off, len);
  971. else if (mode & FALLOC_FL_ZERO_RANGE) {
  972. if (mode & FALLOC_FL_KEEP_SIZE)
  973. return smb3_zero_range(file, tcon, off, len, true);
  974. return smb3_zero_range(file, tcon, off, len, false);
  975. }
  976. return -EOPNOTSUPP;
  977. }
  978. static void
  979. smb2_downgrade_oplock(struct TCP_Server_Info *server,
  980. struct cifsInodeInfo *cinode, bool set_level2)
  981. {
  982. if (set_level2)
  983. server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
  984. 0, NULL);
  985. else
  986. server->ops->set_oplock_level(cinode, 0, 0, NULL);
  987. }
  988. static void
  989. smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  990. unsigned int epoch, bool *purge_cache)
  991. {
  992. oplock &= 0xFF;
  993. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  994. return;
  995. if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
  996. cinode->oplock = CIFS_CACHE_RHW_FLG;
  997. cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
  998. &cinode->vfs_inode);
  999. } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
  1000. cinode->oplock = CIFS_CACHE_RW_FLG;
  1001. cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
  1002. &cinode->vfs_inode);
  1003. } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
  1004. cinode->oplock = CIFS_CACHE_READ_FLG;
  1005. cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
  1006. &cinode->vfs_inode);
  1007. } else
  1008. cinode->oplock = 0;
  1009. }
  1010. static void
  1011. smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1012. unsigned int epoch, bool *purge_cache)
  1013. {
  1014. char message[5] = {0};
  1015. oplock &= 0xFF;
  1016. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  1017. return;
  1018. cinode->oplock = 0;
  1019. if (oplock & SMB2_LEASE_READ_CACHING_HE) {
  1020. cinode->oplock |= CIFS_CACHE_READ_FLG;
  1021. strcat(message, "R");
  1022. }
  1023. if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
  1024. cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
  1025. strcat(message, "H");
  1026. }
  1027. if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
  1028. cinode->oplock |= CIFS_CACHE_WRITE_FLG;
  1029. strcat(message, "W");
  1030. }
  1031. if (!cinode->oplock)
  1032. strcat(message, "None");
  1033. cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
  1034. &cinode->vfs_inode);
  1035. }
  1036. static void
  1037. smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1038. unsigned int epoch, bool *purge_cache)
  1039. {
  1040. unsigned int old_oplock = cinode->oplock;
  1041. smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
  1042. if (purge_cache) {
  1043. *purge_cache = false;
  1044. if (old_oplock == CIFS_CACHE_READ_FLG) {
  1045. if (cinode->oplock == CIFS_CACHE_READ_FLG &&
  1046. (epoch - cinode->epoch > 0))
  1047. *purge_cache = true;
  1048. else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  1049. (epoch - cinode->epoch > 1))
  1050. *purge_cache = true;
  1051. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  1052. (epoch - cinode->epoch > 1))
  1053. *purge_cache = true;
  1054. else if (cinode->oplock == 0 &&
  1055. (epoch - cinode->epoch > 0))
  1056. *purge_cache = true;
  1057. } else if (old_oplock == CIFS_CACHE_RH_FLG) {
  1058. if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  1059. (epoch - cinode->epoch > 0))
  1060. *purge_cache = true;
  1061. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  1062. (epoch - cinode->epoch > 1))
  1063. *purge_cache = true;
  1064. }
  1065. cinode->epoch = epoch;
  1066. }
  1067. }
  1068. static bool
  1069. smb2_is_read_op(__u32 oplock)
  1070. {
  1071. return oplock == SMB2_OPLOCK_LEVEL_II;
  1072. }
  1073. static bool
  1074. smb21_is_read_op(__u32 oplock)
  1075. {
  1076. return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
  1077. !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
  1078. }
  1079. static __le32
  1080. map_oplock_to_lease(u8 oplock)
  1081. {
  1082. if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
  1083. return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
  1084. else if (oplock == SMB2_OPLOCK_LEVEL_II)
  1085. return SMB2_LEASE_READ_CACHING;
  1086. else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
  1087. return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
  1088. SMB2_LEASE_WRITE_CACHING;
  1089. return 0;
  1090. }
  1091. static char *
  1092. smb2_create_lease_buf(u8 *lease_key, u8 oplock)
  1093. {
  1094. struct create_lease *buf;
  1095. buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
  1096. if (!buf)
  1097. return NULL;
  1098. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  1099. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  1100. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  1101. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  1102. (struct create_lease, lcontext));
  1103. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
  1104. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  1105. (struct create_lease, Name));
  1106. buf->ccontext.NameLength = cpu_to_le16(4);
  1107. /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
  1108. buf->Name[0] = 'R';
  1109. buf->Name[1] = 'q';
  1110. buf->Name[2] = 'L';
  1111. buf->Name[3] = 's';
  1112. return (char *)buf;
  1113. }
  1114. static char *
  1115. smb3_create_lease_buf(u8 *lease_key, u8 oplock)
  1116. {
  1117. struct create_lease_v2 *buf;
  1118. buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
  1119. if (!buf)
  1120. return NULL;
  1121. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  1122. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  1123. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  1124. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  1125. (struct create_lease_v2, lcontext));
  1126. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
  1127. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  1128. (struct create_lease_v2, Name));
  1129. buf->ccontext.NameLength = cpu_to_le16(4);
  1130. /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
  1131. buf->Name[0] = 'R';
  1132. buf->Name[1] = 'q';
  1133. buf->Name[2] = 'L';
  1134. buf->Name[3] = 's';
  1135. return (char *)buf;
  1136. }
  1137. static __u8
  1138. smb2_parse_lease_buf(void *buf, unsigned int *epoch)
  1139. {
  1140. struct create_lease *lc = (struct create_lease *)buf;
  1141. *epoch = 0; /* not used */
  1142. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  1143. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  1144. return le32_to_cpu(lc->lcontext.LeaseState);
  1145. }
  1146. static __u8
  1147. smb3_parse_lease_buf(void *buf, unsigned int *epoch)
  1148. {
  1149. struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
  1150. *epoch = le16_to_cpu(lc->lcontext.Epoch);
  1151. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  1152. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  1153. return le32_to_cpu(lc->lcontext.LeaseState);
  1154. }
  1155. static unsigned int
  1156. smb2_wp_retry_size(struct inode *inode)
  1157. {
  1158. return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
  1159. SMB2_MAX_BUFFER_SIZE);
  1160. }
  1161. static bool
  1162. smb2_dir_needs_close(struct cifsFileInfo *cfile)
  1163. {
  1164. return !cfile->invalidHandle;
  1165. }
  1166. struct smb_version_operations smb20_operations = {
  1167. .compare_fids = smb2_compare_fids,
  1168. .setup_request = smb2_setup_request,
  1169. .setup_async_request = smb2_setup_async_request,
  1170. .check_receive = smb2_check_receive,
  1171. .add_credits = smb2_add_credits,
  1172. .set_credits = smb2_set_credits,
  1173. .get_credits_field = smb2_get_credits_field,
  1174. .get_credits = smb2_get_credits,
  1175. .wait_mtu_credits = cifs_wait_mtu_credits,
  1176. .get_next_mid = smb2_get_next_mid,
  1177. .read_data_offset = smb2_read_data_offset,
  1178. .read_data_length = smb2_read_data_length,
  1179. .map_error = map_smb2_to_linux_error,
  1180. .find_mid = smb2_find_mid,
  1181. .check_message = smb2_check_message,
  1182. .dump_detail = smb2_dump_detail,
  1183. .clear_stats = smb2_clear_stats,
  1184. .print_stats = smb2_print_stats,
  1185. .is_oplock_break = smb2_is_valid_oplock_break,
  1186. .downgrade_oplock = smb2_downgrade_oplock,
  1187. .need_neg = smb2_need_neg,
  1188. .negotiate = smb2_negotiate,
  1189. .negotiate_wsize = smb2_negotiate_wsize,
  1190. .negotiate_rsize = smb2_negotiate_rsize,
  1191. .sess_setup = SMB2_sess_setup,
  1192. .logoff = SMB2_logoff,
  1193. .tree_connect = SMB2_tcon,
  1194. .tree_disconnect = SMB2_tdis,
  1195. .qfs_tcon = smb2_qfs_tcon,
  1196. .is_path_accessible = smb2_is_path_accessible,
  1197. .can_echo = smb2_can_echo,
  1198. .echo = SMB2_echo,
  1199. .query_path_info = smb2_query_path_info,
  1200. .get_srv_inum = smb2_get_srv_inum,
  1201. .query_file_info = smb2_query_file_info,
  1202. .set_path_size = smb2_set_path_size,
  1203. .set_file_size = smb2_set_file_size,
  1204. .set_file_info = smb2_set_file_info,
  1205. .set_compression = smb2_set_compression,
  1206. .mkdir = smb2_mkdir,
  1207. .mkdir_setinfo = smb2_mkdir_setinfo,
  1208. .rmdir = smb2_rmdir,
  1209. .unlink = smb2_unlink,
  1210. .rename = smb2_rename_path,
  1211. .create_hardlink = smb2_create_hardlink,
  1212. .query_symlink = smb2_query_symlink,
  1213. .open = smb2_open_file,
  1214. .set_fid = smb2_set_fid,
  1215. .close = smb2_close_file,
  1216. .flush = smb2_flush_file,
  1217. .async_readv = smb2_async_readv,
  1218. .async_writev = smb2_async_writev,
  1219. .sync_read = smb2_sync_read,
  1220. .sync_write = smb2_sync_write,
  1221. .query_dir_first = smb2_query_dir_first,
  1222. .query_dir_next = smb2_query_dir_next,
  1223. .close_dir = smb2_close_dir,
  1224. .calc_smb_size = smb2_calc_size,
  1225. .is_status_pending = smb2_is_status_pending,
  1226. .oplock_response = smb2_oplock_response,
  1227. .queryfs = smb2_queryfs,
  1228. .mand_lock = smb2_mand_lock,
  1229. .mand_unlock_range = smb2_unlock_range,
  1230. .push_mand_locks = smb2_push_mandatory_locks,
  1231. .get_lease_key = smb2_get_lease_key,
  1232. .set_lease_key = smb2_set_lease_key,
  1233. .new_lease_key = smb2_new_lease_key,
  1234. .calc_signature = smb2_calc_signature,
  1235. .is_read_op = smb2_is_read_op,
  1236. .set_oplock_level = smb2_set_oplock_level,
  1237. .create_lease_buf = smb2_create_lease_buf,
  1238. .parse_lease_buf = smb2_parse_lease_buf,
  1239. .clone_range = smb2_clone_range,
  1240. .wp_retry_size = smb2_wp_retry_size,
  1241. .dir_needs_close = smb2_dir_needs_close,
  1242. };
  1243. struct smb_version_operations smb21_operations = {
  1244. .compare_fids = smb2_compare_fids,
  1245. .setup_request = smb2_setup_request,
  1246. .setup_async_request = smb2_setup_async_request,
  1247. .check_receive = smb2_check_receive,
  1248. .add_credits = smb2_add_credits,
  1249. .set_credits = smb2_set_credits,
  1250. .get_credits_field = smb2_get_credits_field,
  1251. .get_credits = smb2_get_credits,
  1252. .wait_mtu_credits = smb2_wait_mtu_credits,
  1253. .get_next_mid = smb2_get_next_mid,
  1254. .read_data_offset = smb2_read_data_offset,
  1255. .read_data_length = smb2_read_data_length,
  1256. .map_error = map_smb2_to_linux_error,
  1257. .find_mid = smb2_find_mid,
  1258. .check_message = smb2_check_message,
  1259. .dump_detail = smb2_dump_detail,
  1260. .clear_stats = smb2_clear_stats,
  1261. .print_stats = smb2_print_stats,
  1262. .is_oplock_break = smb2_is_valid_oplock_break,
  1263. .downgrade_oplock = smb2_downgrade_oplock,
  1264. .need_neg = smb2_need_neg,
  1265. .negotiate = smb2_negotiate,
  1266. .negotiate_wsize = smb2_negotiate_wsize,
  1267. .negotiate_rsize = smb2_negotiate_rsize,
  1268. .sess_setup = SMB2_sess_setup,
  1269. .logoff = SMB2_logoff,
  1270. .tree_connect = SMB2_tcon,
  1271. .tree_disconnect = SMB2_tdis,
  1272. .qfs_tcon = smb2_qfs_tcon,
  1273. .is_path_accessible = smb2_is_path_accessible,
  1274. .can_echo = smb2_can_echo,
  1275. .echo = SMB2_echo,
  1276. .query_path_info = smb2_query_path_info,
  1277. .get_srv_inum = smb2_get_srv_inum,
  1278. .query_file_info = smb2_query_file_info,
  1279. .set_path_size = smb2_set_path_size,
  1280. .set_file_size = smb2_set_file_size,
  1281. .set_file_info = smb2_set_file_info,
  1282. .set_compression = smb2_set_compression,
  1283. .mkdir = smb2_mkdir,
  1284. .mkdir_setinfo = smb2_mkdir_setinfo,
  1285. .rmdir = smb2_rmdir,
  1286. .unlink = smb2_unlink,
  1287. .rename = smb2_rename_path,
  1288. .create_hardlink = smb2_create_hardlink,
  1289. .query_symlink = smb2_query_symlink,
  1290. .query_mf_symlink = smb3_query_mf_symlink,
  1291. .create_mf_symlink = smb3_create_mf_symlink,
  1292. .open = smb2_open_file,
  1293. .set_fid = smb2_set_fid,
  1294. .close = smb2_close_file,
  1295. .flush = smb2_flush_file,
  1296. .async_readv = smb2_async_readv,
  1297. .async_writev = smb2_async_writev,
  1298. .sync_read = smb2_sync_read,
  1299. .sync_write = smb2_sync_write,
  1300. .query_dir_first = smb2_query_dir_first,
  1301. .query_dir_next = smb2_query_dir_next,
  1302. .close_dir = smb2_close_dir,
  1303. .calc_smb_size = smb2_calc_size,
  1304. .is_status_pending = smb2_is_status_pending,
  1305. .oplock_response = smb2_oplock_response,
  1306. .queryfs = smb2_queryfs,
  1307. .mand_lock = smb2_mand_lock,
  1308. .mand_unlock_range = smb2_unlock_range,
  1309. .push_mand_locks = smb2_push_mandatory_locks,
  1310. .get_lease_key = smb2_get_lease_key,
  1311. .set_lease_key = smb2_set_lease_key,
  1312. .new_lease_key = smb2_new_lease_key,
  1313. .calc_signature = smb2_calc_signature,
  1314. .is_read_op = smb21_is_read_op,
  1315. .set_oplock_level = smb21_set_oplock_level,
  1316. .create_lease_buf = smb2_create_lease_buf,
  1317. .parse_lease_buf = smb2_parse_lease_buf,
  1318. .clone_range = smb2_clone_range,
  1319. .wp_retry_size = smb2_wp_retry_size,
  1320. .dir_needs_close = smb2_dir_needs_close,
  1321. };
  1322. struct smb_version_operations smb30_operations = {
  1323. .compare_fids = smb2_compare_fids,
  1324. .setup_request = smb2_setup_request,
  1325. .setup_async_request = smb2_setup_async_request,
  1326. .check_receive = smb2_check_receive,
  1327. .add_credits = smb2_add_credits,
  1328. .set_credits = smb2_set_credits,
  1329. .get_credits_field = smb2_get_credits_field,
  1330. .get_credits = smb2_get_credits,
  1331. .wait_mtu_credits = smb2_wait_mtu_credits,
  1332. .get_next_mid = smb2_get_next_mid,
  1333. .read_data_offset = smb2_read_data_offset,
  1334. .read_data_length = smb2_read_data_length,
  1335. .map_error = map_smb2_to_linux_error,
  1336. .find_mid = smb2_find_mid,
  1337. .check_message = smb2_check_message,
  1338. .dump_detail = smb2_dump_detail,
  1339. .clear_stats = smb2_clear_stats,
  1340. .print_stats = smb2_print_stats,
  1341. .dump_share_caps = smb2_dump_share_caps,
  1342. .is_oplock_break = smb2_is_valid_oplock_break,
  1343. .downgrade_oplock = smb2_downgrade_oplock,
  1344. .need_neg = smb2_need_neg,
  1345. .negotiate = smb2_negotiate,
  1346. .negotiate_wsize = smb2_negotiate_wsize,
  1347. .negotiate_rsize = smb2_negotiate_rsize,
  1348. .sess_setup = SMB2_sess_setup,
  1349. .logoff = SMB2_logoff,
  1350. .tree_connect = SMB2_tcon,
  1351. .tree_disconnect = SMB2_tdis,
  1352. .qfs_tcon = smb3_qfs_tcon,
  1353. .is_path_accessible = smb2_is_path_accessible,
  1354. .can_echo = smb2_can_echo,
  1355. .echo = SMB2_echo,
  1356. .query_path_info = smb2_query_path_info,
  1357. .get_srv_inum = smb2_get_srv_inum,
  1358. .query_file_info = smb2_query_file_info,
  1359. .set_path_size = smb2_set_path_size,
  1360. .set_file_size = smb2_set_file_size,
  1361. .set_file_info = smb2_set_file_info,
  1362. .set_compression = smb2_set_compression,
  1363. .mkdir = smb2_mkdir,
  1364. .mkdir_setinfo = smb2_mkdir_setinfo,
  1365. .rmdir = smb2_rmdir,
  1366. .unlink = smb2_unlink,
  1367. .rename = smb2_rename_path,
  1368. .create_hardlink = smb2_create_hardlink,
  1369. .query_symlink = smb2_query_symlink,
  1370. .query_mf_symlink = smb3_query_mf_symlink,
  1371. .create_mf_symlink = smb3_create_mf_symlink,
  1372. .open = smb2_open_file,
  1373. .set_fid = smb2_set_fid,
  1374. .close = smb2_close_file,
  1375. .flush = smb2_flush_file,
  1376. .async_readv = smb2_async_readv,
  1377. .async_writev = smb2_async_writev,
  1378. .sync_read = smb2_sync_read,
  1379. .sync_write = smb2_sync_write,
  1380. .query_dir_first = smb2_query_dir_first,
  1381. .query_dir_next = smb2_query_dir_next,
  1382. .close_dir = smb2_close_dir,
  1383. .calc_smb_size = smb2_calc_size,
  1384. .is_status_pending = smb2_is_status_pending,
  1385. .oplock_response = smb2_oplock_response,
  1386. .queryfs = smb2_queryfs,
  1387. .mand_lock = smb2_mand_lock,
  1388. .mand_unlock_range = smb2_unlock_range,
  1389. .push_mand_locks = smb2_push_mandatory_locks,
  1390. .get_lease_key = smb2_get_lease_key,
  1391. .set_lease_key = smb2_set_lease_key,
  1392. .new_lease_key = smb2_new_lease_key,
  1393. .generate_signingkey = generate_smb3signingkey,
  1394. .calc_signature = smb3_calc_signature,
  1395. .is_read_op = smb21_is_read_op,
  1396. .set_oplock_level = smb3_set_oplock_level,
  1397. .create_lease_buf = smb3_create_lease_buf,
  1398. .parse_lease_buf = smb3_parse_lease_buf,
  1399. .clone_range = smb2_clone_range,
  1400. .validate_negotiate = smb3_validate_negotiate,
  1401. .wp_retry_size = smb2_wp_retry_size,
  1402. .dir_needs_close = smb2_dir_needs_close,
  1403. .fallocate = smb3_fallocate,
  1404. };
  1405. struct smb_version_values smb20_values = {
  1406. .version_string = SMB20_VERSION_STRING,
  1407. .protocol_id = SMB20_PROT_ID,
  1408. .req_capabilities = 0, /* MBZ */
  1409. .large_lock_type = 0,
  1410. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1411. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1412. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1413. .header_size = sizeof(struct smb2_hdr),
  1414. .max_header_size = MAX_SMB2_HDR_SIZE,
  1415. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1416. .lock_cmd = SMB2_LOCK,
  1417. .cap_unix = 0,
  1418. .cap_nt_find = SMB2_NT_FIND,
  1419. .cap_large_files = SMB2_LARGE_FILES,
  1420. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1421. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1422. .create_lease_size = sizeof(struct create_lease),
  1423. };
  1424. struct smb_version_values smb21_values = {
  1425. .version_string = SMB21_VERSION_STRING,
  1426. .protocol_id = SMB21_PROT_ID,
  1427. .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
  1428. .large_lock_type = 0,
  1429. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1430. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1431. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1432. .header_size = sizeof(struct smb2_hdr),
  1433. .max_header_size = MAX_SMB2_HDR_SIZE,
  1434. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1435. .lock_cmd = SMB2_LOCK,
  1436. .cap_unix = 0,
  1437. .cap_nt_find = SMB2_NT_FIND,
  1438. .cap_large_files = SMB2_LARGE_FILES,
  1439. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1440. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1441. .create_lease_size = sizeof(struct create_lease),
  1442. };
  1443. struct smb_version_values smb30_values = {
  1444. .version_string = SMB30_VERSION_STRING,
  1445. .protocol_id = SMB30_PROT_ID,
  1446. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1447. .large_lock_type = 0,
  1448. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1449. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1450. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1451. .header_size = sizeof(struct smb2_hdr),
  1452. .max_header_size = MAX_SMB2_HDR_SIZE,
  1453. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1454. .lock_cmd = SMB2_LOCK,
  1455. .cap_unix = 0,
  1456. .cap_nt_find = SMB2_NT_FIND,
  1457. .cap_large_files = SMB2_LARGE_FILES,
  1458. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1459. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1460. .create_lease_size = sizeof(struct create_lease_v2),
  1461. };
  1462. struct smb_version_values smb302_values = {
  1463. .version_string = SMB302_VERSION_STRING,
  1464. .protocol_id = SMB302_PROT_ID,
  1465. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1466. .large_lock_type = 0,
  1467. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1468. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1469. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1470. .header_size = sizeof(struct smb2_hdr),
  1471. .max_header_size = MAX_SMB2_HDR_SIZE,
  1472. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1473. .lock_cmd = SMB2_LOCK,
  1474. .cap_unix = 0,
  1475. .cap_nt_find = SMB2_NT_FIND,
  1476. .cap_large_files = SMB2_LARGE_FILES,
  1477. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1478. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1479. .create_lease_size = sizeof(struct create_lease_v2),
  1480. };