smb2ops.c 48 KB

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