smb2ops.c 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215
  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 <linux/scatterlist.h>
  23. #include <linux/uuid.h>
  24. #include <crypto/aead.h>
  25. #include "cifsglob.h"
  26. #include "smb2pdu.h"
  27. #include "smb2proto.h"
  28. #include "cifsproto.h"
  29. #include "cifs_debug.h"
  30. #include "cifs_unicode.h"
  31. #include "smb2status.h"
  32. #include "smb2glob.h"
  33. #include "cifs_ioctl.h"
  34. static int
  35. change_conf(struct TCP_Server_Info *server)
  36. {
  37. server->credits += server->echo_credits + server->oplock_credits;
  38. server->oplock_credits = server->echo_credits = 0;
  39. switch (server->credits) {
  40. case 0:
  41. return -1;
  42. case 1:
  43. server->echoes = false;
  44. server->oplocks = false;
  45. cifs_dbg(VFS, "disabling echoes and oplocks\n");
  46. break;
  47. case 2:
  48. server->echoes = true;
  49. server->oplocks = false;
  50. server->echo_credits = 1;
  51. cifs_dbg(FYI, "disabling oplocks\n");
  52. break;
  53. default:
  54. server->echoes = true;
  55. if (enable_oplocks) {
  56. server->oplocks = true;
  57. server->oplock_credits = 1;
  58. } else
  59. server->oplocks = false;
  60. server->echo_credits = 1;
  61. }
  62. server->credits -= server->echo_credits + server->oplock_credits;
  63. return 0;
  64. }
  65. static void
  66. smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
  67. const int optype)
  68. {
  69. int *val, rc = 0;
  70. spin_lock(&server->req_lock);
  71. val = server->ops->get_credits_field(server, optype);
  72. *val += add;
  73. if (*val > 65000) {
  74. *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
  75. printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
  76. }
  77. server->in_flight--;
  78. if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
  79. rc = change_conf(server);
  80. /*
  81. * Sometimes server returns 0 credits on oplock break ack - we need to
  82. * rebalance credits in this case.
  83. */
  84. else if (server->in_flight > 0 && server->oplock_credits == 0 &&
  85. server->oplocks) {
  86. if (server->credits > 1) {
  87. server->credits--;
  88. server->oplock_credits++;
  89. }
  90. }
  91. spin_unlock(&server->req_lock);
  92. wake_up(&server->request_q);
  93. if (rc)
  94. cifs_reconnect(server);
  95. }
  96. static void
  97. smb2_set_credits(struct TCP_Server_Info *server, const int val)
  98. {
  99. spin_lock(&server->req_lock);
  100. server->credits = val;
  101. spin_unlock(&server->req_lock);
  102. }
  103. static int *
  104. smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
  105. {
  106. switch (optype) {
  107. case CIFS_ECHO_OP:
  108. return &server->echo_credits;
  109. case CIFS_OBREAK_OP:
  110. return &server->oplock_credits;
  111. default:
  112. return &server->credits;
  113. }
  114. }
  115. static unsigned int
  116. smb2_get_credits(struct mid_q_entry *mid)
  117. {
  118. struct smb2_sync_hdr *shdr = get_sync_hdr(mid->resp_buf);
  119. return le16_to_cpu(shdr->CreditRequest);
  120. }
  121. static int
  122. smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
  123. unsigned int *num, unsigned int *credits)
  124. {
  125. int rc = 0;
  126. unsigned int scredits;
  127. spin_lock(&server->req_lock);
  128. while (1) {
  129. if (server->credits <= 0) {
  130. spin_unlock(&server->req_lock);
  131. cifs_num_waiters_inc(server);
  132. rc = wait_event_killable(server->request_q,
  133. has_credits(server, &server->credits));
  134. cifs_num_waiters_dec(server);
  135. if (rc)
  136. return rc;
  137. spin_lock(&server->req_lock);
  138. } else {
  139. if (server->tcpStatus == CifsExiting) {
  140. spin_unlock(&server->req_lock);
  141. return -ENOENT;
  142. }
  143. scredits = server->credits;
  144. /* can deadlock with reopen */
  145. if (scredits == 1) {
  146. *num = SMB2_MAX_BUFFER_SIZE;
  147. *credits = 0;
  148. break;
  149. }
  150. /* leave one credit for a possible reopen */
  151. scredits--;
  152. *num = min_t(unsigned int, size,
  153. scredits * SMB2_MAX_BUFFER_SIZE);
  154. *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
  155. server->credits -= *credits;
  156. server->in_flight++;
  157. break;
  158. }
  159. }
  160. spin_unlock(&server->req_lock);
  161. return rc;
  162. }
  163. static __u64
  164. smb2_get_next_mid(struct TCP_Server_Info *server)
  165. {
  166. __u64 mid;
  167. /* for SMB2 we need the current value */
  168. spin_lock(&GlobalMid_Lock);
  169. mid = server->CurrentMid++;
  170. spin_unlock(&GlobalMid_Lock);
  171. return mid;
  172. }
  173. static struct mid_q_entry *
  174. smb2_find_mid(struct TCP_Server_Info *server, char *buf)
  175. {
  176. struct mid_q_entry *mid;
  177. struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
  178. __u64 wire_mid = le64_to_cpu(shdr->MessageId);
  179. if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
  180. cifs_dbg(VFS, "encrypted frame parsing not supported yet");
  181. return NULL;
  182. }
  183. spin_lock(&GlobalMid_Lock);
  184. list_for_each_entry(mid, &server->pending_mid_q, qhead) {
  185. if ((mid->mid == wire_mid) &&
  186. (mid->mid_state == MID_REQUEST_SUBMITTED) &&
  187. (mid->command == shdr->Command)) {
  188. spin_unlock(&GlobalMid_Lock);
  189. return mid;
  190. }
  191. }
  192. spin_unlock(&GlobalMid_Lock);
  193. return NULL;
  194. }
  195. static void
  196. smb2_dump_detail(void *buf)
  197. {
  198. #ifdef CONFIG_CIFS_DEBUG2
  199. struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
  200. cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
  201. shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
  202. shdr->ProcessId);
  203. cifs_dbg(VFS, "smb buf %p len %u\n", buf, smb2_calc_size(buf));
  204. #endif
  205. }
  206. static bool
  207. smb2_need_neg(struct TCP_Server_Info *server)
  208. {
  209. return server->max_read == 0;
  210. }
  211. static int
  212. smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
  213. {
  214. int rc;
  215. ses->server->CurrentMid = 0;
  216. rc = SMB2_negotiate(xid, ses);
  217. /* BB we probably don't need to retry with modern servers */
  218. if (rc == -EAGAIN)
  219. rc = -EHOSTDOWN;
  220. return rc;
  221. }
  222. static unsigned int
  223. smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  224. {
  225. struct TCP_Server_Info *server = tcon->ses->server;
  226. unsigned int wsize;
  227. /* start with specified wsize, or default */
  228. wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
  229. wsize = min_t(unsigned int, wsize, server->max_write);
  230. if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
  231. wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
  232. return wsize;
  233. }
  234. static unsigned int
  235. smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  236. {
  237. struct TCP_Server_Info *server = tcon->ses->server;
  238. unsigned int rsize;
  239. /* start with specified rsize, or default */
  240. rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
  241. rsize = min_t(unsigned int, rsize, server->max_read);
  242. if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
  243. rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
  244. return rsize;
  245. }
  246. #ifdef CONFIG_CIFS_STATS2
  247. static int
  248. SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
  249. {
  250. int rc;
  251. unsigned int ret_data_len = 0;
  252. struct network_interface_info_ioctl_rsp *out_buf;
  253. rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
  254. FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
  255. false /* use_ipc */,
  256. NULL /* no data input */, 0 /* no data input */,
  257. (char **)&out_buf, &ret_data_len);
  258. if (rc != 0)
  259. cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
  260. else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
  261. cifs_dbg(VFS, "server returned bad net interface info buf\n");
  262. rc = -EINVAL;
  263. } else {
  264. /* Dump info on first interface */
  265. cifs_dbg(FYI, "Adapter Capability 0x%x\t",
  266. le32_to_cpu(out_buf->Capability));
  267. cifs_dbg(FYI, "Link Speed %lld\n",
  268. le64_to_cpu(out_buf->LinkSpeed));
  269. }
  270. kfree(out_buf);
  271. return rc;
  272. }
  273. #endif /* STATS2 */
  274. static void
  275. smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  276. {
  277. int rc;
  278. __le16 srch_path = 0; /* Null - open root of share */
  279. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  280. struct cifs_open_parms oparms;
  281. struct cifs_fid fid;
  282. oparms.tcon = tcon;
  283. oparms.desired_access = FILE_READ_ATTRIBUTES;
  284. oparms.disposition = FILE_OPEN;
  285. oparms.create_options = 0;
  286. oparms.fid = &fid;
  287. oparms.reconnect = false;
  288. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  289. if (rc)
  290. return;
  291. #ifdef CONFIG_CIFS_STATS2
  292. SMB3_request_interfaces(xid, tcon);
  293. #endif /* STATS2 */
  294. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  295. FS_ATTRIBUTE_INFORMATION);
  296. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  297. FS_DEVICE_INFORMATION);
  298. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  299. FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
  300. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  301. return;
  302. }
  303. static void
  304. smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  305. {
  306. int rc;
  307. __le16 srch_path = 0; /* Null - open root of share */
  308. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  309. struct cifs_open_parms oparms;
  310. struct cifs_fid fid;
  311. oparms.tcon = tcon;
  312. oparms.desired_access = FILE_READ_ATTRIBUTES;
  313. oparms.disposition = FILE_OPEN;
  314. oparms.create_options = 0;
  315. oparms.fid = &fid;
  316. oparms.reconnect = false;
  317. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  318. if (rc)
  319. return;
  320. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  321. FS_ATTRIBUTE_INFORMATION);
  322. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  323. FS_DEVICE_INFORMATION);
  324. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  325. return;
  326. }
  327. static int
  328. smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
  329. struct cifs_sb_info *cifs_sb, const char *full_path)
  330. {
  331. int rc;
  332. __le16 *utf16_path;
  333. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  334. struct cifs_open_parms oparms;
  335. struct cifs_fid fid;
  336. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  337. if (!utf16_path)
  338. return -ENOMEM;
  339. oparms.tcon = tcon;
  340. oparms.desired_access = FILE_READ_ATTRIBUTES;
  341. oparms.disposition = FILE_OPEN;
  342. oparms.create_options = 0;
  343. oparms.fid = &fid;
  344. oparms.reconnect = false;
  345. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  346. if (rc) {
  347. kfree(utf16_path);
  348. return rc;
  349. }
  350. rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  351. kfree(utf16_path);
  352. return rc;
  353. }
  354. static int
  355. smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
  356. struct cifs_sb_info *cifs_sb, const char *full_path,
  357. u64 *uniqueid, FILE_ALL_INFO *data)
  358. {
  359. *uniqueid = le64_to_cpu(data->IndexNumber);
  360. return 0;
  361. }
  362. static int
  363. smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
  364. struct cifs_fid *fid, FILE_ALL_INFO *data)
  365. {
  366. int rc;
  367. struct smb2_file_all_info *smb2_data;
  368. smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
  369. GFP_KERNEL);
  370. if (smb2_data == NULL)
  371. return -ENOMEM;
  372. rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
  373. smb2_data);
  374. if (!rc)
  375. move_smb2_info_to_cifs(data, smb2_data);
  376. kfree(smb2_data);
  377. return rc;
  378. }
  379. #ifdef CONFIG_CIFS_XATTR
  380. static ssize_t
  381. move_smb2_ea_to_cifs(char *dst, size_t dst_size,
  382. struct smb2_file_full_ea_info *src, size_t src_size,
  383. const unsigned char *ea_name)
  384. {
  385. int rc = 0;
  386. unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
  387. char *name, *value;
  388. size_t name_len, value_len, user_name_len;
  389. while (src_size > 0) {
  390. name = &src->ea_data[0];
  391. name_len = (size_t)src->ea_name_length;
  392. value = &src->ea_data[src->ea_name_length + 1];
  393. value_len = (size_t)le16_to_cpu(src->ea_value_length);
  394. if (name_len == 0) {
  395. break;
  396. }
  397. if (src_size < 8 + name_len + 1 + value_len) {
  398. cifs_dbg(FYI, "EA entry goes beyond length of list\n");
  399. rc = -EIO;
  400. goto out;
  401. }
  402. if (ea_name) {
  403. if (ea_name_len == name_len &&
  404. memcmp(ea_name, name, name_len) == 0) {
  405. rc = value_len;
  406. if (dst_size == 0)
  407. goto out;
  408. if (dst_size < value_len) {
  409. rc = -ERANGE;
  410. goto out;
  411. }
  412. memcpy(dst, value, value_len);
  413. goto out;
  414. }
  415. } else {
  416. /* 'user.' plus a terminating null */
  417. user_name_len = 5 + 1 + name_len;
  418. rc += user_name_len;
  419. if (dst_size >= user_name_len) {
  420. dst_size -= user_name_len;
  421. memcpy(dst, "user.", 5);
  422. dst += 5;
  423. memcpy(dst, src->ea_data, name_len);
  424. dst += name_len;
  425. *dst = 0;
  426. ++dst;
  427. } else if (dst_size == 0) {
  428. /* skip copy - calc size only */
  429. } else {
  430. /* stop before overrun buffer */
  431. rc = -ERANGE;
  432. break;
  433. }
  434. }
  435. if (!src->next_entry_offset)
  436. break;
  437. if (src_size < le32_to_cpu(src->next_entry_offset)) {
  438. /* stop before overrun buffer */
  439. rc = -ERANGE;
  440. break;
  441. }
  442. src_size -= le32_to_cpu(src->next_entry_offset);
  443. src = (void *)((char *)src +
  444. le32_to_cpu(src->next_entry_offset));
  445. }
  446. /* didn't find the named attribute */
  447. if (ea_name)
  448. rc = -ENODATA;
  449. out:
  450. return (ssize_t)rc;
  451. }
  452. static ssize_t
  453. smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
  454. const unsigned char *path, const unsigned char *ea_name,
  455. char *ea_data, size_t buf_size,
  456. struct cifs_sb_info *cifs_sb)
  457. {
  458. int rc;
  459. __le16 *utf16_path;
  460. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  461. struct cifs_open_parms oparms;
  462. struct cifs_fid fid;
  463. struct smb2_file_full_ea_info *smb2_data;
  464. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  465. if (!utf16_path)
  466. return -ENOMEM;
  467. oparms.tcon = tcon;
  468. oparms.desired_access = FILE_READ_EA;
  469. oparms.disposition = FILE_OPEN;
  470. oparms.create_options = 0;
  471. oparms.fid = &fid;
  472. oparms.reconnect = false;
  473. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  474. kfree(utf16_path);
  475. if (rc) {
  476. cifs_dbg(FYI, "open failed rc=%d\n", rc);
  477. return rc;
  478. }
  479. smb2_data = kzalloc(SMB2_MAX_EA_BUF, GFP_KERNEL);
  480. if (smb2_data == NULL) {
  481. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  482. return -ENOMEM;
  483. }
  484. rc = SMB2_query_eas(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  485. smb2_data);
  486. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  487. if (!rc)
  488. rc = move_smb2_ea_to_cifs(ea_data, buf_size, smb2_data,
  489. SMB2_MAX_EA_BUF, ea_name);
  490. kfree(smb2_data);
  491. return rc;
  492. }
  493. static int
  494. smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
  495. const char *path, const char *ea_name, const void *ea_value,
  496. const __u16 ea_value_len, const struct nls_table *nls_codepage,
  497. struct cifs_sb_info *cifs_sb)
  498. {
  499. int rc;
  500. __le16 *utf16_path;
  501. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  502. struct cifs_open_parms oparms;
  503. struct cifs_fid fid;
  504. struct smb2_file_full_ea_info *ea;
  505. int ea_name_len = strlen(ea_name);
  506. int len;
  507. if (ea_name_len > 255)
  508. return -EINVAL;
  509. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  510. if (!utf16_path)
  511. return -ENOMEM;
  512. oparms.tcon = tcon;
  513. oparms.desired_access = FILE_WRITE_EA;
  514. oparms.disposition = FILE_OPEN;
  515. oparms.create_options = 0;
  516. oparms.fid = &fid;
  517. oparms.reconnect = false;
  518. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  519. kfree(utf16_path);
  520. if (rc) {
  521. cifs_dbg(FYI, "open failed rc=%d\n", rc);
  522. return rc;
  523. }
  524. len = sizeof(ea) + ea_name_len + ea_value_len + 1;
  525. ea = kzalloc(len, GFP_KERNEL);
  526. if (ea == NULL) {
  527. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  528. return -ENOMEM;
  529. }
  530. ea->ea_name_length = ea_name_len;
  531. ea->ea_value_length = cpu_to_le16(ea_value_len);
  532. memcpy(ea->ea_data, ea_name, ea_name_len + 1);
  533. memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
  534. rc = SMB2_set_ea(xid, tcon, fid.persistent_fid, fid.volatile_fid, ea,
  535. len);
  536. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  537. return rc;
  538. }
  539. #endif
  540. static bool
  541. smb2_can_echo(struct TCP_Server_Info *server)
  542. {
  543. return server->echoes;
  544. }
  545. static void
  546. smb2_clear_stats(struct cifs_tcon *tcon)
  547. {
  548. #ifdef CONFIG_CIFS_STATS
  549. int i;
  550. for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
  551. atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
  552. atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
  553. }
  554. #endif
  555. }
  556. static void
  557. smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
  558. {
  559. seq_puts(m, "\n\tShare Capabilities:");
  560. if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
  561. seq_puts(m, " DFS,");
  562. if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
  563. seq_puts(m, " CONTINUOUS AVAILABILITY,");
  564. if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
  565. seq_puts(m, " SCALEOUT,");
  566. if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
  567. seq_puts(m, " CLUSTER,");
  568. if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
  569. seq_puts(m, " ASYMMETRIC,");
  570. if (tcon->capabilities == 0)
  571. seq_puts(m, " None");
  572. if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
  573. seq_puts(m, " Aligned,");
  574. if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
  575. seq_puts(m, " Partition Aligned,");
  576. if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
  577. seq_puts(m, " SSD,");
  578. if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
  579. seq_puts(m, " TRIM-support,");
  580. seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
  581. if (tcon->perf_sector_size)
  582. seq_printf(m, "\tOptimal sector size: 0x%x",
  583. tcon->perf_sector_size);
  584. }
  585. static void
  586. smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
  587. {
  588. #ifdef CONFIG_CIFS_STATS
  589. atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
  590. atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
  591. seq_printf(m, "\nNegotiates: %d sent %d failed",
  592. atomic_read(&sent[SMB2_NEGOTIATE_HE]),
  593. atomic_read(&failed[SMB2_NEGOTIATE_HE]));
  594. seq_printf(m, "\nSessionSetups: %d sent %d failed",
  595. atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
  596. atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
  597. seq_printf(m, "\nLogoffs: %d sent %d failed",
  598. atomic_read(&sent[SMB2_LOGOFF_HE]),
  599. atomic_read(&failed[SMB2_LOGOFF_HE]));
  600. seq_printf(m, "\nTreeConnects: %d sent %d failed",
  601. atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
  602. atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
  603. seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
  604. atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
  605. atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
  606. seq_printf(m, "\nCreates: %d sent %d failed",
  607. atomic_read(&sent[SMB2_CREATE_HE]),
  608. atomic_read(&failed[SMB2_CREATE_HE]));
  609. seq_printf(m, "\nCloses: %d sent %d failed",
  610. atomic_read(&sent[SMB2_CLOSE_HE]),
  611. atomic_read(&failed[SMB2_CLOSE_HE]));
  612. seq_printf(m, "\nFlushes: %d sent %d failed",
  613. atomic_read(&sent[SMB2_FLUSH_HE]),
  614. atomic_read(&failed[SMB2_FLUSH_HE]));
  615. seq_printf(m, "\nReads: %d sent %d failed",
  616. atomic_read(&sent[SMB2_READ_HE]),
  617. atomic_read(&failed[SMB2_READ_HE]));
  618. seq_printf(m, "\nWrites: %d sent %d failed",
  619. atomic_read(&sent[SMB2_WRITE_HE]),
  620. atomic_read(&failed[SMB2_WRITE_HE]));
  621. seq_printf(m, "\nLocks: %d sent %d failed",
  622. atomic_read(&sent[SMB2_LOCK_HE]),
  623. atomic_read(&failed[SMB2_LOCK_HE]));
  624. seq_printf(m, "\nIOCTLs: %d sent %d failed",
  625. atomic_read(&sent[SMB2_IOCTL_HE]),
  626. atomic_read(&failed[SMB2_IOCTL_HE]));
  627. seq_printf(m, "\nCancels: %d sent %d failed",
  628. atomic_read(&sent[SMB2_CANCEL_HE]),
  629. atomic_read(&failed[SMB2_CANCEL_HE]));
  630. seq_printf(m, "\nEchos: %d sent %d failed",
  631. atomic_read(&sent[SMB2_ECHO_HE]),
  632. atomic_read(&failed[SMB2_ECHO_HE]));
  633. seq_printf(m, "\nQueryDirectories: %d sent %d failed",
  634. atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
  635. atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
  636. seq_printf(m, "\nChangeNotifies: %d sent %d failed",
  637. atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
  638. atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
  639. seq_printf(m, "\nQueryInfos: %d sent %d failed",
  640. atomic_read(&sent[SMB2_QUERY_INFO_HE]),
  641. atomic_read(&failed[SMB2_QUERY_INFO_HE]));
  642. seq_printf(m, "\nSetInfos: %d sent %d failed",
  643. atomic_read(&sent[SMB2_SET_INFO_HE]),
  644. atomic_read(&failed[SMB2_SET_INFO_HE]));
  645. seq_printf(m, "\nOplockBreaks: %d sent %d failed",
  646. atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
  647. atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
  648. #endif
  649. }
  650. static void
  651. smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
  652. {
  653. struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
  654. struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
  655. cfile->fid.persistent_fid = fid->persistent_fid;
  656. cfile->fid.volatile_fid = fid->volatile_fid;
  657. server->ops->set_oplock_level(cinode, oplock, fid->epoch,
  658. &fid->purge_cache);
  659. cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
  660. memcpy(cfile->fid.create_guid, fid->create_guid, 16);
  661. }
  662. static void
  663. smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
  664. struct cifs_fid *fid)
  665. {
  666. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  667. }
  668. static int
  669. SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
  670. u64 persistent_fid, u64 volatile_fid,
  671. struct copychunk_ioctl *pcchunk)
  672. {
  673. int rc;
  674. unsigned int ret_data_len;
  675. struct resume_key_req *res_key;
  676. rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
  677. FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
  678. false /* use_ipc */,
  679. NULL, 0 /* no input */,
  680. (char **)&res_key, &ret_data_len);
  681. if (rc) {
  682. cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
  683. goto req_res_key_exit;
  684. }
  685. if (ret_data_len < sizeof(struct resume_key_req)) {
  686. cifs_dbg(VFS, "Invalid refcopy resume key length\n");
  687. rc = -EINVAL;
  688. goto req_res_key_exit;
  689. }
  690. memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
  691. req_res_key_exit:
  692. kfree(res_key);
  693. return rc;
  694. }
  695. static ssize_t
  696. smb2_copychunk_range(const unsigned int xid,
  697. struct cifsFileInfo *srcfile,
  698. struct cifsFileInfo *trgtfile, u64 src_off,
  699. u64 len, u64 dest_off)
  700. {
  701. int rc;
  702. unsigned int ret_data_len;
  703. struct copychunk_ioctl *pcchunk;
  704. struct copychunk_ioctl_rsp *retbuf = NULL;
  705. struct cifs_tcon *tcon;
  706. int chunks_copied = 0;
  707. bool chunk_sizes_updated = false;
  708. ssize_t bytes_written, total_bytes_written = 0;
  709. pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
  710. if (pcchunk == NULL)
  711. return -ENOMEM;
  712. cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
  713. /* Request a key from the server to identify the source of the copy */
  714. rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
  715. srcfile->fid.persistent_fid,
  716. srcfile->fid.volatile_fid, pcchunk);
  717. /* Note: request_res_key sets res_key null only if rc !=0 */
  718. if (rc)
  719. goto cchunk_out;
  720. /* For now array only one chunk long, will make more flexible later */
  721. pcchunk->ChunkCount = cpu_to_le32(1);
  722. pcchunk->Reserved = 0;
  723. pcchunk->Reserved2 = 0;
  724. tcon = tlink_tcon(trgtfile->tlink);
  725. while (len > 0) {
  726. pcchunk->SourceOffset = cpu_to_le64(src_off);
  727. pcchunk->TargetOffset = cpu_to_le64(dest_off);
  728. pcchunk->Length =
  729. cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
  730. /* Request server copy to target from src identified by key */
  731. rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
  732. trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
  733. true /* is_fsctl */, false /* use_ipc */,
  734. (char *)pcchunk,
  735. sizeof(struct copychunk_ioctl), (char **)&retbuf,
  736. &ret_data_len);
  737. if (rc == 0) {
  738. if (ret_data_len !=
  739. sizeof(struct copychunk_ioctl_rsp)) {
  740. cifs_dbg(VFS, "invalid cchunk response size\n");
  741. rc = -EIO;
  742. goto cchunk_out;
  743. }
  744. if (retbuf->TotalBytesWritten == 0) {
  745. cifs_dbg(FYI, "no bytes copied\n");
  746. rc = -EIO;
  747. goto cchunk_out;
  748. }
  749. /*
  750. * Check if server claimed to write more than we asked
  751. */
  752. if (le32_to_cpu(retbuf->TotalBytesWritten) >
  753. le32_to_cpu(pcchunk->Length)) {
  754. cifs_dbg(VFS, "invalid copy chunk response\n");
  755. rc = -EIO;
  756. goto cchunk_out;
  757. }
  758. if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
  759. cifs_dbg(VFS, "invalid num chunks written\n");
  760. rc = -EIO;
  761. goto cchunk_out;
  762. }
  763. chunks_copied++;
  764. bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
  765. src_off += bytes_written;
  766. dest_off += bytes_written;
  767. len -= bytes_written;
  768. total_bytes_written += bytes_written;
  769. cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
  770. le32_to_cpu(retbuf->ChunksWritten),
  771. le32_to_cpu(retbuf->ChunkBytesWritten),
  772. bytes_written);
  773. } else if (rc == -EINVAL) {
  774. if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
  775. goto cchunk_out;
  776. cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
  777. le32_to_cpu(retbuf->ChunksWritten),
  778. le32_to_cpu(retbuf->ChunkBytesWritten),
  779. le32_to_cpu(retbuf->TotalBytesWritten));
  780. /*
  781. * Check if this is the first request using these sizes,
  782. * (ie check if copy succeed once with original sizes
  783. * and check if the server gave us different sizes after
  784. * we already updated max sizes on previous request).
  785. * if not then why is the server returning an error now
  786. */
  787. if ((chunks_copied != 0) || chunk_sizes_updated)
  788. goto cchunk_out;
  789. /* Check that server is not asking us to grow size */
  790. if (le32_to_cpu(retbuf->ChunkBytesWritten) <
  791. tcon->max_bytes_chunk)
  792. tcon->max_bytes_chunk =
  793. le32_to_cpu(retbuf->ChunkBytesWritten);
  794. else
  795. goto cchunk_out; /* server gave us bogus size */
  796. /* No need to change MaxChunks since already set to 1 */
  797. chunk_sizes_updated = true;
  798. } else
  799. goto cchunk_out;
  800. }
  801. cchunk_out:
  802. kfree(pcchunk);
  803. kfree(retbuf);
  804. if (rc)
  805. return rc;
  806. else
  807. return total_bytes_written;
  808. }
  809. static int
  810. smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
  811. struct cifs_fid *fid)
  812. {
  813. return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  814. }
  815. static unsigned int
  816. smb2_read_data_offset(char *buf)
  817. {
  818. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  819. return rsp->DataOffset;
  820. }
  821. static unsigned int
  822. smb2_read_data_length(char *buf)
  823. {
  824. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  825. return le32_to_cpu(rsp->DataLength);
  826. }
  827. static int
  828. smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
  829. struct cifs_io_parms *parms, unsigned int *bytes_read,
  830. char **buf, int *buf_type)
  831. {
  832. parms->persistent_fid = pfid->persistent_fid;
  833. parms->volatile_fid = pfid->volatile_fid;
  834. return SMB2_read(xid, parms, bytes_read, buf, buf_type);
  835. }
  836. static int
  837. smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
  838. struct cifs_io_parms *parms, unsigned int *written,
  839. struct kvec *iov, unsigned long nr_segs)
  840. {
  841. parms->persistent_fid = pfid->persistent_fid;
  842. parms->volatile_fid = pfid->volatile_fid;
  843. return SMB2_write(xid, parms, written, iov, nr_segs);
  844. }
  845. /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
  846. static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
  847. struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
  848. {
  849. struct cifsInodeInfo *cifsi;
  850. int rc;
  851. cifsi = CIFS_I(inode);
  852. /* if file already sparse don't bother setting sparse again */
  853. if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
  854. return true; /* already sparse */
  855. if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
  856. return true; /* already not sparse */
  857. /*
  858. * Can't check for sparse support on share the usual way via the
  859. * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
  860. * since Samba server doesn't set the flag on the share, yet
  861. * supports the set sparse FSCTL and returns sparse correctly
  862. * in the file attributes. If we fail setting sparse though we
  863. * mark that server does not support sparse files for this share
  864. * to avoid repeatedly sending the unsupported fsctl to server
  865. * if the file is repeatedly extended.
  866. */
  867. if (tcon->broken_sparse_sup)
  868. return false;
  869. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  870. cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
  871. true /* is_fctl */, false /* use_ipc */,
  872. &setsparse, 1, NULL, NULL);
  873. if (rc) {
  874. tcon->broken_sparse_sup = true;
  875. cifs_dbg(FYI, "set sparse rc = %d\n", rc);
  876. return false;
  877. }
  878. if (setsparse)
  879. cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
  880. else
  881. cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
  882. return true;
  883. }
  884. static int
  885. smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
  886. struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
  887. {
  888. __le64 eof = cpu_to_le64(size);
  889. struct inode *inode;
  890. /*
  891. * If extending file more than one page make sparse. Many Linux fs
  892. * make files sparse by default when extending via ftruncate
  893. */
  894. inode = d_inode(cfile->dentry);
  895. if (!set_alloc && (size > inode->i_size + 8192)) {
  896. __u8 set_sparse = 1;
  897. /* whether set sparse succeeds or not, extend the file */
  898. smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
  899. }
  900. return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
  901. cfile->fid.volatile_fid, cfile->pid, &eof, false);
  902. }
  903. static int
  904. smb2_duplicate_extents(const unsigned int xid,
  905. struct cifsFileInfo *srcfile,
  906. struct cifsFileInfo *trgtfile, u64 src_off,
  907. u64 len, u64 dest_off)
  908. {
  909. int rc;
  910. unsigned int ret_data_len;
  911. struct duplicate_extents_to_file dup_ext_buf;
  912. struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
  913. /* server fileays advertise duplicate extent support with this flag */
  914. if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
  915. FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
  916. return -EOPNOTSUPP;
  917. dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
  918. dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
  919. dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
  920. dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
  921. dup_ext_buf.ByteCount = cpu_to_le64(len);
  922. cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
  923. src_off, dest_off, len);
  924. rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
  925. if (rc)
  926. goto duplicate_extents_out;
  927. rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
  928. trgtfile->fid.volatile_fid,
  929. FSCTL_DUPLICATE_EXTENTS_TO_FILE,
  930. true /* is_fsctl */, false /* use_ipc */,
  931. (char *)&dup_ext_buf,
  932. sizeof(struct duplicate_extents_to_file),
  933. NULL,
  934. &ret_data_len);
  935. if (ret_data_len > 0)
  936. cifs_dbg(FYI, "non-zero response length in duplicate extents");
  937. duplicate_extents_out:
  938. return rc;
  939. }
  940. static int
  941. smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
  942. struct cifsFileInfo *cfile)
  943. {
  944. return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
  945. cfile->fid.volatile_fid);
  946. }
  947. static int
  948. smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
  949. struct cifsFileInfo *cfile)
  950. {
  951. struct fsctl_set_integrity_information_req integr_info;
  952. unsigned int ret_data_len;
  953. integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
  954. integr_info.Flags = 0;
  955. integr_info.Reserved = 0;
  956. return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  957. cfile->fid.volatile_fid,
  958. FSCTL_SET_INTEGRITY_INFORMATION,
  959. true /* is_fsctl */, false /* use_ipc */,
  960. (char *)&integr_info,
  961. sizeof(struct fsctl_set_integrity_information_req),
  962. NULL,
  963. &ret_data_len);
  964. }
  965. static int
  966. smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
  967. struct cifsFileInfo *cfile, void __user *ioc_buf)
  968. {
  969. char *retbuf = NULL;
  970. unsigned int ret_data_len = 0;
  971. int rc;
  972. struct smb_snapshot_array snapshot_in;
  973. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  974. cfile->fid.volatile_fid,
  975. FSCTL_SRV_ENUMERATE_SNAPSHOTS,
  976. true /* is_fsctl */, false /* use_ipc */,
  977. NULL, 0 /* no input data */,
  978. (char **)&retbuf,
  979. &ret_data_len);
  980. cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
  981. rc, ret_data_len);
  982. if (rc)
  983. return rc;
  984. if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
  985. /* Fixup buffer */
  986. if (copy_from_user(&snapshot_in, ioc_buf,
  987. sizeof(struct smb_snapshot_array))) {
  988. rc = -EFAULT;
  989. kfree(retbuf);
  990. return rc;
  991. }
  992. if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) {
  993. rc = -ERANGE;
  994. kfree(retbuf);
  995. return rc;
  996. }
  997. if (ret_data_len > snapshot_in.snapshot_array_size)
  998. ret_data_len = snapshot_in.snapshot_array_size;
  999. if (copy_to_user(ioc_buf, retbuf, ret_data_len))
  1000. rc = -EFAULT;
  1001. }
  1002. kfree(retbuf);
  1003. return rc;
  1004. }
  1005. static int
  1006. smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
  1007. const char *path, struct cifs_sb_info *cifs_sb,
  1008. struct cifs_fid *fid, __u16 search_flags,
  1009. struct cifs_search_info *srch_inf)
  1010. {
  1011. __le16 *utf16_path;
  1012. int rc;
  1013. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1014. struct cifs_open_parms oparms;
  1015. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  1016. if (!utf16_path)
  1017. return -ENOMEM;
  1018. oparms.tcon = tcon;
  1019. oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
  1020. oparms.disposition = FILE_OPEN;
  1021. oparms.create_options = 0;
  1022. oparms.fid = fid;
  1023. oparms.reconnect = false;
  1024. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  1025. kfree(utf16_path);
  1026. if (rc) {
  1027. cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
  1028. return rc;
  1029. }
  1030. srch_inf->entries_in_buffer = 0;
  1031. srch_inf->index_of_last_entry = 0;
  1032. rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
  1033. fid->volatile_fid, 0, srch_inf);
  1034. if (rc) {
  1035. cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
  1036. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  1037. }
  1038. return rc;
  1039. }
  1040. static int
  1041. smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
  1042. struct cifs_fid *fid, __u16 search_flags,
  1043. struct cifs_search_info *srch_inf)
  1044. {
  1045. return SMB2_query_directory(xid, tcon, fid->persistent_fid,
  1046. fid->volatile_fid, 0, srch_inf);
  1047. }
  1048. static int
  1049. smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
  1050. struct cifs_fid *fid)
  1051. {
  1052. return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  1053. }
  1054. /*
  1055. * If we negotiate SMB2 protocol and get STATUS_PENDING - update
  1056. * the number of credits and return true. Otherwise - return false.
  1057. */
  1058. static bool
  1059. smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
  1060. {
  1061. struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
  1062. if (shdr->Status != STATUS_PENDING)
  1063. return false;
  1064. if (!length) {
  1065. spin_lock(&server->req_lock);
  1066. server->credits += le16_to_cpu(shdr->CreditRequest);
  1067. spin_unlock(&server->req_lock);
  1068. wake_up(&server->request_q);
  1069. }
  1070. return true;
  1071. }
  1072. static bool
  1073. smb2_is_session_expired(char *buf)
  1074. {
  1075. struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
  1076. if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED)
  1077. return false;
  1078. cifs_dbg(FYI, "Session expired\n");
  1079. return true;
  1080. }
  1081. static int
  1082. smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
  1083. struct cifsInodeInfo *cinode)
  1084. {
  1085. if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
  1086. return SMB2_lease_break(0, tcon, cinode->lease_key,
  1087. smb2_get_lease_state(cinode));
  1088. return SMB2_oplock_break(0, tcon, fid->persistent_fid,
  1089. fid->volatile_fid,
  1090. CIFS_CACHE_READ(cinode) ? 1 : 0);
  1091. }
  1092. static int
  1093. smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
  1094. struct kstatfs *buf)
  1095. {
  1096. int rc;
  1097. __le16 srch_path = 0; /* Null - open root of share */
  1098. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1099. struct cifs_open_parms oparms;
  1100. struct cifs_fid fid;
  1101. oparms.tcon = tcon;
  1102. oparms.desired_access = FILE_READ_ATTRIBUTES;
  1103. oparms.disposition = FILE_OPEN;
  1104. oparms.create_options = 0;
  1105. oparms.fid = &fid;
  1106. oparms.reconnect = false;
  1107. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  1108. if (rc)
  1109. return rc;
  1110. buf->f_type = SMB2_MAGIC_NUMBER;
  1111. rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  1112. buf);
  1113. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  1114. return rc;
  1115. }
  1116. static bool
  1117. smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  1118. {
  1119. return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
  1120. ob1->fid.volatile_fid == ob2->fid.volatile_fid;
  1121. }
  1122. static int
  1123. smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
  1124. __u64 length, __u32 type, int lock, int unlock, bool wait)
  1125. {
  1126. if (unlock && !lock)
  1127. type = SMB2_LOCKFLAG_UNLOCK;
  1128. return SMB2_lock(xid, tlink_tcon(cfile->tlink),
  1129. cfile->fid.persistent_fid, cfile->fid.volatile_fid,
  1130. current->tgid, length, offset, type, wait);
  1131. }
  1132. static void
  1133. smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
  1134. {
  1135. memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
  1136. }
  1137. static void
  1138. smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
  1139. {
  1140. memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
  1141. }
  1142. static void
  1143. smb2_new_lease_key(struct cifs_fid *fid)
  1144. {
  1145. generate_random_uuid(fid->lease_key);
  1146. }
  1147. static int
  1148. smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
  1149. const char *search_name,
  1150. struct dfs_info3_param **target_nodes,
  1151. unsigned int *num_of_nodes,
  1152. const struct nls_table *nls_codepage, int remap)
  1153. {
  1154. int rc;
  1155. __le16 *utf16_path = NULL;
  1156. int utf16_path_len = 0;
  1157. struct cifs_tcon *tcon;
  1158. struct fsctl_get_dfs_referral_req *dfs_req = NULL;
  1159. struct get_dfs_referral_rsp *dfs_rsp = NULL;
  1160. u32 dfs_req_size = 0, dfs_rsp_size = 0;
  1161. cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
  1162. /*
  1163. * Use any tcon from the current session. Here, the first one.
  1164. */
  1165. spin_lock(&cifs_tcp_ses_lock);
  1166. tcon = list_first_entry_or_null(&ses->tcon_list, struct cifs_tcon,
  1167. tcon_list);
  1168. if (tcon)
  1169. tcon->tc_count++;
  1170. spin_unlock(&cifs_tcp_ses_lock);
  1171. if (!tcon) {
  1172. cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
  1173. ses);
  1174. rc = -ENOTCONN;
  1175. goto out;
  1176. }
  1177. utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
  1178. &utf16_path_len,
  1179. nls_codepage, remap);
  1180. if (!utf16_path) {
  1181. rc = -ENOMEM;
  1182. goto out;
  1183. }
  1184. dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
  1185. dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
  1186. if (!dfs_req) {
  1187. rc = -ENOMEM;
  1188. goto out;
  1189. }
  1190. /* Highest DFS referral version understood */
  1191. dfs_req->MaxReferralLevel = DFS_VERSION;
  1192. /* Path to resolve in an UTF-16 null-terminated string */
  1193. memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
  1194. do {
  1195. /* try first with IPC */
  1196. rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
  1197. FSCTL_DFS_GET_REFERRALS,
  1198. true /* is_fsctl */, true /* use_ipc */,
  1199. (char *)dfs_req, dfs_req_size,
  1200. (char **)&dfs_rsp, &dfs_rsp_size);
  1201. if (rc == -ENOTCONN) {
  1202. /* try with normal tcon */
  1203. rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
  1204. FSCTL_DFS_GET_REFERRALS,
  1205. true /* is_fsctl */, false /*use_ipc*/,
  1206. (char *)dfs_req, dfs_req_size,
  1207. (char **)&dfs_rsp, &dfs_rsp_size);
  1208. }
  1209. } while (rc == -EAGAIN);
  1210. if (rc) {
  1211. cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
  1212. goto out;
  1213. }
  1214. rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
  1215. num_of_nodes, target_nodes,
  1216. nls_codepage, remap, search_name,
  1217. true /* is_unicode */);
  1218. if (rc) {
  1219. cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
  1220. goto out;
  1221. }
  1222. out:
  1223. if (tcon) {
  1224. spin_lock(&cifs_tcp_ses_lock);
  1225. tcon->tc_count--;
  1226. spin_unlock(&cifs_tcp_ses_lock);
  1227. }
  1228. kfree(utf16_path);
  1229. kfree(dfs_req);
  1230. kfree(dfs_rsp);
  1231. return rc;
  1232. }
  1233. #define SMB2_SYMLINK_STRUCT_SIZE \
  1234. (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
  1235. static int
  1236. smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
  1237. const char *full_path, char **target_path,
  1238. struct cifs_sb_info *cifs_sb)
  1239. {
  1240. int rc;
  1241. __le16 *utf16_path;
  1242. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1243. struct cifs_open_parms oparms;
  1244. struct cifs_fid fid;
  1245. struct smb2_err_rsp *err_buf = NULL;
  1246. struct smb2_symlink_err_rsp *symlink;
  1247. unsigned int sub_len;
  1248. unsigned int sub_offset;
  1249. unsigned int print_len;
  1250. unsigned int print_offset;
  1251. cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
  1252. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  1253. if (!utf16_path)
  1254. return -ENOMEM;
  1255. oparms.tcon = tcon;
  1256. oparms.desired_access = FILE_READ_ATTRIBUTES;
  1257. oparms.disposition = FILE_OPEN;
  1258. oparms.create_options = 0;
  1259. oparms.fid = &fid;
  1260. oparms.reconnect = false;
  1261. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
  1262. if (!rc || !err_buf) {
  1263. kfree(utf16_path);
  1264. return -ENOENT;
  1265. }
  1266. if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
  1267. get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) {
  1268. kfree(utf16_path);
  1269. return -ENOENT;
  1270. }
  1271. /* open must fail on symlink - reset rc */
  1272. rc = 0;
  1273. symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
  1274. sub_len = le16_to_cpu(symlink->SubstituteNameLength);
  1275. sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
  1276. print_len = le16_to_cpu(symlink->PrintNameLength);
  1277. print_offset = le16_to_cpu(symlink->PrintNameOffset);
  1278. if (get_rfc1002_length(err_buf) + 4 <
  1279. SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
  1280. kfree(utf16_path);
  1281. return -ENOENT;
  1282. }
  1283. if (get_rfc1002_length(err_buf) + 4 <
  1284. SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
  1285. kfree(utf16_path);
  1286. return -ENOENT;
  1287. }
  1288. *target_path = cifs_strndup_from_utf16(
  1289. (char *)symlink->PathBuffer + sub_offset,
  1290. sub_len, true, cifs_sb->local_nls);
  1291. if (!(*target_path)) {
  1292. kfree(utf16_path);
  1293. return -ENOMEM;
  1294. }
  1295. convert_delimiter(*target_path, '/');
  1296. cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
  1297. kfree(utf16_path);
  1298. return rc;
  1299. }
  1300. #ifdef CONFIG_CIFS_ACL
  1301. static struct cifs_ntsd *
  1302. get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
  1303. const struct cifs_fid *cifsfid, u32 *pacllen)
  1304. {
  1305. struct cifs_ntsd *pntsd = NULL;
  1306. unsigned int xid;
  1307. int rc = -EOPNOTSUPP;
  1308. struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
  1309. if (IS_ERR(tlink))
  1310. return ERR_CAST(tlink);
  1311. xid = get_xid();
  1312. cifs_dbg(FYI, "trying to get acl\n");
  1313. rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
  1314. cifsfid->volatile_fid, (void **)&pntsd, pacllen);
  1315. free_xid(xid);
  1316. cifs_put_tlink(tlink);
  1317. cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
  1318. if (rc)
  1319. return ERR_PTR(rc);
  1320. return pntsd;
  1321. }
  1322. static struct cifs_ntsd *
  1323. get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
  1324. const char *path, u32 *pacllen)
  1325. {
  1326. struct cifs_ntsd *pntsd = NULL;
  1327. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1328. unsigned int xid;
  1329. int rc;
  1330. struct cifs_tcon *tcon;
  1331. struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
  1332. struct cifs_fid fid;
  1333. struct cifs_open_parms oparms;
  1334. __le16 *utf16_path;
  1335. cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
  1336. if (IS_ERR(tlink))
  1337. return ERR_CAST(tlink);
  1338. tcon = tlink_tcon(tlink);
  1339. xid = get_xid();
  1340. if (backup_cred(cifs_sb))
  1341. oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
  1342. else
  1343. oparms.create_options = 0;
  1344. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  1345. if (!utf16_path)
  1346. return ERR_PTR(-ENOMEM);
  1347. oparms.tcon = tcon;
  1348. oparms.desired_access = READ_CONTROL;
  1349. oparms.disposition = FILE_OPEN;
  1350. oparms.fid = &fid;
  1351. oparms.reconnect = false;
  1352. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  1353. kfree(utf16_path);
  1354. if (!rc) {
  1355. rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
  1356. fid.volatile_fid, (void **)&pntsd, pacllen);
  1357. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  1358. }
  1359. cifs_put_tlink(tlink);
  1360. free_xid(xid);
  1361. cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
  1362. if (rc)
  1363. return ERR_PTR(rc);
  1364. return pntsd;
  1365. }
  1366. #ifdef CONFIG_CIFS_ACL
  1367. static int
  1368. set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
  1369. struct inode *inode, const char *path, int aclflag)
  1370. {
  1371. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1372. unsigned int xid;
  1373. int rc, access_flags = 0;
  1374. struct cifs_tcon *tcon;
  1375. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  1376. struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
  1377. struct cifs_fid fid;
  1378. struct cifs_open_parms oparms;
  1379. __le16 *utf16_path;
  1380. cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
  1381. if (IS_ERR(tlink))
  1382. return PTR_ERR(tlink);
  1383. tcon = tlink_tcon(tlink);
  1384. xid = get_xid();
  1385. if (backup_cred(cifs_sb))
  1386. oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
  1387. else
  1388. oparms.create_options = 0;
  1389. if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
  1390. access_flags = WRITE_OWNER;
  1391. else
  1392. access_flags = WRITE_DAC;
  1393. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  1394. if (!utf16_path)
  1395. return -ENOMEM;
  1396. oparms.tcon = tcon;
  1397. oparms.desired_access = access_flags;
  1398. oparms.disposition = FILE_OPEN;
  1399. oparms.path = path;
  1400. oparms.fid = &fid;
  1401. oparms.reconnect = false;
  1402. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  1403. kfree(utf16_path);
  1404. if (!rc) {
  1405. rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
  1406. fid.volatile_fid, pnntsd, acllen, aclflag);
  1407. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  1408. }
  1409. cifs_put_tlink(tlink);
  1410. free_xid(xid);
  1411. return rc;
  1412. }
  1413. #endif /* CIFS_ACL */
  1414. /* Retrieve an ACL from the server */
  1415. static struct cifs_ntsd *
  1416. get_smb2_acl(struct cifs_sb_info *cifs_sb,
  1417. struct inode *inode, const char *path,
  1418. u32 *pacllen)
  1419. {
  1420. struct cifs_ntsd *pntsd = NULL;
  1421. struct cifsFileInfo *open_file = NULL;
  1422. if (inode)
  1423. open_file = find_readable_file(CIFS_I(inode), true);
  1424. if (!open_file)
  1425. return get_smb2_acl_by_path(cifs_sb, path, pacllen);
  1426. pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
  1427. cifsFileInfo_put(open_file);
  1428. return pntsd;
  1429. }
  1430. #endif
  1431. static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
  1432. loff_t offset, loff_t len, bool keep_size)
  1433. {
  1434. struct inode *inode;
  1435. struct cifsInodeInfo *cifsi;
  1436. struct cifsFileInfo *cfile = file->private_data;
  1437. struct file_zero_data_information fsctl_buf;
  1438. long rc;
  1439. unsigned int xid;
  1440. xid = get_xid();
  1441. inode = d_inode(cfile->dentry);
  1442. cifsi = CIFS_I(inode);
  1443. /* if file not oplocked can't be sure whether asking to extend size */
  1444. if (!CIFS_CACHE_READ(cifsi))
  1445. if (keep_size == false)
  1446. return -EOPNOTSUPP;
  1447. /*
  1448. * Must check if file sparse since fallocate -z (zero range) assumes
  1449. * non-sparse allocation
  1450. */
  1451. if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
  1452. return -EOPNOTSUPP;
  1453. /*
  1454. * need to make sure we are not asked to extend the file since the SMB3
  1455. * fsctl does not change the file size. In the future we could change
  1456. * this to zero the first part of the range then set the file size
  1457. * which for a non sparse file would zero the newly extended range
  1458. */
  1459. if (keep_size == false)
  1460. if (i_size_read(inode) < offset + len)
  1461. return -EOPNOTSUPP;
  1462. cifs_dbg(FYI, "offset %lld len %lld", offset, len);
  1463. fsctl_buf.FileOffset = cpu_to_le64(offset);
  1464. fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
  1465. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  1466. cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
  1467. true /* is_fctl */, false /* use_ipc */,
  1468. (char *)&fsctl_buf,
  1469. sizeof(struct file_zero_data_information), NULL, NULL);
  1470. free_xid(xid);
  1471. return rc;
  1472. }
  1473. static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
  1474. loff_t offset, loff_t len)
  1475. {
  1476. struct inode *inode;
  1477. struct cifsInodeInfo *cifsi;
  1478. struct cifsFileInfo *cfile = file->private_data;
  1479. struct file_zero_data_information fsctl_buf;
  1480. long rc;
  1481. unsigned int xid;
  1482. __u8 set_sparse = 1;
  1483. xid = get_xid();
  1484. inode = d_inode(cfile->dentry);
  1485. cifsi = CIFS_I(inode);
  1486. /* Need to make file sparse, if not already, before freeing range. */
  1487. /* Consider adding equivalent for compressed since it could also work */
  1488. if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
  1489. return -EOPNOTSUPP;
  1490. cifs_dbg(FYI, "offset %lld len %lld", offset, len);
  1491. fsctl_buf.FileOffset = cpu_to_le64(offset);
  1492. fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
  1493. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  1494. cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
  1495. true /* is_fctl */, false /* use_ipc */,
  1496. (char *)&fsctl_buf,
  1497. sizeof(struct file_zero_data_information), NULL, NULL);
  1498. free_xid(xid);
  1499. return rc;
  1500. }
  1501. static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
  1502. loff_t off, loff_t len, bool keep_size)
  1503. {
  1504. struct inode *inode;
  1505. struct cifsInodeInfo *cifsi;
  1506. struct cifsFileInfo *cfile = file->private_data;
  1507. long rc = -EOPNOTSUPP;
  1508. unsigned int xid;
  1509. xid = get_xid();
  1510. inode = d_inode(cfile->dentry);
  1511. cifsi = CIFS_I(inode);
  1512. /* if file not oplocked can't be sure whether asking to extend size */
  1513. if (!CIFS_CACHE_READ(cifsi))
  1514. if (keep_size == false)
  1515. return -EOPNOTSUPP;
  1516. /*
  1517. * Files are non-sparse by default so falloc may be a no-op
  1518. * Must check if file sparse. If not sparse, and not extending
  1519. * then no need to do anything since file already allocated
  1520. */
  1521. if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
  1522. if (keep_size == true)
  1523. return 0;
  1524. /* check if extending file */
  1525. else if (i_size_read(inode) >= off + len)
  1526. /* not extending file and already not sparse */
  1527. return 0;
  1528. /* BB: in future add else clause to extend file */
  1529. else
  1530. return -EOPNOTSUPP;
  1531. }
  1532. if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
  1533. /*
  1534. * Check if falloc starts within first few pages of file
  1535. * and ends within a few pages of the end of file to
  1536. * ensure that most of file is being forced to be
  1537. * fallocated now. If so then setting whole file sparse
  1538. * ie potentially making a few extra pages at the beginning
  1539. * or end of the file non-sparse via set_sparse is harmless.
  1540. */
  1541. if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
  1542. return -EOPNOTSUPP;
  1543. rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
  1544. }
  1545. /* BB: else ... in future add code to extend file and set sparse */
  1546. free_xid(xid);
  1547. return rc;
  1548. }
  1549. static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
  1550. loff_t off, loff_t len)
  1551. {
  1552. /* KEEP_SIZE already checked for by do_fallocate */
  1553. if (mode & FALLOC_FL_PUNCH_HOLE)
  1554. return smb3_punch_hole(file, tcon, off, len);
  1555. else if (mode & FALLOC_FL_ZERO_RANGE) {
  1556. if (mode & FALLOC_FL_KEEP_SIZE)
  1557. return smb3_zero_range(file, tcon, off, len, true);
  1558. return smb3_zero_range(file, tcon, off, len, false);
  1559. } else if (mode == FALLOC_FL_KEEP_SIZE)
  1560. return smb3_simple_falloc(file, tcon, off, len, true);
  1561. else if (mode == 0)
  1562. return smb3_simple_falloc(file, tcon, off, len, false);
  1563. return -EOPNOTSUPP;
  1564. }
  1565. static void
  1566. smb2_downgrade_oplock(struct TCP_Server_Info *server,
  1567. struct cifsInodeInfo *cinode, bool set_level2)
  1568. {
  1569. if (set_level2)
  1570. server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
  1571. 0, NULL);
  1572. else
  1573. server->ops->set_oplock_level(cinode, 0, 0, NULL);
  1574. }
  1575. static void
  1576. smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1577. unsigned int epoch, bool *purge_cache)
  1578. {
  1579. oplock &= 0xFF;
  1580. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  1581. return;
  1582. if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
  1583. cinode->oplock = CIFS_CACHE_RHW_FLG;
  1584. cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
  1585. &cinode->vfs_inode);
  1586. } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
  1587. cinode->oplock = CIFS_CACHE_RW_FLG;
  1588. cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
  1589. &cinode->vfs_inode);
  1590. } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
  1591. cinode->oplock = CIFS_CACHE_READ_FLG;
  1592. cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
  1593. &cinode->vfs_inode);
  1594. } else
  1595. cinode->oplock = 0;
  1596. }
  1597. static void
  1598. smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1599. unsigned int epoch, bool *purge_cache)
  1600. {
  1601. char message[5] = {0};
  1602. oplock &= 0xFF;
  1603. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  1604. return;
  1605. cinode->oplock = 0;
  1606. if (oplock & SMB2_LEASE_READ_CACHING_HE) {
  1607. cinode->oplock |= CIFS_CACHE_READ_FLG;
  1608. strcat(message, "R");
  1609. }
  1610. if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
  1611. cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
  1612. strcat(message, "H");
  1613. }
  1614. if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
  1615. cinode->oplock |= CIFS_CACHE_WRITE_FLG;
  1616. strcat(message, "W");
  1617. }
  1618. if (!cinode->oplock)
  1619. strcat(message, "None");
  1620. cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
  1621. &cinode->vfs_inode);
  1622. }
  1623. static void
  1624. smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1625. unsigned int epoch, bool *purge_cache)
  1626. {
  1627. unsigned int old_oplock = cinode->oplock;
  1628. smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
  1629. if (purge_cache) {
  1630. *purge_cache = false;
  1631. if (old_oplock == CIFS_CACHE_READ_FLG) {
  1632. if (cinode->oplock == CIFS_CACHE_READ_FLG &&
  1633. (epoch - cinode->epoch > 0))
  1634. *purge_cache = true;
  1635. else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  1636. (epoch - cinode->epoch > 1))
  1637. *purge_cache = true;
  1638. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  1639. (epoch - cinode->epoch > 1))
  1640. *purge_cache = true;
  1641. else if (cinode->oplock == 0 &&
  1642. (epoch - cinode->epoch > 0))
  1643. *purge_cache = true;
  1644. } else if (old_oplock == CIFS_CACHE_RH_FLG) {
  1645. if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  1646. (epoch - cinode->epoch > 0))
  1647. *purge_cache = true;
  1648. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  1649. (epoch - cinode->epoch > 1))
  1650. *purge_cache = true;
  1651. }
  1652. cinode->epoch = epoch;
  1653. }
  1654. }
  1655. static bool
  1656. smb2_is_read_op(__u32 oplock)
  1657. {
  1658. return oplock == SMB2_OPLOCK_LEVEL_II;
  1659. }
  1660. static bool
  1661. smb21_is_read_op(__u32 oplock)
  1662. {
  1663. return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
  1664. !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
  1665. }
  1666. static __le32
  1667. map_oplock_to_lease(u8 oplock)
  1668. {
  1669. if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
  1670. return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
  1671. else if (oplock == SMB2_OPLOCK_LEVEL_II)
  1672. return SMB2_LEASE_READ_CACHING;
  1673. else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
  1674. return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
  1675. SMB2_LEASE_WRITE_CACHING;
  1676. return 0;
  1677. }
  1678. static char *
  1679. smb2_create_lease_buf(u8 *lease_key, u8 oplock)
  1680. {
  1681. struct create_lease *buf;
  1682. buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
  1683. if (!buf)
  1684. return NULL;
  1685. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  1686. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  1687. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  1688. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  1689. (struct create_lease, lcontext));
  1690. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
  1691. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  1692. (struct create_lease, Name));
  1693. buf->ccontext.NameLength = cpu_to_le16(4);
  1694. /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
  1695. buf->Name[0] = 'R';
  1696. buf->Name[1] = 'q';
  1697. buf->Name[2] = 'L';
  1698. buf->Name[3] = 's';
  1699. return (char *)buf;
  1700. }
  1701. static char *
  1702. smb3_create_lease_buf(u8 *lease_key, u8 oplock)
  1703. {
  1704. struct create_lease_v2 *buf;
  1705. buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
  1706. if (!buf)
  1707. return NULL;
  1708. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  1709. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  1710. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  1711. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  1712. (struct create_lease_v2, lcontext));
  1713. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
  1714. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  1715. (struct create_lease_v2, Name));
  1716. buf->ccontext.NameLength = cpu_to_le16(4);
  1717. /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
  1718. buf->Name[0] = 'R';
  1719. buf->Name[1] = 'q';
  1720. buf->Name[2] = 'L';
  1721. buf->Name[3] = 's';
  1722. return (char *)buf;
  1723. }
  1724. static __u8
  1725. smb2_parse_lease_buf(void *buf, unsigned int *epoch)
  1726. {
  1727. struct create_lease *lc = (struct create_lease *)buf;
  1728. *epoch = 0; /* not used */
  1729. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  1730. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  1731. return le32_to_cpu(lc->lcontext.LeaseState);
  1732. }
  1733. static __u8
  1734. smb3_parse_lease_buf(void *buf, unsigned int *epoch)
  1735. {
  1736. struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
  1737. *epoch = le16_to_cpu(lc->lcontext.Epoch);
  1738. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  1739. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  1740. return le32_to_cpu(lc->lcontext.LeaseState);
  1741. }
  1742. static unsigned int
  1743. smb2_wp_retry_size(struct inode *inode)
  1744. {
  1745. return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
  1746. SMB2_MAX_BUFFER_SIZE);
  1747. }
  1748. static bool
  1749. smb2_dir_needs_close(struct cifsFileInfo *cfile)
  1750. {
  1751. return !cfile->invalidHandle;
  1752. }
  1753. static void
  1754. fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, struct smb_rqst *old_rq)
  1755. {
  1756. struct smb2_sync_hdr *shdr =
  1757. (struct smb2_sync_hdr *)old_rq->rq_iov[1].iov_base;
  1758. unsigned int orig_len = get_rfc1002_length(old_rq->rq_iov[0].iov_base);
  1759. memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
  1760. tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
  1761. tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
  1762. tr_hdr->Flags = cpu_to_le16(0x01);
  1763. get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
  1764. memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
  1765. inc_rfc1001_len(tr_hdr, sizeof(struct smb2_transform_hdr) - 4);
  1766. inc_rfc1001_len(tr_hdr, orig_len);
  1767. }
  1768. static struct scatterlist *
  1769. init_sg(struct smb_rqst *rqst, u8 *sign)
  1770. {
  1771. unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1;
  1772. unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24;
  1773. struct scatterlist *sg;
  1774. unsigned int i;
  1775. unsigned int j;
  1776. sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
  1777. if (!sg)
  1778. return NULL;
  1779. sg_init_table(sg, sg_len);
  1780. sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len);
  1781. for (i = 1; i < rqst->rq_nvec; i++)
  1782. sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base,
  1783. rqst->rq_iov[i].iov_len);
  1784. for (j = 0; i < sg_len - 1; i++, j++) {
  1785. unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz
  1786. : rqst->rq_tailsz;
  1787. sg_set_page(&sg[i], rqst->rq_pages[j], len, 0);
  1788. }
  1789. sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE);
  1790. return sg;
  1791. }
  1792. struct cifs_crypt_result {
  1793. int err;
  1794. struct completion completion;
  1795. };
  1796. static void cifs_crypt_complete(struct crypto_async_request *req, int err)
  1797. {
  1798. struct cifs_crypt_result *res = req->data;
  1799. if (err == -EINPROGRESS)
  1800. return;
  1801. res->err = err;
  1802. complete(&res->completion);
  1803. }
  1804. static int
  1805. smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
  1806. {
  1807. struct cifs_ses *ses;
  1808. u8 *ses_enc_key;
  1809. spin_lock(&cifs_tcp_ses_lock);
  1810. list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
  1811. if (ses->Suid != ses_id)
  1812. continue;
  1813. ses_enc_key = enc ? ses->smb3encryptionkey :
  1814. ses->smb3decryptionkey;
  1815. memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
  1816. spin_unlock(&cifs_tcp_ses_lock);
  1817. return 0;
  1818. }
  1819. spin_unlock(&cifs_tcp_ses_lock);
  1820. return 1;
  1821. }
  1822. /*
  1823. * Encrypt or decrypt @rqst message. @rqst has the following format:
  1824. * iov[0] - transform header (associate data),
  1825. * iov[1-N] and pages - data to encrypt.
  1826. * On success return encrypted data in iov[1-N] and pages, leave iov[0]
  1827. * untouched.
  1828. */
  1829. static int
  1830. crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc)
  1831. {
  1832. struct smb2_transform_hdr *tr_hdr =
  1833. (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base;
  1834. unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24;
  1835. int rc = 0;
  1836. struct scatterlist *sg;
  1837. u8 sign[SMB2_SIGNATURE_SIZE] = {};
  1838. u8 key[SMB3_SIGN_KEY_SIZE];
  1839. struct aead_request *req;
  1840. char *iv;
  1841. unsigned int iv_len;
  1842. struct cifs_crypt_result result = {0, };
  1843. struct crypto_aead *tfm;
  1844. unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
  1845. init_completion(&result.completion);
  1846. rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
  1847. if (rc) {
  1848. cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
  1849. enc ? "en" : "de");
  1850. return 0;
  1851. }
  1852. rc = smb3_crypto_aead_allocate(server);
  1853. if (rc) {
  1854. cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
  1855. return rc;
  1856. }
  1857. tfm = enc ? server->secmech.ccmaesencrypt :
  1858. server->secmech.ccmaesdecrypt;
  1859. rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
  1860. if (rc) {
  1861. cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
  1862. return rc;
  1863. }
  1864. rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
  1865. if (rc) {
  1866. cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
  1867. return rc;
  1868. }
  1869. req = aead_request_alloc(tfm, GFP_KERNEL);
  1870. if (!req) {
  1871. cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
  1872. return -ENOMEM;
  1873. }
  1874. if (!enc) {
  1875. memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
  1876. crypt_len += SMB2_SIGNATURE_SIZE;
  1877. }
  1878. sg = init_sg(rqst, sign);
  1879. if (!sg) {
  1880. cifs_dbg(VFS, "%s: Failed to init sg", __func__);
  1881. rc = -ENOMEM;
  1882. goto free_req;
  1883. }
  1884. iv_len = crypto_aead_ivsize(tfm);
  1885. iv = kzalloc(iv_len, GFP_KERNEL);
  1886. if (!iv) {
  1887. cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
  1888. rc = -ENOMEM;
  1889. goto free_sg;
  1890. }
  1891. iv[0] = 3;
  1892. memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
  1893. aead_request_set_crypt(req, sg, sg, crypt_len, iv);
  1894. aead_request_set_ad(req, assoc_data_len);
  1895. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  1896. cifs_crypt_complete, &result);
  1897. rc = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
  1898. if (rc == -EINPROGRESS || rc == -EBUSY) {
  1899. wait_for_completion(&result.completion);
  1900. rc = result.err;
  1901. }
  1902. if (!rc && enc)
  1903. memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
  1904. kfree(iv);
  1905. free_sg:
  1906. kfree(sg);
  1907. free_req:
  1908. kfree(req);
  1909. return rc;
  1910. }
  1911. static int
  1912. smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
  1913. struct smb_rqst *old_rq)
  1914. {
  1915. struct kvec *iov;
  1916. struct page **pages;
  1917. struct smb2_transform_hdr *tr_hdr;
  1918. unsigned int npages = old_rq->rq_npages;
  1919. int i;
  1920. int rc = -ENOMEM;
  1921. pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
  1922. if (!pages)
  1923. return rc;
  1924. new_rq->rq_pages = pages;
  1925. new_rq->rq_npages = old_rq->rq_npages;
  1926. new_rq->rq_pagesz = old_rq->rq_pagesz;
  1927. new_rq->rq_tailsz = old_rq->rq_tailsz;
  1928. for (i = 0; i < npages; i++) {
  1929. pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
  1930. if (!pages[i])
  1931. goto err_free_pages;
  1932. }
  1933. iov = kmalloc_array(old_rq->rq_nvec, sizeof(struct kvec), GFP_KERNEL);
  1934. if (!iov)
  1935. goto err_free_pages;
  1936. /* copy all iovs from the old except the 1st one (rfc1002 length) */
  1937. memcpy(&iov[1], &old_rq->rq_iov[1],
  1938. sizeof(struct kvec) * (old_rq->rq_nvec - 1));
  1939. new_rq->rq_iov = iov;
  1940. new_rq->rq_nvec = old_rq->rq_nvec;
  1941. tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL);
  1942. if (!tr_hdr)
  1943. goto err_free_iov;
  1944. /* fill the 1st iov with a transform header */
  1945. fill_transform_hdr(tr_hdr, old_rq);
  1946. new_rq->rq_iov[0].iov_base = tr_hdr;
  1947. new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr);
  1948. /* copy pages form the old */
  1949. for (i = 0; i < npages; i++) {
  1950. char *dst = kmap(new_rq->rq_pages[i]);
  1951. char *src = kmap(old_rq->rq_pages[i]);
  1952. unsigned int len = (i < npages - 1) ? new_rq->rq_pagesz :
  1953. new_rq->rq_tailsz;
  1954. memcpy(dst, src, len);
  1955. kunmap(new_rq->rq_pages[i]);
  1956. kunmap(old_rq->rq_pages[i]);
  1957. }
  1958. rc = crypt_message(server, new_rq, 1);
  1959. cifs_dbg(FYI, "encrypt message returned %d", rc);
  1960. if (rc)
  1961. goto err_free_tr_hdr;
  1962. return rc;
  1963. err_free_tr_hdr:
  1964. kfree(tr_hdr);
  1965. err_free_iov:
  1966. kfree(iov);
  1967. err_free_pages:
  1968. for (i = i - 1; i >= 0; i--)
  1969. put_page(pages[i]);
  1970. kfree(pages);
  1971. return rc;
  1972. }
  1973. static void
  1974. smb3_free_transform_rq(struct smb_rqst *rqst)
  1975. {
  1976. int i = rqst->rq_npages - 1;
  1977. for (; i >= 0; i--)
  1978. put_page(rqst->rq_pages[i]);
  1979. kfree(rqst->rq_pages);
  1980. /* free transform header */
  1981. kfree(rqst->rq_iov[0].iov_base);
  1982. kfree(rqst->rq_iov);
  1983. }
  1984. static int
  1985. smb3_is_transform_hdr(void *buf)
  1986. {
  1987. struct smb2_transform_hdr *trhdr = buf;
  1988. return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
  1989. }
  1990. static int
  1991. decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
  1992. unsigned int buf_data_size, struct page **pages,
  1993. unsigned int npages, unsigned int page_data_size)
  1994. {
  1995. struct kvec iov[2];
  1996. struct smb_rqst rqst = {NULL};
  1997. struct smb2_hdr *hdr;
  1998. int rc;
  1999. iov[0].iov_base = buf;
  2000. iov[0].iov_len = sizeof(struct smb2_transform_hdr);
  2001. iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
  2002. iov[1].iov_len = buf_data_size;
  2003. rqst.rq_iov = iov;
  2004. rqst.rq_nvec = 2;
  2005. rqst.rq_pages = pages;
  2006. rqst.rq_npages = npages;
  2007. rqst.rq_pagesz = PAGE_SIZE;
  2008. rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
  2009. rc = crypt_message(server, &rqst, 0);
  2010. cifs_dbg(FYI, "decrypt message returned %d\n", rc);
  2011. if (rc)
  2012. return rc;
  2013. memmove(buf + 4, iov[1].iov_base, buf_data_size);
  2014. hdr = (struct smb2_hdr *)buf;
  2015. hdr->smb2_buf_length = cpu_to_be32(buf_data_size + page_data_size);
  2016. server->total_read = buf_data_size + page_data_size + 4;
  2017. return rc;
  2018. }
  2019. static int
  2020. read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
  2021. unsigned int npages, unsigned int len)
  2022. {
  2023. int i;
  2024. int length;
  2025. for (i = 0; i < npages; i++) {
  2026. struct page *page = pages[i];
  2027. size_t n;
  2028. n = len;
  2029. if (len >= PAGE_SIZE) {
  2030. /* enough data to fill the page */
  2031. n = PAGE_SIZE;
  2032. len -= n;
  2033. } else {
  2034. zero_user(page, len, PAGE_SIZE - len);
  2035. len = 0;
  2036. }
  2037. length = cifs_read_page_from_socket(server, page, n);
  2038. if (length < 0)
  2039. return length;
  2040. server->total_read += length;
  2041. }
  2042. return 0;
  2043. }
  2044. static int
  2045. init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
  2046. unsigned int cur_off, struct bio_vec **page_vec)
  2047. {
  2048. struct bio_vec *bvec;
  2049. int i;
  2050. bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
  2051. if (!bvec)
  2052. return -ENOMEM;
  2053. for (i = 0; i < npages; i++) {
  2054. bvec[i].bv_page = pages[i];
  2055. bvec[i].bv_offset = (i == 0) ? cur_off : 0;
  2056. bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
  2057. data_size -= bvec[i].bv_len;
  2058. }
  2059. if (data_size != 0) {
  2060. cifs_dbg(VFS, "%s: something went wrong\n", __func__);
  2061. kfree(bvec);
  2062. return -EIO;
  2063. }
  2064. *page_vec = bvec;
  2065. return 0;
  2066. }
  2067. static int
  2068. handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
  2069. char *buf, unsigned int buf_len, struct page **pages,
  2070. unsigned int npages, unsigned int page_data_size)
  2071. {
  2072. unsigned int data_offset;
  2073. unsigned int data_len;
  2074. unsigned int cur_off;
  2075. unsigned int cur_page_idx;
  2076. unsigned int pad_len;
  2077. struct cifs_readdata *rdata = mid->callback_data;
  2078. struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
  2079. struct bio_vec *bvec = NULL;
  2080. struct iov_iter iter;
  2081. struct kvec iov;
  2082. int length;
  2083. if (shdr->Command != SMB2_READ) {
  2084. cifs_dbg(VFS, "only big read responses are supported\n");
  2085. return -ENOTSUPP;
  2086. }
  2087. if (server->ops->is_session_expired &&
  2088. server->ops->is_session_expired(buf)) {
  2089. cifs_reconnect(server);
  2090. wake_up(&server->response_q);
  2091. return -1;
  2092. }
  2093. if (server->ops->is_status_pending &&
  2094. server->ops->is_status_pending(buf, server, 0))
  2095. return -1;
  2096. rdata->result = server->ops->map_error(buf, false);
  2097. if (rdata->result != 0) {
  2098. cifs_dbg(FYI, "%s: server returned error %d\n",
  2099. __func__, rdata->result);
  2100. dequeue_mid(mid, rdata->result);
  2101. return 0;
  2102. }
  2103. data_offset = server->ops->read_data_offset(buf) + 4;
  2104. data_len = server->ops->read_data_length(buf);
  2105. if (data_offset < server->vals->read_rsp_size) {
  2106. /*
  2107. * win2k8 sometimes sends an offset of 0 when the read
  2108. * is beyond the EOF. Treat it as if the data starts just after
  2109. * the header.
  2110. */
  2111. cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
  2112. __func__, data_offset);
  2113. data_offset = server->vals->read_rsp_size;
  2114. } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
  2115. /* data_offset is beyond the end of smallbuf */
  2116. cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
  2117. __func__, data_offset);
  2118. rdata->result = -EIO;
  2119. dequeue_mid(mid, rdata->result);
  2120. return 0;
  2121. }
  2122. pad_len = data_offset - server->vals->read_rsp_size;
  2123. if (buf_len <= data_offset) {
  2124. /* read response payload is in pages */
  2125. cur_page_idx = pad_len / PAGE_SIZE;
  2126. cur_off = pad_len % PAGE_SIZE;
  2127. if (cur_page_idx != 0) {
  2128. /* data offset is beyond the 1st page of response */
  2129. cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
  2130. __func__, data_offset);
  2131. rdata->result = -EIO;
  2132. dequeue_mid(mid, rdata->result);
  2133. return 0;
  2134. }
  2135. if (data_len > page_data_size - pad_len) {
  2136. /* data_len is corrupt -- discard frame */
  2137. rdata->result = -EIO;
  2138. dequeue_mid(mid, rdata->result);
  2139. return 0;
  2140. }
  2141. rdata->result = init_read_bvec(pages, npages, page_data_size,
  2142. cur_off, &bvec);
  2143. if (rdata->result != 0) {
  2144. dequeue_mid(mid, rdata->result);
  2145. return 0;
  2146. }
  2147. iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len);
  2148. } else if (buf_len >= data_offset + data_len) {
  2149. /* read response payload is in buf */
  2150. WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
  2151. iov.iov_base = buf + data_offset;
  2152. iov.iov_len = data_len;
  2153. iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len);
  2154. } else {
  2155. /* read response payload cannot be in both buf and pages */
  2156. WARN_ONCE(1, "buf can not contain only a part of read data");
  2157. rdata->result = -EIO;
  2158. dequeue_mid(mid, rdata->result);
  2159. return 0;
  2160. }
  2161. /* set up first iov for signature check */
  2162. rdata->iov[0].iov_base = buf;
  2163. rdata->iov[0].iov_len = 4;
  2164. rdata->iov[1].iov_base = buf + 4;
  2165. rdata->iov[1].iov_len = server->vals->read_rsp_size - 4;
  2166. cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
  2167. rdata->iov[0].iov_base, server->vals->read_rsp_size);
  2168. length = rdata->copy_into_pages(server, rdata, &iter);
  2169. kfree(bvec);
  2170. if (length < 0)
  2171. return length;
  2172. dequeue_mid(mid, false);
  2173. return length;
  2174. }
  2175. static int
  2176. receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
  2177. {
  2178. char *buf = server->smallbuf;
  2179. struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
  2180. unsigned int npages;
  2181. struct page **pages;
  2182. unsigned int len;
  2183. unsigned int buflen = get_rfc1002_length(buf) + 4;
  2184. int rc;
  2185. int i = 0;
  2186. len = min_t(unsigned int, buflen, server->vals->read_rsp_size - 4 +
  2187. sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
  2188. rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
  2189. if (rc < 0)
  2190. return rc;
  2191. server->total_read += rc;
  2192. len = le32_to_cpu(tr_hdr->OriginalMessageSize) + 4 -
  2193. server->vals->read_rsp_size;
  2194. npages = DIV_ROUND_UP(len, PAGE_SIZE);
  2195. pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
  2196. if (!pages) {
  2197. rc = -ENOMEM;
  2198. goto discard_data;
  2199. }
  2200. for (; i < npages; i++) {
  2201. pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
  2202. if (!pages[i]) {
  2203. rc = -ENOMEM;
  2204. goto discard_data;
  2205. }
  2206. }
  2207. /* read read data into pages */
  2208. rc = read_data_into_pages(server, pages, npages, len);
  2209. if (rc)
  2210. goto free_pages;
  2211. rc = cifs_discard_remaining_data(server);
  2212. if (rc)
  2213. goto free_pages;
  2214. rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size - 4,
  2215. pages, npages, len);
  2216. if (rc)
  2217. goto free_pages;
  2218. *mid = smb2_find_mid(server, buf);
  2219. if (*mid == NULL)
  2220. cifs_dbg(FYI, "mid not found\n");
  2221. else {
  2222. cifs_dbg(FYI, "mid found\n");
  2223. (*mid)->decrypted = true;
  2224. rc = handle_read_data(server, *mid, buf,
  2225. server->vals->read_rsp_size,
  2226. pages, npages, len);
  2227. }
  2228. free_pages:
  2229. for (i = i - 1; i >= 0; i--)
  2230. put_page(pages[i]);
  2231. kfree(pages);
  2232. return rc;
  2233. discard_data:
  2234. cifs_discard_remaining_data(server);
  2235. goto free_pages;
  2236. }
  2237. static int
  2238. receive_encrypted_standard(struct TCP_Server_Info *server,
  2239. struct mid_q_entry **mid)
  2240. {
  2241. int length;
  2242. char *buf = server->smallbuf;
  2243. unsigned int pdu_length = get_rfc1002_length(buf);
  2244. unsigned int buf_size;
  2245. struct mid_q_entry *mid_entry;
  2246. /* switch to large buffer if too big for a small one */
  2247. if (pdu_length + 4 > MAX_CIFS_SMALL_BUFFER_SIZE) {
  2248. server->large_buf = true;
  2249. memcpy(server->bigbuf, buf, server->total_read);
  2250. buf = server->bigbuf;
  2251. }
  2252. /* now read the rest */
  2253. length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
  2254. pdu_length - HEADER_SIZE(server) + 1 + 4);
  2255. if (length < 0)
  2256. return length;
  2257. server->total_read += length;
  2258. buf_size = pdu_length + 4 - sizeof(struct smb2_transform_hdr);
  2259. length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
  2260. if (length)
  2261. return length;
  2262. mid_entry = smb2_find_mid(server, buf);
  2263. if (mid_entry == NULL)
  2264. cifs_dbg(FYI, "mid not found\n");
  2265. else {
  2266. cifs_dbg(FYI, "mid found\n");
  2267. mid_entry->decrypted = true;
  2268. }
  2269. *mid = mid_entry;
  2270. if (mid_entry && mid_entry->handle)
  2271. return mid_entry->handle(server, mid_entry);
  2272. return cifs_handle_standard(server, mid_entry);
  2273. }
  2274. static int
  2275. smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid)
  2276. {
  2277. char *buf = server->smallbuf;
  2278. unsigned int pdu_length = get_rfc1002_length(buf);
  2279. struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
  2280. unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
  2281. if (pdu_length + 4 < sizeof(struct smb2_transform_hdr) +
  2282. sizeof(struct smb2_sync_hdr)) {
  2283. cifs_dbg(VFS, "Transform message is too small (%u)\n",
  2284. pdu_length);
  2285. cifs_reconnect(server);
  2286. wake_up(&server->response_q);
  2287. return -ECONNABORTED;
  2288. }
  2289. if (pdu_length + 4 < orig_len + sizeof(struct smb2_transform_hdr)) {
  2290. cifs_dbg(VFS, "Transform message is broken\n");
  2291. cifs_reconnect(server);
  2292. wake_up(&server->response_q);
  2293. return -ECONNABORTED;
  2294. }
  2295. if (pdu_length + 4 > CIFSMaxBufSize + MAX_HEADER_SIZE(server))
  2296. return receive_encrypted_read(server, mid);
  2297. return receive_encrypted_standard(server, mid);
  2298. }
  2299. int
  2300. smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
  2301. {
  2302. char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
  2303. return handle_read_data(server, mid, buf, get_rfc1002_length(buf) + 4,
  2304. NULL, 0, 0);
  2305. }
  2306. struct smb_version_operations smb20_operations = {
  2307. .compare_fids = smb2_compare_fids,
  2308. .setup_request = smb2_setup_request,
  2309. .setup_async_request = smb2_setup_async_request,
  2310. .check_receive = smb2_check_receive,
  2311. .add_credits = smb2_add_credits,
  2312. .set_credits = smb2_set_credits,
  2313. .get_credits_field = smb2_get_credits_field,
  2314. .get_credits = smb2_get_credits,
  2315. .wait_mtu_credits = cifs_wait_mtu_credits,
  2316. .get_next_mid = smb2_get_next_mid,
  2317. .read_data_offset = smb2_read_data_offset,
  2318. .read_data_length = smb2_read_data_length,
  2319. .map_error = map_smb2_to_linux_error,
  2320. .find_mid = smb2_find_mid,
  2321. .check_message = smb2_check_message,
  2322. .dump_detail = smb2_dump_detail,
  2323. .clear_stats = smb2_clear_stats,
  2324. .print_stats = smb2_print_stats,
  2325. .is_oplock_break = smb2_is_valid_oplock_break,
  2326. .handle_cancelled_mid = smb2_handle_cancelled_mid,
  2327. .downgrade_oplock = smb2_downgrade_oplock,
  2328. .need_neg = smb2_need_neg,
  2329. .negotiate = smb2_negotiate,
  2330. .negotiate_wsize = smb2_negotiate_wsize,
  2331. .negotiate_rsize = smb2_negotiate_rsize,
  2332. .sess_setup = SMB2_sess_setup,
  2333. .logoff = SMB2_logoff,
  2334. .tree_connect = SMB2_tcon,
  2335. .tree_disconnect = SMB2_tdis,
  2336. .qfs_tcon = smb2_qfs_tcon,
  2337. .is_path_accessible = smb2_is_path_accessible,
  2338. .can_echo = smb2_can_echo,
  2339. .echo = SMB2_echo,
  2340. .query_path_info = smb2_query_path_info,
  2341. .get_srv_inum = smb2_get_srv_inum,
  2342. .query_file_info = smb2_query_file_info,
  2343. .set_path_size = smb2_set_path_size,
  2344. .set_file_size = smb2_set_file_size,
  2345. .set_file_info = smb2_set_file_info,
  2346. .set_compression = smb2_set_compression,
  2347. .mkdir = smb2_mkdir,
  2348. .mkdir_setinfo = smb2_mkdir_setinfo,
  2349. .rmdir = smb2_rmdir,
  2350. .unlink = smb2_unlink,
  2351. .rename = smb2_rename_path,
  2352. .create_hardlink = smb2_create_hardlink,
  2353. .query_symlink = smb2_query_symlink,
  2354. .query_mf_symlink = smb3_query_mf_symlink,
  2355. .create_mf_symlink = smb3_create_mf_symlink,
  2356. .open = smb2_open_file,
  2357. .set_fid = smb2_set_fid,
  2358. .close = smb2_close_file,
  2359. .flush = smb2_flush_file,
  2360. .async_readv = smb2_async_readv,
  2361. .async_writev = smb2_async_writev,
  2362. .sync_read = smb2_sync_read,
  2363. .sync_write = smb2_sync_write,
  2364. .query_dir_first = smb2_query_dir_first,
  2365. .query_dir_next = smb2_query_dir_next,
  2366. .close_dir = smb2_close_dir,
  2367. .calc_smb_size = smb2_calc_size,
  2368. .is_status_pending = smb2_is_status_pending,
  2369. .is_session_expired = smb2_is_session_expired,
  2370. .oplock_response = smb2_oplock_response,
  2371. .queryfs = smb2_queryfs,
  2372. .mand_lock = smb2_mand_lock,
  2373. .mand_unlock_range = smb2_unlock_range,
  2374. .push_mand_locks = smb2_push_mandatory_locks,
  2375. .get_lease_key = smb2_get_lease_key,
  2376. .set_lease_key = smb2_set_lease_key,
  2377. .new_lease_key = smb2_new_lease_key,
  2378. .calc_signature = smb2_calc_signature,
  2379. .is_read_op = smb2_is_read_op,
  2380. .set_oplock_level = smb2_set_oplock_level,
  2381. .create_lease_buf = smb2_create_lease_buf,
  2382. .parse_lease_buf = smb2_parse_lease_buf,
  2383. .copychunk_range = smb2_copychunk_range,
  2384. .wp_retry_size = smb2_wp_retry_size,
  2385. .dir_needs_close = smb2_dir_needs_close,
  2386. .get_dfs_refer = smb2_get_dfs_refer,
  2387. .select_sectype = smb2_select_sectype,
  2388. #ifdef CONFIG_CIFS_XATTR
  2389. .query_all_EAs = smb2_query_eas,
  2390. .set_EA = smb2_set_ea,
  2391. #endif /* CIFS_XATTR */
  2392. #ifdef CONFIG_CIFS_ACL
  2393. .get_acl = get_smb2_acl,
  2394. .get_acl_by_fid = get_smb2_acl_by_fid,
  2395. .set_acl = set_smb2_acl,
  2396. #endif /* CIFS_ACL */
  2397. };
  2398. struct smb_version_operations smb21_operations = {
  2399. .compare_fids = smb2_compare_fids,
  2400. .setup_request = smb2_setup_request,
  2401. .setup_async_request = smb2_setup_async_request,
  2402. .check_receive = smb2_check_receive,
  2403. .add_credits = smb2_add_credits,
  2404. .set_credits = smb2_set_credits,
  2405. .get_credits_field = smb2_get_credits_field,
  2406. .get_credits = smb2_get_credits,
  2407. .wait_mtu_credits = smb2_wait_mtu_credits,
  2408. .get_next_mid = smb2_get_next_mid,
  2409. .read_data_offset = smb2_read_data_offset,
  2410. .read_data_length = smb2_read_data_length,
  2411. .map_error = map_smb2_to_linux_error,
  2412. .find_mid = smb2_find_mid,
  2413. .check_message = smb2_check_message,
  2414. .dump_detail = smb2_dump_detail,
  2415. .clear_stats = smb2_clear_stats,
  2416. .print_stats = smb2_print_stats,
  2417. .is_oplock_break = smb2_is_valid_oplock_break,
  2418. .handle_cancelled_mid = smb2_handle_cancelled_mid,
  2419. .downgrade_oplock = smb2_downgrade_oplock,
  2420. .need_neg = smb2_need_neg,
  2421. .negotiate = smb2_negotiate,
  2422. .negotiate_wsize = smb2_negotiate_wsize,
  2423. .negotiate_rsize = smb2_negotiate_rsize,
  2424. .sess_setup = SMB2_sess_setup,
  2425. .logoff = SMB2_logoff,
  2426. .tree_connect = SMB2_tcon,
  2427. .tree_disconnect = SMB2_tdis,
  2428. .qfs_tcon = smb2_qfs_tcon,
  2429. .is_path_accessible = smb2_is_path_accessible,
  2430. .can_echo = smb2_can_echo,
  2431. .echo = SMB2_echo,
  2432. .query_path_info = smb2_query_path_info,
  2433. .get_srv_inum = smb2_get_srv_inum,
  2434. .query_file_info = smb2_query_file_info,
  2435. .set_path_size = smb2_set_path_size,
  2436. .set_file_size = smb2_set_file_size,
  2437. .set_file_info = smb2_set_file_info,
  2438. .set_compression = smb2_set_compression,
  2439. .mkdir = smb2_mkdir,
  2440. .mkdir_setinfo = smb2_mkdir_setinfo,
  2441. .rmdir = smb2_rmdir,
  2442. .unlink = smb2_unlink,
  2443. .rename = smb2_rename_path,
  2444. .create_hardlink = smb2_create_hardlink,
  2445. .query_symlink = smb2_query_symlink,
  2446. .query_mf_symlink = smb3_query_mf_symlink,
  2447. .create_mf_symlink = smb3_create_mf_symlink,
  2448. .open = smb2_open_file,
  2449. .set_fid = smb2_set_fid,
  2450. .close = smb2_close_file,
  2451. .flush = smb2_flush_file,
  2452. .async_readv = smb2_async_readv,
  2453. .async_writev = smb2_async_writev,
  2454. .sync_read = smb2_sync_read,
  2455. .sync_write = smb2_sync_write,
  2456. .query_dir_first = smb2_query_dir_first,
  2457. .query_dir_next = smb2_query_dir_next,
  2458. .close_dir = smb2_close_dir,
  2459. .calc_smb_size = smb2_calc_size,
  2460. .is_status_pending = smb2_is_status_pending,
  2461. .is_session_expired = smb2_is_session_expired,
  2462. .oplock_response = smb2_oplock_response,
  2463. .queryfs = smb2_queryfs,
  2464. .mand_lock = smb2_mand_lock,
  2465. .mand_unlock_range = smb2_unlock_range,
  2466. .push_mand_locks = smb2_push_mandatory_locks,
  2467. .get_lease_key = smb2_get_lease_key,
  2468. .set_lease_key = smb2_set_lease_key,
  2469. .new_lease_key = smb2_new_lease_key,
  2470. .calc_signature = smb2_calc_signature,
  2471. .is_read_op = smb21_is_read_op,
  2472. .set_oplock_level = smb21_set_oplock_level,
  2473. .create_lease_buf = smb2_create_lease_buf,
  2474. .parse_lease_buf = smb2_parse_lease_buf,
  2475. .copychunk_range = smb2_copychunk_range,
  2476. .wp_retry_size = smb2_wp_retry_size,
  2477. .dir_needs_close = smb2_dir_needs_close,
  2478. .enum_snapshots = smb3_enum_snapshots,
  2479. .get_dfs_refer = smb2_get_dfs_refer,
  2480. .select_sectype = smb2_select_sectype,
  2481. #ifdef CONFIG_CIFS_XATTR
  2482. .query_all_EAs = smb2_query_eas,
  2483. .set_EA = smb2_set_ea,
  2484. #endif /* CIFS_XATTR */
  2485. #ifdef CONFIG_CIFS_ACL
  2486. .get_acl = get_smb2_acl,
  2487. .get_acl_by_fid = get_smb2_acl_by_fid,
  2488. .set_acl = set_smb2_acl,
  2489. #endif /* CIFS_ACL */
  2490. };
  2491. struct smb_version_operations smb30_operations = {
  2492. .compare_fids = smb2_compare_fids,
  2493. .setup_request = smb2_setup_request,
  2494. .setup_async_request = smb2_setup_async_request,
  2495. .check_receive = smb2_check_receive,
  2496. .add_credits = smb2_add_credits,
  2497. .set_credits = smb2_set_credits,
  2498. .get_credits_field = smb2_get_credits_field,
  2499. .get_credits = smb2_get_credits,
  2500. .wait_mtu_credits = smb2_wait_mtu_credits,
  2501. .get_next_mid = smb2_get_next_mid,
  2502. .read_data_offset = smb2_read_data_offset,
  2503. .read_data_length = smb2_read_data_length,
  2504. .map_error = map_smb2_to_linux_error,
  2505. .find_mid = smb2_find_mid,
  2506. .check_message = smb2_check_message,
  2507. .dump_detail = smb2_dump_detail,
  2508. .clear_stats = smb2_clear_stats,
  2509. .print_stats = smb2_print_stats,
  2510. .dump_share_caps = smb2_dump_share_caps,
  2511. .is_oplock_break = smb2_is_valid_oplock_break,
  2512. .handle_cancelled_mid = smb2_handle_cancelled_mid,
  2513. .downgrade_oplock = smb2_downgrade_oplock,
  2514. .need_neg = smb2_need_neg,
  2515. .negotiate = smb2_negotiate,
  2516. .negotiate_wsize = smb2_negotiate_wsize,
  2517. .negotiate_rsize = smb2_negotiate_rsize,
  2518. .sess_setup = SMB2_sess_setup,
  2519. .logoff = SMB2_logoff,
  2520. .tree_connect = SMB2_tcon,
  2521. .tree_disconnect = SMB2_tdis,
  2522. .qfs_tcon = smb3_qfs_tcon,
  2523. .is_path_accessible = smb2_is_path_accessible,
  2524. .can_echo = smb2_can_echo,
  2525. .echo = SMB2_echo,
  2526. .query_path_info = smb2_query_path_info,
  2527. .get_srv_inum = smb2_get_srv_inum,
  2528. .query_file_info = smb2_query_file_info,
  2529. .set_path_size = smb2_set_path_size,
  2530. .set_file_size = smb2_set_file_size,
  2531. .set_file_info = smb2_set_file_info,
  2532. .set_compression = smb2_set_compression,
  2533. .mkdir = smb2_mkdir,
  2534. .mkdir_setinfo = smb2_mkdir_setinfo,
  2535. .rmdir = smb2_rmdir,
  2536. .unlink = smb2_unlink,
  2537. .rename = smb2_rename_path,
  2538. .create_hardlink = smb2_create_hardlink,
  2539. .query_symlink = smb2_query_symlink,
  2540. .query_mf_symlink = smb3_query_mf_symlink,
  2541. .create_mf_symlink = smb3_create_mf_symlink,
  2542. .open = smb2_open_file,
  2543. .set_fid = smb2_set_fid,
  2544. .close = smb2_close_file,
  2545. .flush = smb2_flush_file,
  2546. .async_readv = smb2_async_readv,
  2547. .async_writev = smb2_async_writev,
  2548. .sync_read = smb2_sync_read,
  2549. .sync_write = smb2_sync_write,
  2550. .query_dir_first = smb2_query_dir_first,
  2551. .query_dir_next = smb2_query_dir_next,
  2552. .close_dir = smb2_close_dir,
  2553. .calc_smb_size = smb2_calc_size,
  2554. .is_status_pending = smb2_is_status_pending,
  2555. .is_session_expired = smb2_is_session_expired,
  2556. .oplock_response = smb2_oplock_response,
  2557. .queryfs = smb2_queryfs,
  2558. .mand_lock = smb2_mand_lock,
  2559. .mand_unlock_range = smb2_unlock_range,
  2560. .push_mand_locks = smb2_push_mandatory_locks,
  2561. .get_lease_key = smb2_get_lease_key,
  2562. .set_lease_key = smb2_set_lease_key,
  2563. .new_lease_key = smb2_new_lease_key,
  2564. .generate_signingkey = generate_smb30signingkey,
  2565. .calc_signature = smb3_calc_signature,
  2566. .set_integrity = smb3_set_integrity,
  2567. .is_read_op = smb21_is_read_op,
  2568. .set_oplock_level = smb3_set_oplock_level,
  2569. .create_lease_buf = smb3_create_lease_buf,
  2570. .parse_lease_buf = smb3_parse_lease_buf,
  2571. .copychunk_range = smb2_copychunk_range,
  2572. .duplicate_extents = smb2_duplicate_extents,
  2573. .validate_negotiate = smb3_validate_negotiate,
  2574. .wp_retry_size = smb2_wp_retry_size,
  2575. .dir_needs_close = smb2_dir_needs_close,
  2576. .fallocate = smb3_fallocate,
  2577. .enum_snapshots = smb3_enum_snapshots,
  2578. .init_transform_rq = smb3_init_transform_rq,
  2579. .free_transform_rq = smb3_free_transform_rq,
  2580. .is_transform_hdr = smb3_is_transform_hdr,
  2581. .receive_transform = smb3_receive_transform,
  2582. .get_dfs_refer = smb2_get_dfs_refer,
  2583. .select_sectype = smb2_select_sectype,
  2584. #ifdef CONFIG_CIFS_XATTR
  2585. .query_all_EAs = smb2_query_eas,
  2586. .set_EA = smb2_set_ea,
  2587. #endif /* CIFS_XATTR */
  2588. #ifdef CONFIG_CIFS_ACL
  2589. .get_acl = get_smb2_acl,
  2590. .get_acl_by_fid = get_smb2_acl_by_fid,
  2591. .set_acl = set_smb2_acl,
  2592. #endif /* CIFS_ACL */
  2593. };
  2594. #ifdef CONFIG_CIFS_SMB311
  2595. struct smb_version_operations smb311_operations = {
  2596. .compare_fids = smb2_compare_fids,
  2597. .setup_request = smb2_setup_request,
  2598. .setup_async_request = smb2_setup_async_request,
  2599. .check_receive = smb2_check_receive,
  2600. .add_credits = smb2_add_credits,
  2601. .set_credits = smb2_set_credits,
  2602. .get_credits_field = smb2_get_credits_field,
  2603. .get_credits = smb2_get_credits,
  2604. .wait_mtu_credits = smb2_wait_mtu_credits,
  2605. .get_next_mid = smb2_get_next_mid,
  2606. .read_data_offset = smb2_read_data_offset,
  2607. .read_data_length = smb2_read_data_length,
  2608. .map_error = map_smb2_to_linux_error,
  2609. .find_mid = smb2_find_mid,
  2610. .check_message = smb2_check_message,
  2611. .dump_detail = smb2_dump_detail,
  2612. .clear_stats = smb2_clear_stats,
  2613. .print_stats = smb2_print_stats,
  2614. .dump_share_caps = smb2_dump_share_caps,
  2615. .is_oplock_break = smb2_is_valid_oplock_break,
  2616. .handle_cancelled_mid = smb2_handle_cancelled_mid,
  2617. .downgrade_oplock = smb2_downgrade_oplock,
  2618. .need_neg = smb2_need_neg,
  2619. .negotiate = smb2_negotiate,
  2620. .negotiate_wsize = smb2_negotiate_wsize,
  2621. .negotiate_rsize = smb2_negotiate_rsize,
  2622. .sess_setup = SMB2_sess_setup,
  2623. .logoff = SMB2_logoff,
  2624. .tree_connect = SMB2_tcon,
  2625. .tree_disconnect = SMB2_tdis,
  2626. .qfs_tcon = smb3_qfs_tcon,
  2627. .is_path_accessible = smb2_is_path_accessible,
  2628. .can_echo = smb2_can_echo,
  2629. .echo = SMB2_echo,
  2630. .query_path_info = smb2_query_path_info,
  2631. .get_srv_inum = smb2_get_srv_inum,
  2632. .query_file_info = smb2_query_file_info,
  2633. .set_path_size = smb2_set_path_size,
  2634. .set_file_size = smb2_set_file_size,
  2635. .set_file_info = smb2_set_file_info,
  2636. .set_compression = smb2_set_compression,
  2637. .mkdir = smb2_mkdir,
  2638. .mkdir_setinfo = smb2_mkdir_setinfo,
  2639. .rmdir = smb2_rmdir,
  2640. .unlink = smb2_unlink,
  2641. .rename = smb2_rename_path,
  2642. .create_hardlink = smb2_create_hardlink,
  2643. .query_symlink = smb2_query_symlink,
  2644. .query_mf_symlink = smb3_query_mf_symlink,
  2645. .create_mf_symlink = smb3_create_mf_symlink,
  2646. .open = smb2_open_file,
  2647. .set_fid = smb2_set_fid,
  2648. .close = smb2_close_file,
  2649. .flush = smb2_flush_file,
  2650. .async_readv = smb2_async_readv,
  2651. .async_writev = smb2_async_writev,
  2652. .sync_read = smb2_sync_read,
  2653. .sync_write = smb2_sync_write,
  2654. .query_dir_first = smb2_query_dir_first,
  2655. .query_dir_next = smb2_query_dir_next,
  2656. .close_dir = smb2_close_dir,
  2657. .calc_smb_size = smb2_calc_size,
  2658. .is_status_pending = smb2_is_status_pending,
  2659. .is_session_expired = smb2_is_session_expired,
  2660. .oplock_response = smb2_oplock_response,
  2661. .queryfs = smb2_queryfs,
  2662. .mand_lock = smb2_mand_lock,
  2663. .mand_unlock_range = smb2_unlock_range,
  2664. .push_mand_locks = smb2_push_mandatory_locks,
  2665. .get_lease_key = smb2_get_lease_key,
  2666. .set_lease_key = smb2_set_lease_key,
  2667. .new_lease_key = smb2_new_lease_key,
  2668. .generate_signingkey = generate_smb311signingkey,
  2669. .calc_signature = smb3_calc_signature,
  2670. .set_integrity = smb3_set_integrity,
  2671. .is_read_op = smb21_is_read_op,
  2672. .set_oplock_level = smb3_set_oplock_level,
  2673. .create_lease_buf = smb3_create_lease_buf,
  2674. .parse_lease_buf = smb3_parse_lease_buf,
  2675. .copychunk_range = smb2_copychunk_range,
  2676. .duplicate_extents = smb2_duplicate_extents,
  2677. /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
  2678. .wp_retry_size = smb2_wp_retry_size,
  2679. .dir_needs_close = smb2_dir_needs_close,
  2680. .fallocate = smb3_fallocate,
  2681. .enum_snapshots = smb3_enum_snapshots,
  2682. .init_transform_rq = smb3_init_transform_rq,
  2683. .free_transform_rq = smb3_free_transform_rq,
  2684. .is_transform_hdr = smb3_is_transform_hdr,
  2685. .receive_transform = smb3_receive_transform,
  2686. .get_dfs_refer = smb2_get_dfs_refer,
  2687. .select_sectype = smb2_select_sectype,
  2688. #ifdef CONFIG_CIFS_XATTR
  2689. .query_all_EAs = smb2_query_eas,
  2690. .set_EA = smb2_set_ea,
  2691. #endif /* CIFS_XATTR */
  2692. };
  2693. #endif /* CIFS_SMB311 */
  2694. struct smb_version_values smb20_values = {
  2695. .version_string = SMB20_VERSION_STRING,
  2696. .protocol_id = SMB20_PROT_ID,
  2697. .req_capabilities = 0, /* MBZ */
  2698. .large_lock_type = 0,
  2699. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  2700. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  2701. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  2702. .header_size = sizeof(struct smb2_hdr),
  2703. .max_header_size = MAX_SMB2_HDR_SIZE,
  2704. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  2705. .lock_cmd = SMB2_LOCK,
  2706. .cap_unix = 0,
  2707. .cap_nt_find = SMB2_NT_FIND,
  2708. .cap_large_files = SMB2_LARGE_FILES,
  2709. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2710. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2711. .create_lease_size = sizeof(struct create_lease),
  2712. };
  2713. struct smb_version_values smb21_values = {
  2714. .version_string = SMB21_VERSION_STRING,
  2715. .protocol_id = SMB21_PROT_ID,
  2716. .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
  2717. .large_lock_type = 0,
  2718. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  2719. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  2720. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  2721. .header_size = sizeof(struct smb2_hdr),
  2722. .max_header_size = MAX_SMB2_HDR_SIZE,
  2723. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  2724. .lock_cmd = SMB2_LOCK,
  2725. .cap_unix = 0,
  2726. .cap_nt_find = SMB2_NT_FIND,
  2727. .cap_large_files = SMB2_LARGE_FILES,
  2728. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2729. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2730. .create_lease_size = sizeof(struct create_lease),
  2731. };
  2732. struct smb_version_values smb3any_values = {
  2733. .version_string = SMB3ANY_VERSION_STRING,
  2734. .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
  2735. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
  2736. .large_lock_type = 0,
  2737. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  2738. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  2739. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  2740. .header_size = sizeof(struct smb2_hdr),
  2741. .max_header_size = MAX_SMB2_HDR_SIZE,
  2742. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  2743. .lock_cmd = SMB2_LOCK,
  2744. .cap_unix = 0,
  2745. .cap_nt_find = SMB2_NT_FIND,
  2746. .cap_large_files = SMB2_LARGE_FILES,
  2747. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2748. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2749. .create_lease_size = sizeof(struct create_lease_v2),
  2750. };
  2751. struct smb_version_values smbdefault_values = {
  2752. .version_string = SMBDEFAULT_VERSION_STRING,
  2753. .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
  2754. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
  2755. .large_lock_type = 0,
  2756. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  2757. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  2758. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  2759. .header_size = sizeof(struct smb2_hdr),
  2760. .max_header_size = MAX_SMB2_HDR_SIZE,
  2761. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  2762. .lock_cmd = SMB2_LOCK,
  2763. .cap_unix = 0,
  2764. .cap_nt_find = SMB2_NT_FIND,
  2765. .cap_large_files = SMB2_LARGE_FILES,
  2766. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2767. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2768. .create_lease_size = sizeof(struct create_lease_v2),
  2769. };
  2770. struct smb_version_values smb30_values = {
  2771. .version_string = SMB30_VERSION_STRING,
  2772. .protocol_id = SMB30_PROT_ID,
  2773. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
  2774. .large_lock_type = 0,
  2775. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  2776. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  2777. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  2778. .header_size = sizeof(struct smb2_hdr),
  2779. .max_header_size = MAX_SMB2_HDR_SIZE,
  2780. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  2781. .lock_cmd = SMB2_LOCK,
  2782. .cap_unix = 0,
  2783. .cap_nt_find = SMB2_NT_FIND,
  2784. .cap_large_files = SMB2_LARGE_FILES,
  2785. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2786. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2787. .create_lease_size = sizeof(struct create_lease_v2),
  2788. };
  2789. struct smb_version_values smb302_values = {
  2790. .version_string = SMB302_VERSION_STRING,
  2791. .protocol_id = SMB302_PROT_ID,
  2792. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
  2793. .large_lock_type = 0,
  2794. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  2795. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  2796. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  2797. .header_size = sizeof(struct smb2_hdr),
  2798. .max_header_size = MAX_SMB2_HDR_SIZE,
  2799. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  2800. .lock_cmd = SMB2_LOCK,
  2801. .cap_unix = 0,
  2802. .cap_nt_find = SMB2_NT_FIND,
  2803. .cap_large_files = SMB2_LARGE_FILES,
  2804. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2805. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2806. .create_lease_size = sizeof(struct create_lease_v2),
  2807. };
  2808. #ifdef CONFIG_CIFS_SMB311
  2809. struct smb_version_values smb311_values = {
  2810. .version_string = SMB311_VERSION_STRING,
  2811. .protocol_id = SMB311_PROT_ID,
  2812. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
  2813. .large_lock_type = 0,
  2814. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  2815. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  2816. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  2817. .header_size = sizeof(struct smb2_hdr),
  2818. .max_header_size = MAX_SMB2_HDR_SIZE,
  2819. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  2820. .lock_cmd = SMB2_LOCK,
  2821. .cap_unix = 0,
  2822. .cap_nt_find = SMB2_NT_FIND,
  2823. .cap_large_files = SMB2_LARGE_FILES,
  2824. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2825. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  2826. .create_lease_size = sizeof(struct create_lease_v2),
  2827. };
  2828. #endif /* SMB311 */