nfs4xdr.c 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244
  1. /*
  2. * fs/nfs/nfs4xdr.c
  3. *
  4. * Client-side XDR for NFSv4.
  5. *
  6. * Copyright (c) 2002 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Kendrick Smith <kmsmith@umich.edu>
  10. * Andy Adamson <andros@umich.edu>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the University nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  26. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  27. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  32. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #include <linux/param.h>
  38. #include <linux/time.h>
  39. #include <linux/mm.h>
  40. #include <linux/slab.h>
  41. #include <linux/utsname.h>
  42. #include <linux/errno.h>
  43. #include <linux/string.h>
  44. #include <linux/in.h>
  45. #include <linux/pagemap.h>
  46. #include <linux/proc_fs.h>
  47. #include <linux/kdev_t.h>
  48. #include <linux/sunrpc/clnt.h>
  49. #include <linux/nfs.h>
  50. #include <linux/nfs4.h>
  51. #include <linux/nfs_fs.h>
  52. #include <linux/nfs_idmap.h>
  53. #include "nfs4_fs.h"
  54. #define NFSDBG_FACILITY NFSDBG_XDR
  55. /* Mapping from NFS error code to "errno" error code. */
  56. #define errno_NFSERR_IO EIO
  57. static int nfs_stat_to_errno(int);
  58. /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
  59. #ifdef DEBUG
  60. #define NFS4_MAXTAGLEN 20
  61. #else
  62. #define NFS4_MAXTAGLEN 0
  63. #endif
  64. /* lock,open owner id:
  65. * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
  66. */
  67. #define owner_id_maxsz (1 + 1)
  68. #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  69. #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  70. #define op_encode_hdr_maxsz (1)
  71. #define op_decode_hdr_maxsz (2)
  72. #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
  73. (NFS4_FHSIZE >> 2))
  74. #define decode_putfh_maxsz (op_decode_hdr_maxsz)
  75. #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
  76. #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
  77. #define encode_getfh_maxsz (op_encode_hdr_maxsz)
  78. #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
  79. ((3+NFS4_FHSIZE) >> 2))
  80. #define nfs4_fattr_bitmap_maxsz 3
  81. #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
  82. #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
  83. #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
  84. /* This is based on getfattr, which uses the most attributes: */
  85. #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
  86. 3 + 3 + 3 + 2 * nfs4_name_maxsz))
  87. #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
  88. nfs4_fattr_value_maxsz)
  89. #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
  90. #define encode_savefh_maxsz (op_encode_hdr_maxsz)
  91. #define decode_savefh_maxsz (op_decode_hdr_maxsz)
  92. #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
  93. #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
  94. #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
  95. #define decode_renew_maxsz (op_decode_hdr_maxsz)
  96. #define encode_setclientid_maxsz \
  97. (op_encode_hdr_maxsz + \
  98. 4 /*server->ip_addr*/ + \
  99. 1 /*Netid*/ + \
  100. 6 /*uaddr*/ + \
  101. 6 + (NFS4_VERIFIER_SIZE >> 2))
  102. #define decode_setclientid_maxsz \
  103. (op_decode_hdr_maxsz + \
  104. 2 + \
  105. 1024) /* large value for CLID_INUSE */
  106. #define encode_setclientid_confirm_maxsz \
  107. (op_encode_hdr_maxsz + \
  108. 3 + (NFS4_VERIFIER_SIZE >> 2))
  109. #define decode_setclientid_confirm_maxsz \
  110. (op_decode_hdr_maxsz)
  111. #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
  112. 1 + ((3 + NFS4_FHSIZE) >> 2))
  113. #define encode_remove_maxsz (op_encode_hdr_maxsz + \
  114. nfs4_name_maxsz)
  115. #define encode_rename_maxsz (op_encode_hdr_maxsz + \
  116. 2 * nfs4_name_maxsz)
  117. #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
  118. #define encode_link_maxsz (op_encode_hdr_maxsz + \
  119. nfs4_name_maxsz)
  120. #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
  121. #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
  122. 1 + nfs4_name_maxsz + \
  123. nfs4_path_maxsz + \
  124. nfs4_fattr_maxsz)
  125. #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
  126. #define encode_create_maxsz (op_encode_hdr_maxsz + \
  127. 2 + nfs4_name_maxsz + \
  128. nfs4_fattr_maxsz)
  129. #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
  130. #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
  131. #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
  132. #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
  133. #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
  134. #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
  135. encode_putfh_maxsz + \
  136. op_encode_hdr_maxsz + 7)
  137. #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
  138. decode_putfh_maxsz + \
  139. op_decode_hdr_maxsz + 2)
  140. #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
  141. encode_putfh_maxsz + \
  142. op_encode_hdr_maxsz)
  143. #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
  144. decode_putfh_maxsz + \
  145. op_decode_hdr_maxsz)
  146. #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
  147. encode_putfh_maxsz + \
  148. op_encode_hdr_maxsz + 9)
  149. #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
  150. decode_putfh_maxsz + \
  151. op_decode_hdr_maxsz + 2)
  152. #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
  153. encode_putfh_maxsz + \
  154. op_encode_hdr_maxsz + 8)
  155. #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
  156. decode_putfh_maxsz + \
  157. op_decode_hdr_maxsz + 4)
  158. #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
  159. encode_putfh_maxsz + \
  160. op_encode_hdr_maxsz + 3)
  161. #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
  162. decode_putfh_maxsz + \
  163. op_decode_hdr_maxsz + 2)
  164. #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
  165. encode_putfh_maxsz + \
  166. op_encode_hdr_maxsz + \
  167. 13 + 3 + 2 + 64 + \
  168. encode_getattr_maxsz + \
  169. encode_getfh_maxsz)
  170. #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
  171. decode_putfh_maxsz + \
  172. op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
  173. decode_getattr_maxsz + \
  174. decode_getfh_maxsz)
  175. #define NFS4_enc_open_confirm_sz \
  176. (compound_encode_hdr_maxsz + \
  177. encode_putfh_maxsz + \
  178. op_encode_hdr_maxsz + 5)
  179. #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
  180. decode_putfh_maxsz + \
  181. op_decode_hdr_maxsz + 4)
  182. #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
  183. encode_putfh_maxsz + \
  184. op_encode_hdr_maxsz + \
  185. 11)
  186. #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
  187. decode_putfh_maxsz + \
  188. op_decode_hdr_maxsz + \
  189. 4 + 5 + 2 + 3)
  190. #define NFS4_enc_open_downgrade_sz \
  191. (compound_encode_hdr_maxsz + \
  192. encode_putfh_maxsz + \
  193. op_encode_hdr_maxsz + 7)
  194. #define NFS4_dec_open_downgrade_sz \
  195. (compound_decode_hdr_maxsz + \
  196. decode_putfh_maxsz + \
  197. op_decode_hdr_maxsz + 4)
  198. #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
  199. encode_putfh_maxsz + \
  200. op_encode_hdr_maxsz + 5)
  201. #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
  202. decode_putfh_maxsz + \
  203. op_decode_hdr_maxsz + 4)
  204. #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
  205. encode_putfh_maxsz + \
  206. op_encode_hdr_maxsz + 4 + \
  207. nfs4_fattr_maxsz + \
  208. encode_getattr_maxsz)
  209. #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
  210. decode_putfh_maxsz + \
  211. op_decode_hdr_maxsz + 3)
  212. #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
  213. encode_putfh_maxsz + \
  214. encode_fsinfo_maxsz)
  215. #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
  216. decode_putfh_maxsz + \
  217. decode_fsinfo_maxsz)
  218. #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
  219. encode_renew_maxsz)
  220. #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
  221. decode_renew_maxsz)
  222. #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
  223. encode_setclientid_maxsz)
  224. #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
  225. decode_setclientid_maxsz)
  226. #define NFS4_enc_setclientid_confirm_sz \
  227. (compound_encode_hdr_maxsz + \
  228. encode_setclientid_confirm_maxsz + \
  229. encode_putrootfh_maxsz + \
  230. encode_fsinfo_maxsz)
  231. #define NFS4_dec_setclientid_confirm_sz \
  232. (compound_decode_hdr_maxsz + \
  233. decode_setclientid_confirm_maxsz + \
  234. decode_putrootfh_maxsz + \
  235. decode_fsinfo_maxsz)
  236. #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
  237. encode_putfh_maxsz + \
  238. encode_getattr_maxsz + \
  239. op_encode_hdr_maxsz + \
  240. 1 + 1 + 2 + 2 + \
  241. 1 + 4 + 1 + 2 + \
  242. owner_id_maxsz)
  243. #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
  244. decode_putfh_maxsz + \
  245. decode_getattr_maxsz + \
  246. op_decode_hdr_maxsz + \
  247. 2 + 2 + 1 + 2 + \
  248. owner_id_maxsz)
  249. #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
  250. encode_putfh_maxsz + \
  251. encode_getattr_maxsz + \
  252. op_encode_hdr_maxsz + \
  253. 1 + 2 + 2 + 2 + \
  254. owner_id_maxsz)
  255. #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
  256. #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
  257. encode_putfh_maxsz + \
  258. encode_getattr_maxsz + \
  259. op_encode_hdr_maxsz + \
  260. 1 + 1 + 4 + 2 + 2)
  261. #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
  262. decode_putfh_maxsz + \
  263. decode_getattr_maxsz + \
  264. op_decode_hdr_maxsz + 4)
  265. #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
  266. encode_putfh_maxsz + \
  267. op_encode_hdr_maxsz + 1)
  268. #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
  269. decode_putfh_maxsz + \
  270. op_decode_hdr_maxsz + 2)
  271. #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
  272. encode_putfh_maxsz + \
  273. encode_getattr_maxsz)
  274. #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
  275. decode_putfh_maxsz + \
  276. decode_getattr_maxsz)
  277. #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
  278. encode_putfh_maxsz + \
  279. encode_lookup_maxsz + \
  280. encode_getattr_maxsz + \
  281. encode_getfh_maxsz)
  282. #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
  283. decode_putfh_maxsz + \
  284. op_decode_hdr_maxsz + \
  285. decode_getattr_maxsz + \
  286. decode_getfh_maxsz)
  287. #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
  288. encode_putrootfh_maxsz + \
  289. encode_getattr_maxsz + \
  290. encode_getfh_maxsz)
  291. #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
  292. decode_putrootfh_maxsz + \
  293. decode_getattr_maxsz + \
  294. decode_getfh_maxsz)
  295. #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
  296. encode_putfh_maxsz + \
  297. encode_remove_maxsz)
  298. #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
  299. decode_putfh_maxsz + \
  300. op_decode_hdr_maxsz + 5)
  301. #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
  302. encode_putfh_maxsz + \
  303. encode_savefh_maxsz + \
  304. encode_putfh_maxsz + \
  305. encode_rename_maxsz)
  306. #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
  307. decode_putfh_maxsz + \
  308. decode_savefh_maxsz + \
  309. decode_putfh_maxsz + \
  310. decode_rename_maxsz)
  311. #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
  312. encode_putfh_maxsz + \
  313. encode_savefh_maxsz + \
  314. encode_putfh_maxsz + \
  315. encode_link_maxsz)
  316. #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
  317. decode_putfh_maxsz + \
  318. decode_savefh_maxsz + \
  319. decode_putfh_maxsz + \
  320. decode_link_maxsz)
  321. #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
  322. encode_putfh_maxsz + \
  323. encode_symlink_maxsz + \
  324. encode_getattr_maxsz + \
  325. encode_getfh_maxsz)
  326. #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
  327. decode_putfh_maxsz + \
  328. decode_symlink_maxsz + \
  329. decode_getattr_maxsz + \
  330. decode_getfh_maxsz)
  331. #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
  332. encode_putfh_maxsz + \
  333. encode_create_maxsz + \
  334. encode_getattr_maxsz + \
  335. encode_getfh_maxsz)
  336. #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
  337. decode_putfh_maxsz + \
  338. decode_create_maxsz + \
  339. decode_getattr_maxsz + \
  340. decode_getfh_maxsz)
  341. #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
  342. encode_putfh_maxsz + \
  343. encode_getattr_maxsz)
  344. #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
  345. decode_putfh_maxsz + \
  346. decode_getattr_maxsz)
  347. #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
  348. encode_putfh_maxsz + \
  349. encode_getattr_maxsz)
  350. #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
  351. decode_putfh_maxsz + \
  352. op_decode_hdr_maxsz + 12)
  353. #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
  354. encode_getattr_maxsz)
  355. #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
  356. decode_getattr_maxsz)
  357. #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
  358. encode_putfh_maxsz + \
  359. encode_delegreturn_maxsz)
  360. #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
  361. decode_delegreturn_maxsz)
  362. #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
  363. encode_putfh_maxsz + \
  364. encode_getattr_maxsz)
  365. #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
  366. decode_putfh_maxsz + \
  367. op_decode_hdr_maxsz + \
  368. nfs4_fattr_bitmap_maxsz + 1)
  369. #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
  370. encode_putfh_maxsz + \
  371. op_encode_hdr_maxsz + 4 + \
  372. nfs4_fattr_bitmap_maxsz + 1)
  373. #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
  374. decode_putfh_maxsz + \
  375. op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
  376. static struct {
  377. unsigned int mode;
  378. unsigned int nfs2type;
  379. } nfs_type2fmt[] = {
  380. { 0, NFNON },
  381. { S_IFREG, NFREG },
  382. { S_IFDIR, NFDIR },
  383. { S_IFBLK, NFBLK },
  384. { S_IFCHR, NFCHR },
  385. { S_IFLNK, NFLNK },
  386. { S_IFSOCK, NFSOCK },
  387. { S_IFIFO, NFFIFO },
  388. { 0, NFNON },
  389. { 0, NFNON },
  390. };
  391. struct compound_hdr {
  392. int32_t status;
  393. uint32_t nops;
  394. uint32_t taglen;
  395. char * tag;
  396. };
  397. /*
  398. * START OF "GENERIC" ENCODE ROUTINES.
  399. * These may look a little ugly since they are imported from a "generic"
  400. * set of XDR encode/decode routines which are intended to be shared by
  401. * all of our NFSv4 implementations (OpenBSD, MacOS X...).
  402. *
  403. * If the pain of reading these is too great, it should be a straightforward
  404. * task to translate them into Linux-specific versions which are more
  405. * consistent with the style used in NFSv2/v3...
  406. */
  407. #define WRITE32(n) *p++ = htonl(n)
  408. #define WRITE64(n) do { \
  409. *p++ = htonl((uint32_t)((n) >> 32)); \
  410. *p++ = htonl((uint32_t)(n)); \
  411. } while (0)
  412. #define WRITEMEM(ptr,nbytes) do { \
  413. p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
  414. } while (0)
  415. #define RESERVE_SPACE(nbytes) do { \
  416. p = xdr_reserve_space(xdr, nbytes); \
  417. if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
  418. BUG_ON(!p); \
  419. } while (0)
  420. static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
  421. {
  422. uint32_t *p;
  423. p = xdr_reserve_space(xdr, 4 + len);
  424. BUG_ON(p == NULL);
  425. xdr_encode_opaque(p, str, len);
  426. }
  427. static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  428. {
  429. uint32_t *p;
  430. dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
  431. BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
  432. RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
  433. WRITE32(hdr->taglen);
  434. WRITEMEM(hdr->tag, hdr->taglen);
  435. WRITE32(NFS4_MINOR_VERSION);
  436. WRITE32(hdr->nops);
  437. return 0;
  438. }
  439. static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
  440. {
  441. uint32_t *p;
  442. p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
  443. BUG_ON(p == NULL);
  444. xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
  445. }
  446. static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
  447. {
  448. char owner_name[IDMAP_NAMESZ];
  449. char owner_group[IDMAP_NAMESZ];
  450. int owner_namelen = 0;
  451. int owner_grouplen = 0;
  452. uint32_t *p;
  453. uint32_t *q;
  454. int len;
  455. uint32_t bmval0 = 0;
  456. uint32_t bmval1 = 0;
  457. int status;
  458. /*
  459. * We reserve enough space to write the entire attribute buffer at once.
  460. * In the worst-case, this would be
  461. * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
  462. * = 36 bytes, plus any contribution from variable-length fields
  463. * such as owner/group.
  464. */
  465. len = 16;
  466. /* Sigh */
  467. if (iap->ia_valid & ATTR_SIZE)
  468. len += 8;
  469. if (iap->ia_valid & ATTR_MODE)
  470. len += 4;
  471. if (iap->ia_valid & ATTR_UID) {
  472. owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
  473. if (owner_namelen < 0) {
  474. printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
  475. iap->ia_uid);
  476. /* XXX */
  477. strcpy(owner_name, "nobody");
  478. owner_namelen = sizeof("nobody") - 1;
  479. /* goto out; */
  480. }
  481. len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
  482. }
  483. if (iap->ia_valid & ATTR_GID) {
  484. owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
  485. if (owner_grouplen < 0) {
  486. printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
  487. iap->ia_gid);
  488. strcpy(owner_group, "nobody");
  489. owner_grouplen = sizeof("nobody") - 1;
  490. /* goto out; */
  491. }
  492. len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
  493. }
  494. if (iap->ia_valid & ATTR_ATIME_SET)
  495. len += 16;
  496. else if (iap->ia_valid & ATTR_ATIME)
  497. len += 4;
  498. if (iap->ia_valid & ATTR_MTIME_SET)
  499. len += 16;
  500. else if (iap->ia_valid & ATTR_MTIME)
  501. len += 4;
  502. RESERVE_SPACE(len);
  503. /*
  504. * We write the bitmap length now, but leave the bitmap and the attribute
  505. * buffer length to be backfilled at the end of this routine.
  506. */
  507. WRITE32(2);
  508. q = p;
  509. p += 3;
  510. if (iap->ia_valid & ATTR_SIZE) {
  511. bmval0 |= FATTR4_WORD0_SIZE;
  512. WRITE64(iap->ia_size);
  513. }
  514. if (iap->ia_valid & ATTR_MODE) {
  515. bmval1 |= FATTR4_WORD1_MODE;
  516. WRITE32(iap->ia_mode);
  517. }
  518. if (iap->ia_valid & ATTR_UID) {
  519. bmval1 |= FATTR4_WORD1_OWNER;
  520. WRITE32(owner_namelen);
  521. WRITEMEM(owner_name, owner_namelen);
  522. }
  523. if (iap->ia_valid & ATTR_GID) {
  524. bmval1 |= FATTR4_WORD1_OWNER_GROUP;
  525. WRITE32(owner_grouplen);
  526. WRITEMEM(owner_group, owner_grouplen);
  527. }
  528. if (iap->ia_valid & ATTR_ATIME_SET) {
  529. bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
  530. WRITE32(NFS4_SET_TO_CLIENT_TIME);
  531. WRITE32(0);
  532. WRITE32(iap->ia_mtime.tv_sec);
  533. WRITE32(iap->ia_mtime.tv_nsec);
  534. }
  535. else if (iap->ia_valid & ATTR_ATIME) {
  536. bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
  537. WRITE32(NFS4_SET_TO_SERVER_TIME);
  538. }
  539. if (iap->ia_valid & ATTR_MTIME_SET) {
  540. bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
  541. WRITE32(NFS4_SET_TO_CLIENT_TIME);
  542. WRITE32(0);
  543. WRITE32(iap->ia_mtime.tv_sec);
  544. WRITE32(iap->ia_mtime.tv_nsec);
  545. }
  546. else if (iap->ia_valid & ATTR_MTIME) {
  547. bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
  548. WRITE32(NFS4_SET_TO_SERVER_TIME);
  549. }
  550. /*
  551. * Now we backfill the bitmap and the attribute buffer length.
  552. */
  553. if (len != ((char *)p - (char *)q) + 4) {
  554. printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
  555. len, ((char *)p - (char *)q) + 4);
  556. BUG();
  557. }
  558. len = (char *)p - (char *)q - 12;
  559. *q++ = htonl(bmval0);
  560. *q++ = htonl(bmval1);
  561. *q++ = htonl(len);
  562. status = 0;
  563. /* out: */
  564. return status;
  565. }
  566. static int encode_access(struct xdr_stream *xdr, u32 access)
  567. {
  568. uint32_t *p;
  569. RESERVE_SPACE(8);
  570. WRITE32(OP_ACCESS);
  571. WRITE32(access);
  572. return 0;
  573. }
  574. static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
  575. {
  576. uint32_t *p;
  577. RESERVE_SPACE(8+sizeof(arg->stateid->data));
  578. WRITE32(OP_CLOSE);
  579. WRITE32(arg->seqid->sequence->counter);
  580. WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
  581. return 0;
  582. }
  583. static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
  584. {
  585. uint32_t *p;
  586. RESERVE_SPACE(16);
  587. WRITE32(OP_COMMIT);
  588. WRITE64(args->offset);
  589. WRITE32(args->count);
  590. return 0;
  591. }
  592. static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
  593. {
  594. uint32_t *p;
  595. RESERVE_SPACE(8);
  596. WRITE32(OP_CREATE);
  597. WRITE32(create->ftype);
  598. switch (create->ftype) {
  599. case NF4LNK:
  600. RESERVE_SPACE(4 + create->u.symlink->len);
  601. WRITE32(create->u.symlink->len);
  602. WRITEMEM(create->u.symlink->name, create->u.symlink->len);
  603. break;
  604. case NF4BLK: case NF4CHR:
  605. RESERVE_SPACE(8);
  606. WRITE32(create->u.device.specdata1);
  607. WRITE32(create->u.device.specdata2);
  608. break;
  609. default:
  610. break;
  611. }
  612. RESERVE_SPACE(4 + create->name->len);
  613. WRITE32(create->name->len);
  614. WRITEMEM(create->name->name, create->name->len);
  615. return encode_attrs(xdr, create->attrs, create->server);
  616. }
  617. static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
  618. {
  619. uint32_t *p;
  620. RESERVE_SPACE(12);
  621. WRITE32(OP_GETATTR);
  622. WRITE32(1);
  623. WRITE32(bitmap);
  624. return 0;
  625. }
  626. static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
  627. {
  628. uint32_t *p;
  629. RESERVE_SPACE(16);
  630. WRITE32(OP_GETATTR);
  631. WRITE32(2);
  632. WRITE32(bm0);
  633. WRITE32(bm1);
  634. return 0;
  635. }
  636. static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
  637. {
  638. return encode_getattr_two(xdr,
  639. bitmask[0] & nfs4_fattr_bitmap[0],
  640. bitmask[1] & nfs4_fattr_bitmap[1]);
  641. }
  642. static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
  643. {
  644. return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
  645. bitmask[1] & nfs4_fsinfo_bitmap[1]);
  646. }
  647. static int encode_getfh(struct xdr_stream *xdr)
  648. {
  649. uint32_t *p;
  650. RESERVE_SPACE(4);
  651. WRITE32(OP_GETFH);
  652. return 0;
  653. }
  654. static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
  655. {
  656. uint32_t *p;
  657. RESERVE_SPACE(8 + name->len);
  658. WRITE32(OP_LINK);
  659. WRITE32(name->len);
  660. WRITEMEM(name->name, name->len);
  661. return 0;
  662. }
  663. /*
  664. * opcode,type,reclaim,offset,length,new_lock_owner = 32
  665. * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
  666. */
  667. static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
  668. {
  669. uint32_t *p;
  670. struct nfs_lock_opargs *opargs = arg->u.lock;
  671. RESERVE_SPACE(32);
  672. WRITE32(OP_LOCK);
  673. WRITE32(arg->type);
  674. WRITE32(opargs->reclaim);
  675. WRITE64(arg->offset);
  676. WRITE64(arg->length);
  677. WRITE32(opargs->new_lock_owner);
  678. if (opargs->new_lock_owner){
  679. RESERVE_SPACE(40);
  680. WRITE32(opargs->open_seqid->sequence->counter);
  681. WRITEMEM(opargs->open_stateid->data, sizeof(opargs->open_stateid->data));
  682. WRITE32(opargs->lock_seqid->sequence->counter);
  683. WRITE64(opargs->lock_owner.clientid);
  684. WRITE32(4);
  685. WRITE32(opargs->lock_owner.id);
  686. }
  687. else {
  688. RESERVE_SPACE(20);
  689. WRITEMEM(opargs->lock_stateid->data, sizeof(opargs->lock_stateid->data));
  690. WRITE32(opargs->lock_seqid->sequence->counter);
  691. }
  692. return 0;
  693. }
  694. static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
  695. {
  696. uint32_t *p;
  697. struct nfs_lowner *opargs = arg->u.lockt;
  698. RESERVE_SPACE(40);
  699. WRITE32(OP_LOCKT);
  700. WRITE32(arg->type);
  701. WRITE64(arg->offset);
  702. WRITE64(arg->length);
  703. WRITE64(opargs->clientid);
  704. WRITE32(4);
  705. WRITE32(opargs->id);
  706. return 0;
  707. }
  708. static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
  709. {
  710. uint32_t *p;
  711. struct nfs_locku_opargs *opargs = arg->u.locku;
  712. RESERVE_SPACE(44);
  713. WRITE32(OP_LOCKU);
  714. WRITE32(arg->type);
  715. WRITE32(opargs->seqid->sequence->counter);
  716. WRITEMEM(opargs->stateid->data, sizeof(opargs->stateid->data));
  717. WRITE64(arg->offset);
  718. WRITE64(arg->length);
  719. return 0;
  720. }
  721. static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
  722. {
  723. int len = name->len;
  724. uint32_t *p;
  725. RESERVE_SPACE(8 + len);
  726. WRITE32(OP_LOOKUP);
  727. WRITE32(len);
  728. WRITEMEM(name->name, len);
  729. return 0;
  730. }
  731. static void encode_share_access(struct xdr_stream *xdr, int open_flags)
  732. {
  733. uint32_t *p;
  734. RESERVE_SPACE(8);
  735. switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
  736. case FMODE_READ:
  737. WRITE32(NFS4_SHARE_ACCESS_READ);
  738. break;
  739. case FMODE_WRITE:
  740. WRITE32(NFS4_SHARE_ACCESS_WRITE);
  741. break;
  742. case FMODE_READ|FMODE_WRITE:
  743. WRITE32(NFS4_SHARE_ACCESS_BOTH);
  744. break;
  745. default:
  746. BUG();
  747. }
  748. WRITE32(0); /* for linux, share_deny = 0 always */
  749. }
  750. static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  751. {
  752. uint32_t *p;
  753. /*
  754. * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
  755. * owner 4 = 32
  756. */
  757. RESERVE_SPACE(8);
  758. WRITE32(OP_OPEN);
  759. WRITE32(arg->seqid->sequence->counter);
  760. encode_share_access(xdr, arg->open_flags);
  761. RESERVE_SPACE(16);
  762. WRITE64(arg->clientid);
  763. WRITE32(4);
  764. WRITE32(arg->id);
  765. }
  766. static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  767. {
  768. uint32_t *p;
  769. RESERVE_SPACE(4);
  770. switch(arg->open_flags & O_EXCL) {
  771. case 0:
  772. WRITE32(NFS4_CREATE_UNCHECKED);
  773. encode_attrs(xdr, arg->u.attrs, arg->server);
  774. break;
  775. default:
  776. WRITE32(NFS4_CREATE_EXCLUSIVE);
  777. encode_nfs4_verifier(xdr, &arg->u.verifier);
  778. }
  779. }
  780. static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  781. {
  782. uint32_t *p;
  783. RESERVE_SPACE(4);
  784. switch (arg->open_flags & O_CREAT) {
  785. case 0:
  786. WRITE32(NFS4_OPEN_NOCREATE);
  787. break;
  788. default:
  789. BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
  790. WRITE32(NFS4_OPEN_CREATE);
  791. encode_createmode(xdr, arg);
  792. }
  793. }
  794. static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
  795. {
  796. uint32_t *p;
  797. RESERVE_SPACE(4);
  798. switch (delegation_type) {
  799. case 0:
  800. WRITE32(NFS4_OPEN_DELEGATE_NONE);
  801. break;
  802. case FMODE_READ:
  803. WRITE32(NFS4_OPEN_DELEGATE_READ);
  804. break;
  805. case FMODE_WRITE|FMODE_READ:
  806. WRITE32(NFS4_OPEN_DELEGATE_WRITE);
  807. break;
  808. default:
  809. BUG();
  810. }
  811. }
  812. static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
  813. {
  814. uint32_t *p;
  815. RESERVE_SPACE(4);
  816. WRITE32(NFS4_OPEN_CLAIM_NULL);
  817. encode_string(xdr, name->len, name->name);
  818. }
  819. static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
  820. {
  821. uint32_t *p;
  822. RESERVE_SPACE(4);
  823. WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
  824. encode_delegation_type(xdr, type);
  825. }
  826. static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
  827. {
  828. uint32_t *p;
  829. RESERVE_SPACE(4+sizeof(stateid->data));
  830. WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
  831. WRITEMEM(stateid->data, sizeof(stateid->data));
  832. encode_string(xdr, name->len, name->name);
  833. }
  834. static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  835. {
  836. encode_openhdr(xdr, arg);
  837. encode_opentype(xdr, arg);
  838. switch (arg->claim) {
  839. case NFS4_OPEN_CLAIM_NULL:
  840. encode_claim_null(xdr, arg->name);
  841. break;
  842. case NFS4_OPEN_CLAIM_PREVIOUS:
  843. encode_claim_previous(xdr, arg->u.delegation_type);
  844. break;
  845. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  846. encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
  847. break;
  848. default:
  849. BUG();
  850. }
  851. return 0;
  852. }
  853. static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
  854. {
  855. uint32_t *p;
  856. RESERVE_SPACE(8+sizeof(arg->stateid.data));
  857. WRITE32(OP_OPEN_CONFIRM);
  858. WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
  859. WRITE32(arg->seqid->sequence->counter);
  860. return 0;
  861. }
  862. static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
  863. {
  864. uint32_t *p;
  865. RESERVE_SPACE(8+sizeof(arg->stateid->data));
  866. WRITE32(OP_OPEN_DOWNGRADE);
  867. WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
  868. WRITE32(arg->seqid->sequence->counter);
  869. encode_share_access(xdr, arg->open_flags);
  870. return 0;
  871. }
  872. static int
  873. encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
  874. {
  875. int len = fh->size;
  876. uint32_t *p;
  877. RESERVE_SPACE(8 + len);
  878. WRITE32(OP_PUTFH);
  879. WRITE32(len);
  880. WRITEMEM(fh->data, len);
  881. return 0;
  882. }
  883. static int encode_putrootfh(struct xdr_stream *xdr)
  884. {
  885. uint32_t *p;
  886. RESERVE_SPACE(4);
  887. WRITE32(OP_PUTROOTFH);
  888. return 0;
  889. }
  890. static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
  891. {
  892. nfs4_stateid stateid;
  893. uint32_t *p;
  894. RESERVE_SPACE(16);
  895. if (ctx->state != NULL) {
  896. nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
  897. WRITEMEM(stateid.data, sizeof(stateid.data));
  898. } else
  899. WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
  900. }
  901. static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
  902. {
  903. uint32_t *p;
  904. RESERVE_SPACE(4);
  905. WRITE32(OP_READ);
  906. encode_stateid(xdr, args->context);
  907. RESERVE_SPACE(12);
  908. WRITE64(args->offset);
  909. WRITE32(args->count);
  910. return 0;
  911. }
  912. static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
  913. {
  914. struct rpc_auth *auth = req->rq_task->tk_auth;
  915. uint32_t attrs[2] = {
  916. FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
  917. FATTR4_WORD1_MOUNTED_ON_FILEID,
  918. };
  919. int replen;
  920. uint32_t *p;
  921. RESERVE_SPACE(32+sizeof(nfs4_verifier));
  922. WRITE32(OP_READDIR);
  923. WRITE64(readdir->cookie);
  924. WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
  925. WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
  926. WRITE32(readdir->count);
  927. WRITE32(2);
  928. /* Switch to mounted_on_fileid if the server supports it */
  929. if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
  930. attrs[0] &= ~FATTR4_WORD0_FILEID;
  931. else
  932. attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  933. WRITE32(attrs[0] & readdir->bitmask[0]);
  934. WRITE32(attrs[1] & readdir->bitmask[1]);
  935. dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
  936. __FUNCTION__,
  937. (unsigned long long)readdir->cookie,
  938. ((u32 *)readdir->verifier.data)[0],
  939. ((u32 *)readdir->verifier.data)[1],
  940. attrs[0] & readdir->bitmask[0],
  941. attrs[1] & readdir->bitmask[1]);
  942. /* set up reply kvec
  943. * toplevel_status + taglen + rescount + OP_PUTFH + status
  944. * + OP_READDIR + status + verifer(2) = 9
  945. */
  946. replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
  947. xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
  948. readdir->pgbase, readdir->count);
  949. dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
  950. __FUNCTION__, replen, readdir->pages,
  951. readdir->pgbase, readdir->count);
  952. return 0;
  953. }
  954. static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
  955. {
  956. struct rpc_auth *auth = req->rq_task->tk_auth;
  957. unsigned int replen;
  958. uint32_t *p;
  959. RESERVE_SPACE(4);
  960. WRITE32(OP_READLINK);
  961. /* set up reply kvec
  962. * toplevel_status + taglen + rescount + OP_PUTFH + status
  963. * + OP_READLINK + status + string length = 8
  964. */
  965. replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
  966. xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
  967. readlink->pgbase, readlink->pglen);
  968. return 0;
  969. }
  970. static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
  971. {
  972. uint32_t *p;
  973. RESERVE_SPACE(8 + name->len);
  974. WRITE32(OP_REMOVE);
  975. WRITE32(name->len);
  976. WRITEMEM(name->name, name->len);
  977. return 0;
  978. }
  979. static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
  980. {
  981. uint32_t *p;
  982. RESERVE_SPACE(8 + oldname->len);
  983. WRITE32(OP_RENAME);
  984. WRITE32(oldname->len);
  985. WRITEMEM(oldname->name, oldname->len);
  986. RESERVE_SPACE(4 + newname->len);
  987. WRITE32(newname->len);
  988. WRITEMEM(newname->name, newname->len);
  989. return 0;
  990. }
  991. static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
  992. {
  993. uint32_t *p;
  994. RESERVE_SPACE(12);
  995. WRITE32(OP_RENEW);
  996. WRITE64(client_stateid->cl_clientid);
  997. return 0;
  998. }
  999. static int
  1000. encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
  1001. {
  1002. uint32_t *p;
  1003. RESERVE_SPACE(4+sizeof(zero_stateid.data));
  1004. WRITE32(OP_SETATTR);
  1005. WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
  1006. RESERVE_SPACE(2*4);
  1007. WRITE32(1);
  1008. WRITE32(FATTR4_WORD0_ACL);
  1009. if (arg->acl_len % 4)
  1010. return -EINVAL;
  1011. RESERVE_SPACE(4);
  1012. WRITE32(arg->acl_len);
  1013. xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
  1014. return 0;
  1015. }
  1016. static int
  1017. encode_savefh(struct xdr_stream *xdr)
  1018. {
  1019. uint32_t *p;
  1020. RESERVE_SPACE(4);
  1021. WRITE32(OP_SAVEFH);
  1022. return 0;
  1023. }
  1024. static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
  1025. {
  1026. int status;
  1027. uint32_t *p;
  1028. RESERVE_SPACE(4+sizeof(arg->stateid.data));
  1029. WRITE32(OP_SETATTR);
  1030. WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
  1031. if ((status = encode_attrs(xdr, arg->iap, server)))
  1032. return status;
  1033. return 0;
  1034. }
  1035. static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
  1036. {
  1037. uint32_t *p;
  1038. RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
  1039. WRITE32(OP_SETCLIENTID);
  1040. WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
  1041. encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
  1042. RESERVE_SPACE(4);
  1043. WRITE32(setclientid->sc_prog);
  1044. encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
  1045. encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
  1046. RESERVE_SPACE(4);
  1047. WRITE32(setclientid->sc_cb_ident);
  1048. return 0;
  1049. }
  1050. static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
  1051. {
  1052. uint32_t *p;
  1053. RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
  1054. WRITE32(OP_SETCLIENTID_CONFIRM);
  1055. WRITE64(client_state->cl_clientid);
  1056. WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
  1057. return 0;
  1058. }
  1059. static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
  1060. {
  1061. uint32_t *p;
  1062. RESERVE_SPACE(4);
  1063. WRITE32(OP_WRITE);
  1064. encode_stateid(xdr, args->context);
  1065. RESERVE_SPACE(16);
  1066. WRITE64(args->offset);
  1067. WRITE32(args->stable);
  1068. WRITE32(args->count);
  1069. xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
  1070. return 0;
  1071. }
  1072. static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
  1073. {
  1074. uint32_t *p;
  1075. RESERVE_SPACE(20);
  1076. WRITE32(OP_DELEGRETURN);
  1077. WRITEMEM(stateid->data, sizeof(stateid->data));
  1078. return 0;
  1079. }
  1080. /*
  1081. * END OF "GENERIC" ENCODE ROUTINES.
  1082. */
  1083. /*
  1084. * Encode an ACCESS request
  1085. */
  1086. static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
  1087. {
  1088. struct xdr_stream xdr;
  1089. struct compound_hdr hdr = {
  1090. .nops = 2,
  1091. };
  1092. int status;
  1093. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1094. encode_compound_hdr(&xdr, &hdr);
  1095. if ((status = encode_putfh(&xdr, args->fh)) == 0)
  1096. status = encode_access(&xdr, args->access);
  1097. return status;
  1098. }
  1099. /*
  1100. * Encode LOOKUP request
  1101. */
  1102. static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
  1103. {
  1104. struct xdr_stream xdr;
  1105. struct compound_hdr hdr = {
  1106. .nops = 4,
  1107. };
  1108. int status;
  1109. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1110. encode_compound_hdr(&xdr, &hdr);
  1111. if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
  1112. goto out;
  1113. if ((status = encode_lookup(&xdr, args->name)) != 0)
  1114. goto out;
  1115. if ((status = encode_getfh(&xdr)) != 0)
  1116. goto out;
  1117. status = encode_getfattr(&xdr, args->bitmask);
  1118. out:
  1119. return status;
  1120. }
  1121. /*
  1122. * Encode LOOKUP_ROOT request
  1123. */
  1124. static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
  1125. {
  1126. struct xdr_stream xdr;
  1127. struct compound_hdr hdr = {
  1128. .nops = 3,
  1129. };
  1130. int status;
  1131. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1132. encode_compound_hdr(&xdr, &hdr);
  1133. if ((status = encode_putrootfh(&xdr)) != 0)
  1134. goto out;
  1135. if ((status = encode_getfh(&xdr)) == 0)
  1136. status = encode_getfattr(&xdr, args->bitmask);
  1137. out:
  1138. return status;
  1139. }
  1140. /*
  1141. * Encode REMOVE request
  1142. */
  1143. static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
  1144. {
  1145. struct xdr_stream xdr;
  1146. struct compound_hdr hdr = {
  1147. .nops = 2,
  1148. };
  1149. int status;
  1150. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1151. encode_compound_hdr(&xdr, &hdr);
  1152. if ((status = encode_putfh(&xdr, args->fh)) == 0)
  1153. status = encode_remove(&xdr, args->name);
  1154. return status;
  1155. }
  1156. /*
  1157. * Encode RENAME request
  1158. */
  1159. static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
  1160. {
  1161. struct xdr_stream xdr;
  1162. struct compound_hdr hdr = {
  1163. .nops = 4,
  1164. };
  1165. int status;
  1166. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1167. encode_compound_hdr(&xdr, &hdr);
  1168. if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
  1169. goto out;
  1170. if ((status = encode_savefh(&xdr)) != 0)
  1171. goto out;
  1172. if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
  1173. goto out;
  1174. status = encode_rename(&xdr, args->old_name, args->new_name);
  1175. out:
  1176. return status;
  1177. }
  1178. /*
  1179. * Encode LINK request
  1180. */
  1181. static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
  1182. {
  1183. struct xdr_stream xdr;
  1184. struct compound_hdr hdr = {
  1185. .nops = 4,
  1186. };
  1187. int status;
  1188. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1189. encode_compound_hdr(&xdr, &hdr);
  1190. if ((status = encode_putfh(&xdr, args->fh)) != 0)
  1191. goto out;
  1192. if ((status = encode_savefh(&xdr)) != 0)
  1193. goto out;
  1194. if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
  1195. goto out;
  1196. status = encode_link(&xdr, args->name);
  1197. out:
  1198. return status;
  1199. }
  1200. /*
  1201. * Encode CREATE request
  1202. */
  1203. static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
  1204. {
  1205. struct xdr_stream xdr;
  1206. struct compound_hdr hdr = {
  1207. .nops = 4,
  1208. };
  1209. int status;
  1210. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1211. encode_compound_hdr(&xdr, &hdr);
  1212. if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
  1213. goto out;
  1214. if ((status = encode_create(&xdr, args)) != 0)
  1215. goto out;
  1216. if ((status = encode_getfh(&xdr)) != 0)
  1217. goto out;
  1218. status = encode_getfattr(&xdr, args->bitmask);
  1219. out:
  1220. return status;
  1221. }
  1222. /*
  1223. * Encode SYMLINK request
  1224. */
  1225. static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
  1226. {
  1227. return nfs4_xdr_enc_create(req, p, args);
  1228. }
  1229. /*
  1230. * Encode GETATTR request
  1231. */
  1232. static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
  1233. {
  1234. struct xdr_stream xdr;
  1235. struct compound_hdr hdr = {
  1236. .nops = 2,
  1237. };
  1238. int status;
  1239. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1240. encode_compound_hdr(&xdr, &hdr);
  1241. if ((status = encode_putfh(&xdr, args->fh)) == 0)
  1242. status = encode_getfattr(&xdr, args->bitmask);
  1243. return status;
  1244. }
  1245. /*
  1246. * Encode a CLOSE request
  1247. */
  1248. static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
  1249. {
  1250. struct xdr_stream xdr;
  1251. struct compound_hdr hdr = {
  1252. .nops = 2,
  1253. };
  1254. int status;
  1255. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1256. encode_compound_hdr(&xdr, &hdr);
  1257. status = encode_putfh(&xdr, args->fh);
  1258. if(status)
  1259. goto out;
  1260. status = encode_close(&xdr, args);
  1261. out:
  1262. return status;
  1263. }
  1264. /*
  1265. * Encode an OPEN request
  1266. */
  1267. static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
  1268. {
  1269. struct xdr_stream xdr;
  1270. struct compound_hdr hdr = {
  1271. .nops = 4,
  1272. };
  1273. int status;
  1274. status = nfs_wait_on_sequence(args->seqid, req->rq_task);
  1275. if (status != 0)
  1276. goto out;
  1277. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1278. encode_compound_hdr(&xdr, &hdr);
  1279. status = encode_putfh(&xdr, args->fh);
  1280. if (status)
  1281. goto out;
  1282. status = encode_open(&xdr, args);
  1283. if (status)
  1284. goto out;
  1285. status = encode_getfh(&xdr);
  1286. if (status)
  1287. goto out;
  1288. status = encode_getfattr(&xdr, args->bitmask);
  1289. out:
  1290. return status;
  1291. }
  1292. /*
  1293. * Encode an OPEN_CONFIRM request
  1294. */
  1295. static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
  1296. {
  1297. struct xdr_stream xdr;
  1298. struct compound_hdr hdr = {
  1299. .nops = 2,
  1300. };
  1301. int status;
  1302. status = nfs_wait_on_sequence(args->seqid, req->rq_task);
  1303. if (status != 0)
  1304. goto out;
  1305. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1306. encode_compound_hdr(&xdr, &hdr);
  1307. status = encode_putfh(&xdr, args->fh);
  1308. if(status)
  1309. goto out;
  1310. status = encode_open_confirm(&xdr, args);
  1311. out:
  1312. return status;
  1313. }
  1314. /*
  1315. * Encode an OPEN request with no attributes.
  1316. */
  1317. static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
  1318. {
  1319. struct xdr_stream xdr;
  1320. struct compound_hdr hdr = {
  1321. .nops = 2,
  1322. };
  1323. int status;
  1324. status = nfs_wait_on_sequence(args->seqid, req->rq_task);
  1325. if (status != 0)
  1326. goto out;
  1327. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1328. encode_compound_hdr(&xdr, &hdr);
  1329. status = encode_putfh(&xdr, args->fh);
  1330. if (status)
  1331. goto out;
  1332. status = encode_open(&xdr, args);
  1333. out:
  1334. return status;
  1335. }
  1336. /*
  1337. * Encode an OPEN_DOWNGRADE request
  1338. */
  1339. static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
  1340. {
  1341. struct xdr_stream xdr;
  1342. struct compound_hdr hdr = {
  1343. .nops = 2,
  1344. };
  1345. int status;
  1346. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1347. encode_compound_hdr(&xdr, &hdr);
  1348. status = encode_putfh(&xdr, args->fh);
  1349. if (status)
  1350. goto out;
  1351. status = encode_open_downgrade(&xdr, args);
  1352. out:
  1353. return status;
  1354. }
  1355. /*
  1356. * Encode a LOCK request
  1357. */
  1358. static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
  1359. {
  1360. struct xdr_stream xdr;
  1361. struct compound_hdr hdr = {
  1362. .nops = 2,
  1363. };
  1364. struct nfs_lock_opargs *opargs = args->u.lock;
  1365. int status;
  1366. status = nfs_wait_on_sequence(opargs->lock_seqid, req->rq_task);
  1367. if (status != 0)
  1368. goto out;
  1369. /* Do we need to do an open_to_lock_owner? */
  1370. if (opargs->lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)
  1371. opargs->new_lock_owner = 0;
  1372. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1373. encode_compound_hdr(&xdr, &hdr);
  1374. status = encode_putfh(&xdr, args->fh);
  1375. if(status)
  1376. goto out;
  1377. status = encode_lock(&xdr, args);
  1378. out:
  1379. return status;
  1380. }
  1381. /*
  1382. * Encode a LOCKT request
  1383. */
  1384. static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
  1385. {
  1386. struct xdr_stream xdr;
  1387. struct compound_hdr hdr = {
  1388. .nops = 2,
  1389. };
  1390. int status;
  1391. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1392. encode_compound_hdr(&xdr, &hdr);
  1393. status = encode_putfh(&xdr, args->fh);
  1394. if(status)
  1395. goto out;
  1396. status = encode_lockt(&xdr, args);
  1397. out:
  1398. return status;
  1399. }
  1400. /*
  1401. * Encode a LOCKU request
  1402. */
  1403. static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
  1404. {
  1405. struct xdr_stream xdr;
  1406. struct compound_hdr hdr = {
  1407. .nops = 2,
  1408. };
  1409. int status;
  1410. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1411. encode_compound_hdr(&xdr, &hdr);
  1412. status = encode_putfh(&xdr, args->fh);
  1413. if(status)
  1414. goto out;
  1415. status = encode_locku(&xdr, args);
  1416. out:
  1417. return status;
  1418. }
  1419. /*
  1420. * Encode a READLINK request
  1421. */
  1422. static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
  1423. {
  1424. struct xdr_stream xdr;
  1425. struct compound_hdr hdr = {
  1426. .nops = 2,
  1427. };
  1428. int status;
  1429. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1430. encode_compound_hdr(&xdr, &hdr);
  1431. status = encode_putfh(&xdr, args->fh);
  1432. if(status)
  1433. goto out;
  1434. status = encode_readlink(&xdr, args, req);
  1435. out:
  1436. return status;
  1437. }
  1438. /*
  1439. * Encode a READDIR request
  1440. */
  1441. static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
  1442. {
  1443. struct xdr_stream xdr;
  1444. struct compound_hdr hdr = {
  1445. .nops = 2,
  1446. };
  1447. int status;
  1448. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1449. encode_compound_hdr(&xdr, &hdr);
  1450. status = encode_putfh(&xdr, args->fh);
  1451. if(status)
  1452. goto out;
  1453. status = encode_readdir(&xdr, args, req);
  1454. out:
  1455. return status;
  1456. }
  1457. /*
  1458. * Encode a READ request
  1459. */
  1460. static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
  1461. {
  1462. struct rpc_auth *auth = req->rq_task->tk_auth;
  1463. struct xdr_stream xdr;
  1464. struct compound_hdr hdr = {
  1465. .nops = 2,
  1466. };
  1467. int replen, status;
  1468. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1469. encode_compound_hdr(&xdr, &hdr);
  1470. status = encode_putfh(&xdr, args->fh);
  1471. if (status)
  1472. goto out;
  1473. status = encode_read(&xdr, args);
  1474. if (status)
  1475. goto out;
  1476. /* set up reply kvec
  1477. * toplevel status + taglen=0 + rescount + OP_PUTFH + status
  1478. * + OP_READ + status + eof + datalen = 9
  1479. */
  1480. replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
  1481. xdr_inline_pages(&req->rq_rcv_buf, replen,
  1482. args->pages, args->pgbase, args->count);
  1483. out:
  1484. return status;
  1485. }
  1486. /*
  1487. * Encode an SETATTR request
  1488. */
  1489. static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
  1490. {
  1491. struct xdr_stream xdr;
  1492. struct compound_hdr hdr = {
  1493. .nops = 3,
  1494. };
  1495. int status;
  1496. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1497. encode_compound_hdr(&xdr, &hdr);
  1498. status = encode_putfh(&xdr, args->fh);
  1499. if(status)
  1500. goto out;
  1501. status = encode_setattr(&xdr, args, args->server);
  1502. if(status)
  1503. goto out;
  1504. status = encode_getfattr(&xdr, args->bitmask);
  1505. out:
  1506. return status;
  1507. }
  1508. /*
  1509. * Encode a GETACL request
  1510. */
  1511. static int
  1512. nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p,
  1513. struct nfs_getaclargs *args)
  1514. {
  1515. struct xdr_stream xdr;
  1516. struct rpc_auth *auth = req->rq_task->tk_auth;
  1517. struct compound_hdr hdr = {
  1518. .nops = 2,
  1519. };
  1520. int replen, status;
  1521. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1522. encode_compound_hdr(&xdr, &hdr);
  1523. status = encode_putfh(&xdr, args->fh);
  1524. if (status)
  1525. goto out;
  1526. status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
  1527. /* set up reply buffer: */
  1528. replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
  1529. xdr_inline_pages(&req->rq_rcv_buf, replen,
  1530. args->acl_pages, args->acl_pgbase, args->acl_len);
  1531. out:
  1532. return status;
  1533. }
  1534. /*
  1535. * Encode a WRITE request
  1536. */
  1537. static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
  1538. {
  1539. struct xdr_stream xdr;
  1540. struct compound_hdr hdr = {
  1541. .nops = 2,
  1542. };
  1543. int status;
  1544. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1545. encode_compound_hdr(&xdr, &hdr);
  1546. status = encode_putfh(&xdr, args->fh);
  1547. if (status)
  1548. goto out;
  1549. status = encode_write(&xdr, args);
  1550. out:
  1551. return status;
  1552. }
  1553. /*
  1554. * a COMMIT request
  1555. */
  1556. static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
  1557. {
  1558. struct xdr_stream xdr;
  1559. struct compound_hdr hdr = {
  1560. .nops = 2,
  1561. };
  1562. int status;
  1563. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1564. encode_compound_hdr(&xdr, &hdr);
  1565. status = encode_putfh(&xdr, args->fh);
  1566. if (status)
  1567. goto out;
  1568. status = encode_commit(&xdr, args);
  1569. out:
  1570. return status;
  1571. }
  1572. /*
  1573. * FSINFO request
  1574. */
  1575. static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
  1576. {
  1577. struct xdr_stream xdr;
  1578. struct compound_hdr hdr = {
  1579. .nops = 2,
  1580. };
  1581. int status;
  1582. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1583. encode_compound_hdr(&xdr, &hdr);
  1584. status = encode_putfh(&xdr, args->fh);
  1585. if (!status)
  1586. status = encode_fsinfo(&xdr, args->bitmask);
  1587. return status;
  1588. }
  1589. /*
  1590. * a PATHCONF request
  1591. */
  1592. static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
  1593. {
  1594. struct xdr_stream xdr;
  1595. struct compound_hdr hdr = {
  1596. .nops = 2,
  1597. };
  1598. int status;
  1599. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1600. encode_compound_hdr(&xdr, &hdr);
  1601. status = encode_putfh(&xdr, args->fh);
  1602. if (!status)
  1603. status = encode_getattr_one(&xdr,
  1604. args->bitmask[0] & nfs4_pathconf_bitmap[0]);
  1605. return status;
  1606. }
  1607. /*
  1608. * a STATFS request
  1609. */
  1610. static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
  1611. {
  1612. struct xdr_stream xdr;
  1613. struct compound_hdr hdr = {
  1614. .nops = 2,
  1615. };
  1616. int status;
  1617. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1618. encode_compound_hdr(&xdr, &hdr);
  1619. status = encode_putfh(&xdr, args->fh);
  1620. if (status == 0)
  1621. status = encode_getattr_two(&xdr,
  1622. args->bitmask[0] & nfs4_statfs_bitmap[0],
  1623. args->bitmask[1] & nfs4_statfs_bitmap[1]);
  1624. return status;
  1625. }
  1626. /*
  1627. * GETATTR_BITMAP request
  1628. */
  1629. static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
  1630. {
  1631. struct xdr_stream xdr;
  1632. struct compound_hdr hdr = {
  1633. .nops = 2,
  1634. };
  1635. int status;
  1636. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1637. encode_compound_hdr(&xdr, &hdr);
  1638. status = encode_putfh(&xdr, fhandle);
  1639. if (status == 0)
  1640. status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
  1641. FATTR4_WORD0_LINK_SUPPORT|
  1642. FATTR4_WORD0_SYMLINK_SUPPORT|
  1643. FATTR4_WORD0_ACLSUPPORT);
  1644. return status;
  1645. }
  1646. /*
  1647. * a RENEW request
  1648. */
  1649. static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
  1650. {
  1651. struct xdr_stream xdr;
  1652. struct compound_hdr hdr = {
  1653. .nops = 1,
  1654. };
  1655. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1656. encode_compound_hdr(&xdr, &hdr);
  1657. return encode_renew(&xdr, clp);
  1658. }
  1659. /*
  1660. * a SETCLIENTID request
  1661. */
  1662. static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
  1663. {
  1664. struct xdr_stream xdr;
  1665. struct compound_hdr hdr = {
  1666. .nops = 1,
  1667. };
  1668. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1669. encode_compound_hdr(&xdr, &hdr);
  1670. return encode_setclientid(&xdr, sc);
  1671. }
  1672. /*
  1673. * a SETCLIENTID_CONFIRM request
  1674. */
  1675. static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
  1676. {
  1677. struct xdr_stream xdr;
  1678. struct compound_hdr hdr = {
  1679. .nops = 3,
  1680. };
  1681. const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
  1682. int status;
  1683. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1684. encode_compound_hdr(&xdr, &hdr);
  1685. status = encode_setclientid_confirm(&xdr, clp);
  1686. if (!status)
  1687. status = encode_putrootfh(&xdr);
  1688. if (!status)
  1689. status = encode_fsinfo(&xdr, lease_bitmap);
  1690. return status;
  1691. }
  1692. /*
  1693. * DELEGRETURN request
  1694. */
  1695. static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
  1696. {
  1697. struct xdr_stream xdr;
  1698. struct compound_hdr hdr = {
  1699. .nops = 2,
  1700. };
  1701. int status;
  1702. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1703. encode_compound_hdr(&xdr, &hdr);
  1704. if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
  1705. status = encode_delegreturn(&xdr, args->stateid);
  1706. return status;
  1707. }
  1708. /*
  1709. * START OF "GENERIC" DECODE ROUTINES.
  1710. * These may look a little ugly since they are imported from a "generic"
  1711. * set of XDR encode/decode routines which are intended to be shared by
  1712. * all of our NFSv4 implementations (OpenBSD, MacOS X...).
  1713. *
  1714. * If the pain of reading these is too great, it should be a straightforward
  1715. * task to translate them into Linux-specific versions which are more
  1716. * consistent with the style used in NFSv2/v3...
  1717. */
  1718. #define READ32(x) (x) = ntohl(*p++)
  1719. #define READ64(x) do { \
  1720. (x) = (u64)ntohl(*p++) << 32; \
  1721. (x) |= ntohl(*p++); \
  1722. } while (0)
  1723. #define READTIME(x) do { \
  1724. p++; \
  1725. (x.tv_sec) = ntohl(*p++); \
  1726. (x.tv_nsec) = ntohl(*p++); \
  1727. } while (0)
  1728. #define COPYMEM(x,nbytes) do { \
  1729. memcpy((x), p, nbytes); \
  1730. p += XDR_QUADLEN(nbytes); \
  1731. } while (0)
  1732. #define READ_BUF(nbytes) do { \
  1733. p = xdr_inline_decode(xdr, nbytes); \
  1734. if (!p) { \
  1735. printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
  1736. __FUNCTION__, __LINE__); \
  1737. return -EIO; \
  1738. } \
  1739. } while (0)
  1740. static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
  1741. {
  1742. uint32_t *p;
  1743. READ_BUF(4);
  1744. READ32(*len);
  1745. READ_BUF(*len);
  1746. *string = (char *)p;
  1747. return 0;
  1748. }
  1749. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1750. {
  1751. uint32_t *p;
  1752. READ_BUF(8);
  1753. READ32(hdr->status);
  1754. READ32(hdr->taglen);
  1755. READ_BUF(hdr->taglen + 4);
  1756. hdr->tag = (char *)p;
  1757. p += XDR_QUADLEN(hdr->taglen);
  1758. READ32(hdr->nops);
  1759. return 0;
  1760. }
  1761. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  1762. {
  1763. uint32_t *p;
  1764. uint32_t opnum;
  1765. int32_t nfserr;
  1766. READ_BUF(8);
  1767. READ32(opnum);
  1768. if (opnum != expected) {
  1769. printk(KERN_NOTICE
  1770. "nfs4_decode_op_hdr: Server returned operation"
  1771. " %d but we issued a request for %d\n",
  1772. opnum, expected);
  1773. return -EIO;
  1774. }
  1775. READ32(nfserr);
  1776. if (nfserr != NFS_OK)
  1777. return -nfs_stat_to_errno(nfserr);
  1778. return 0;
  1779. }
  1780. /* Dummy routine */
  1781. static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
  1782. {
  1783. uint32_t *p;
  1784. uint32_t strlen;
  1785. char *str;
  1786. READ_BUF(12);
  1787. return decode_opaque_inline(xdr, &strlen, &str);
  1788. }
  1789. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  1790. {
  1791. uint32_t bmlen, *p;
  1792. READ_BUF(4);
  1793. READ32(bmlen);
  1794. bitmap[0] = bitmap[1] = 0;
  1795. READ_BUF((bmlen << 2));
  1796. if (bmlen > 0) {
  1797. READ32(bitmap[0]);
  1798. if (bmlen > 1)
  1799. READ32(bitmap[1]);
  1800. }
  1801. return 0;
  1802. }
  1803. static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
  1804. {
  1805. uint32_t *p;
  1806. READ_BUF(4);
  1807. READ32(*attrlen);
  1808. *savep = xdr->p;
  1809. return 0;
  1810. }
  1811. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  1812. {
  1813. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  1814. decode_attr_bitmap(xdr, bitmask);
  1815. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  1816. } else
  1817. bitmask[0] = bitmask[1] = 0;
  1818. dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
  1819. return 0;
  1820. }
  1821. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  1822. {
  1823. uint32_t *p;
  1824. *type = 0;
  1825. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  1826. return -EIO;
  1827. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  1828. READ_BUF(4);
  1829. READ32(*type);
  1830. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  1831. dprintk("%s: bad type %d\n", __FUNCTION__, *type);
  1832. return -EIO;
  1833. }
  1834. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  1835. }
  1836. dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
  1837. return 0;
  1838. }
  1839. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  1840. {
  1841. uint32_t *p;
  1842. *change = 0;
  1843. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  1844. return -EIO;
  1845. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  1846. READ_BUF(8);
  1847. READ64(*change);
  1848. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  1849. }
  1850. dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
  1851. (unsigned long long)*change);
  1852. return 0;
  1853. }
  1854. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  1855. {
  1856. uint32_t *p;
  1857. *size = 0;
  1858. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  1859. return -EIO;
  1860. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  1861. READ_BUF(8);
  1862. READ64(*size);
  1863. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  1864. }
  1865. dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
  1866. return 0;
  1867. }
  1868. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  1869. {
  1870. uint32_t *p;
  1871. *res = 0;
  1872. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  1873. return -EIO;
  1874. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  1875. READ_BUF(4);
  1876. READ32(*res);
  1877. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  1878. }
  1879. dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
  1880. return 0;
  1881. }
  1882. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  1883. {
  1884. uint32_t *p;
  1885. *res = 0;
  1886. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  1887. return -EIO;
  1888. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  1889. READ_BUF(4);
  1890. READ32(*res);
  1891. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  1892. }
  1893. dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
  1894. return 0;
  1895. }
  1896. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
  1897. {
  1898. uint32_t *p;
  1899. fsid->major = 0;
  1900. fsid->minor = 0;
  1901. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  1902. return -EIO;
  1903. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  1904. READ_BUF(16);
  1905. READ64(fsid->major);
  1906. READ64(fsid->minor);
  1907. bitmap[0] &= ~FATTR4_WORD0_FSID;
  1908. }
  1909. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
  1910. (unsigned long long)fsid->major,
  1911. (unsigned long long)fsid->minor);
  1912. return 0;
  1913. }
  1914. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  1915. {
  1916. uint32_t *p;
  1917. *res = 60;
  1918. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  1919. return -EIO;
  1920. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  1921. READ_BUF(4);
  1922. READ32(*res);
  1923. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  1924. }
  1925. dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
  1926. return 0;
  1927. }
  1928. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  1929. {
  1930. uint32_t *p;
  1931. *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
  1932. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  1933. return -EIO;
  1934. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  1935. READ_BUF(4);
  1936. READ32(*res);
  1937. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  1938. }
  1939. dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
  1940. return 0;
  1941. }
  1942. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  1943. {
  1944. uint32_t *p;
  1945. *fileid = 0;
  1946. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  1947. return -EIO;
  1948. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  1949. READ_BUF(8);
  1950. READ64(*fileid);
  1951. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  1952. }
  1953. dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
  1954. return 0;
  1955. }
  1956. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  1957. {
  1958. uint32_t *p;
  1959. int status = 0;
  1960. *res = 0;
  1961. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  1962. return -EIO;
  1963. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  1964. READ_BUF(8);
  1965. READ64(*res);
  1966. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  1967. }
  1968. dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  1969. return status;
  1970. }
  1971. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  1972. {
  1973. uint32_t *p;
  1974. int status = 0;
  1975. *res = 0;
  1976. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  1977. return -EIO;
  1978. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  1979. READ_BUF(8);
  1980. READ64(*res);
  1981. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  1982. }
  1983. dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  1984. return status;
  1985. }
  1986. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  1987. {
  1988. uint32_t *p;
  1989. int status = 0;
  1990. *res = 0;
  1991. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  1992. return -EIO;
  1993. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  1994. READ_BUF(8);
  1995. READ64(*res);
  1996. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  1997. }
  1998. dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  1999. return status;
  2000. }
  2001. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2002. {
  2003. uint32_t *p;
  2004. int status = 0;
  2005. *res = 0;
  2006. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  2007. return -EIO;
  2008. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  2009. READ_BUF(8);
  2010. READ64(*res);
  2011. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  2012. }
  2013. dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2014. return status;
  2015. }
  2016. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  2017. {
  2018. uint32_t *p;
  2019. int status = 0;
  2020. *maxlink = 1;
  2021. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  2022. return -EIO;
  2023. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  2024. READ_BUF(4);
  2025. READ32(*maxlink);
  2026. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  2027. }
  2028. dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
  2029. return status;
  2030. }
  2031. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  2032. {
  2033. uint32_t *p;
  2034. int status = 0;
  2035. *maxname = 1024;
  2036. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  2037. return -EIO;
  2038. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  2039. READ_BUF(4);
  2040. READ32(*maxname);
  2041. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  2042. }
  2043. dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
  2044. return status;
  2045. }
  2046. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2047. {
  2048. uint32_t *p;
  2049. int status = 0;
  2050. *res = 1024;
  2051. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  2052. return -EIO;
  2053. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  2054. uint64_t maxread;
  2055. READ_BUF(8);
  2056. READ64(maxread);
  2057. if (maxread > 0x7FFFFFFF)
  2058. maxread = 0x7FFFFFFF;
  2059. *res = (uint32_t)maxread;
  2060. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  2061. }
  2062. dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
  2063. return status;
  2064. }
  2065. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2066. {
  2067. uint32_t *p;
  2068. int status = 0;
  2069. *res = 1024;
  2070. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  2071. return -EIO;
  2072. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  2073. uint64_t maxwrite;
  2074. READ_BUF(8);
  2075. READ64(maxwrite);
  2076. if (maxwrite > 0x7FFFFFFF)
  2077. maxwrite = 0x7FFFFFFF;
  2078. *res = (uint32_t)maxwrite;
  2079. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  2080. }
  2081. dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
  2082. return status;
  2083. }
  2084. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
  2085. {
  2086. uint32_t *p;
  2087. *mode = 0;
  2088. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  2089. return -EIO;
  2090. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  2091. READ_BUF(4);
  2092. READ32(*mode);
  2093. *mode &= ~S_IFMT;
  2094. bitmap[1] &= ~FATTR4_WORD1_MODE;
  2095. }
  2096. dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
  2097. return 0;
  2098. }
  2099. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  2100. {
  2101. uint32_t *p;
  2102. *nlink = 1;
  2103. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  2104. return -EIO;
  2105. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  2106. READ_BUF(4);
  2107. READ32(*nlink);
  2108. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  2109. }
  2110. dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
  2111. return 0;
  2112. }
  2113. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
  2114. {
  2115. uint32_t len, *p;
  2116. *uid = -2;
  2117. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  2118. return -EIO;
  2119. if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
  2120. READ_BUF(4);
  2121. READ32(len);
  2122. READ_BUF(len);
  2123. if (len < XDR_MAX_NETOBJ) {
  2124. if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
  2125. dprintk("%s: nfs_map_name_to_uid failed!\n",
  2126. __FUNCTION__);
  2127. } else
  2128. printk(KERN_WARNING "%s: name too long (%u)!\n",
  2129. __FUNCTION__, len);
  2130. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  2131. }
  2132. dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
  2133. return 0;
  2134. }
  2135. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
  2136. {
  2137. uint32_t len, *p;
  2138. *gid = -2;
  2139. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  2140. return -EIO;
  2141. if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
  2142. READ_BUF(4);
  2143. READ32(len);
  2144. READ_BUF(len);
  2145. if (len < XDR_MAX_NETOBJ) {
  2146. if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
  2147. dprintk("%s: nfs_map_group_to_gid failed!\n",
  2148. __FUNCTION__);
  2149. } else
  2150. printk(KERN_WARNING "%s: name too long (%u)!\n",
  2151. __FUNCTION__, len);
  2152. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  2153. }
  2154. dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
  2155. return 0;
  2156. }
  2157. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  2158. {
  2159. uint32_t major = 0, minor = 0, *p;
  2160. *rdev = MKDEV(0,0);
  2161. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  2162. return -EIO;
  2163. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  2164. dev_t tmp;
  2165. READ_BUF(8);
  2166. READ32(major);
  2167. READ32(minor);
  2168. tmp = MKDEV(major, minor);
  2169. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  2170. *rdev = tmp;
  2171. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  2172. }
  2173. dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
  2174. return 0;
  2175. }
  2176. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2177. {
  2178. uint32_t *p;
  2179. int status = 0;
  2180. *res = 0;
  2181. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  2182. return -EIO;
  2183. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  2184. READ_BUF(8);
  2185. READ64(*res);
  2186. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  2187. }
  2188. dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2189. return status;
  2190. }
  2191. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2192. {
  2193. uint32_t *p;
  2194. int status = 0;
  2195. *res = 0;
  2196. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  2197. return -EIO;
  2198. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  2199. READ_BUF(8);
  2200. READ64(*res);
  2201. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  2202. }
  2203. dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2204. return status;
  2205. }
  2206. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2207. {
  2208. uint32_t *p;
  2209. int status = 0;
  2210. *res = 0;
  2211. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  2212. return -EIO;
  2213. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  2214. READ_BUF(8);
  2215. READ64(*res);
  2216. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  2217. }
  2218. dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2219. return status;
  2220. }
  2221. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  2222. {
  2223. uint32_t *p;
  2224. *used = 0;
  2225. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  2226. return -EIO;
  2227. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  2228. READ_BUF(8);
  2229. READ64(*used);
  2230. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  2231. }
  2232. dprintk("%s: space used=%Lu\n", __FUNCTION__,
  2233. (unsigned long long)*used);
  2234. return 0;
  2235. }
  2236. static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
  2237. {
  2238. uint32_t *p;
  2239. uint64_t sec;
  2240. uint32_t nsec;
  2241. READ_BUF(12);
  2242. READ64(sec);
  2243. READ32(nsec);
  2244. time->tv_sec = (time_t)sec;
  2245. time->tv_nsec = (long)nsec;
  2246. return 0;
  2247. }
  2248. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2249. {
  2250. int status = 0;
  2251. time->tv_sec = 0;
  2252. time->tv_nsec = 0;
  2253. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  2254. return -EIO;
  2255. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  2256. status = decode_attr_time(xdr, time);
  2257. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  2258. }
  2259. dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
  2260. return status;
  2261. }
  2262. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2263. {
  2264. int status = 0;
  2265. time->tv_sec = 0;
  2266. time->tv_nsec = 0;
  2267. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  2268. return -EIO;
  2269. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  2270. status = decode_attr_time(xdr, time);
  2271. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  2272. }
  2273. dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
  2274. return status;
  2275. }
  2276. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2277. {
  2278. int status = 0;
  2279. time->tv_sec = 0;
  2280. time->tv_nsec = 0;
  2281. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  2282. return -EIO;
  2283. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  2284. status = decode_attr_time(xdr, time);
  2285. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  2286. }
  2287. dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
  2288. return status;
  2289. }
  2290. static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
  2291. {
  2292. unsigned int attrwords = XDR_QUADLEN(attrlen);
  2293. unsigned int nwords = xdr->p - savep;
  2294. if (unlikely(attrwords != nwords)) {
  2295. printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
  2296. __FUNCTION__,
  2297. attrwords << 2,
  2298. (attrwords < nwords) ? '<' : '>',
  2299. nwords << 2);
  2300. return -EIO;
  2301. }
  2302. return 0;
  2303. }
  2304. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2305. {
  2306. uint32_t *p;
  2307. READ_BUF(20);
  2308. READ32(cinfo->atomic);
  2309. READ64(cinfo->before);
  2310. READ64(cinfo->after);
  2311. return 0;
  2312. }
  2313. static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
  2314. {
  2315. uint32_t *p;
  2316. uint32_t supp, acc;
  2317. int status;
  2318. status = decode_op_hdr(xdr, OP_ACCESS);
  2319. if (status)
  2320. return status;
  2321. READ_BUF(8);
  2322. READ32(supp);
  2323. READ32(acc);
  2324. access->supported = supp;
  2325. access->access = acc;
  2326. return 0;
  2327. }
  2328. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  2329. {
  2330. uint32_t *p;
  2331. int status;
  2332. status = decode_op_hdr(xdr, OP_CLOSE);
  2333. if (status)
  2334. return status;
  2335. READ_BUF(sizeof(res->stateid.data));
  2336. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2337. return 0;
  2338. }
  2339. static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
  2340. {
  2341. uint32_t *p;
  2342. int status;
  2343. status = decode_op_hdr(xdr, OP_COMMIT);
  2344. if (status)
  2345. return status;
  2346. READ_BUF(8);
  2347. COPYMEM(res->verf->verifier, 8);
  2348. return 0;
  2349. }
  2350. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2351. {
  2352. uint32_t *p;
  2353. uint32_t bmlen;
  2354. int status;
  2355. status = decode_op_hdr(xdr, OP_CREATE);
  2356. if (status)
  2357. return status;
  2358. if ((status = decode_change_info(xdr, cinfo)))
  2359. return status;
  2360. READ_BUF(4);
  2361. READ32(bmlen);
  2362. READ_BUF(bmlen << 2);
  2363. return 0;
  2364. }
  2365. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  2366. {
  2367. uint32_t *savep;
  2368. uint32_t attrlen,
  2369. bitmap[2] = {0};
  2370. int status;
  2371. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2372. goto xdr_error;
  2373. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2374. goto xdr_error;
  2375. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2376. goto xdr_error;
  2377. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  2378. goto xdr_error;
  2379. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  2380. goto xdr_error;
  2381. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  2382. goto xdr_error;
  2383. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  2384. goto xdr_error;
  2385. status = verify_attr_len(xdr, savep, attrlen);
  2386. xdr_error:
  2387. if (status != 0)
  2388. printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
  2389. return status;
  2390. }
  2391. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  2392. {
  2393. uint32_t *savep;
  2394. uint32_t attrlen,
  2395. bitmap[2] = {0};
  2396. int status;
  2397. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2398. goto xdr_error;
  2399. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2400. goto xdr_error;
  2401. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2402. goto xdr_error;
  2403. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  2404. goto xdr_error;
  2405. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  2406. goto xdr_error;
  2407. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  2408. goto xdr_error;
  2409. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  2410. goto xdr_error;
  2411. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  2412. goto xdr_error;
  2413. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  2414. goto xdr_error;
  2415. status = verify_attr_len(xdr, savep, attrlen);
  2416. xdr_error:
  2417. if (status != 0)
  2418. printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
  2419. return status;
  2420. }
  2421. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  2422. {
  2423. uint32_t *savep;
  2424. uint32_t attrlen,
  2425. bitmap[2] = {0};
  2426. int status;
  2427. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2428. goto xdr_error;
  2429. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2430. goto xdr_error;
  2431. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2432. goto xdr_error;
  2433. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  2434. goto xdr_error;
  2435. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
  2436. goto xdr_error;
  2437. status = verify_attr_len(xdr, savep, attrlen);
  2438. xdr_error:
  2439. if (status != 0)
  2440. printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
  2441. return status;
  2442. }
  2443. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
  2444. {
  2445. uint32_t *savep;
  2446. uint32_t attrlen,
  2447. bitmap[2] = {0},
  2448. type;
  2449. int status, fmode = 0;
  2450. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2451. goto xdr_error;
  2452. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2453. goto xdr_error;
  2454. fattr->bitmap[0] = bitmap[0];
  2455. fattr->bitmap[1] = bitmap[1];
  2456. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2457. goto xdr_error;
  2458. if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
  2459. goto xdr_error;
  2460. fattr->type = nfs_type2fmt[type].nfs2type;
  2461. fmode = nfs_type2fmt[type].mode;
  2462. if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
  2463. goto xdr_error;
  2464. if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
  2465. goto xdr_error;
  2466. if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
  2467. goto xdr_error;
  2468. if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
  2469. goto xdr_error;
  2470. if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
  2471. goto xdr_error;
  2472. fattr->mode |= fmode;
  2473. if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
  2474. goto xdr_error;
  2475. if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
  2476. goto xdr_error;
  2477. if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
  2478. goto xdr_error;
  2479. if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
  2480. goto xdr_error;
  2481. if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
  2482. goto xdr_error;
  2483. if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
  2484. goto xdr_error;
  2485. if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
  2486. goto xdr_error;
  2487. if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
  2488. goto xdr_error;
  2489. if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
  2490. fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
  2491. fattr->timestamp = jiffies;
  2492. }
  2493. xdr_error:
  2494. if (status != 0)
  2495. printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
  2496. return status;
  2497. }
  2498. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  2499. {
  2500. uint32_t *savep;
  2501. uint32_t attrlen, bitmap[2];
  2502. int status;
  2503. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2504. goto xdr_error;
  2505. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2506. goto xdr_error;
  2507. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2508. goto xdr_error;
  2509. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  2510. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  2511. goto xdr_error;
  2512. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  2513. goto xdr_error;
  2514. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  2515. goto xdr_error;
  2516. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  2517. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  2518. goto xdr_error;
  2519. fsinfo->wtpref = fsinfo->wtmax;
  2520. status = verify_attr_len(xdr, savep, attrlen);
  2521. xdr_error:
  2522. if (status != 0)
  2523. printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
  2524. return status;
  2525. }
  2526. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  2527. {
  2528. uint32_t *p;
  2529. uint32_t len;
  2530. int status;
  2531. status = decode_op_hdr(xdr, OP_GETFH);
  2532. if (status)
  2533. return status;
  2534. /* Zero handle first to allow comparisons */
  2535. memset(fh, 0, sizeof(*fh));
  2536. READ_BUF(4);
  2537. READ32(len);
  2538. if (len > NFS4_FHSIZE)
  2539. return -EIO;
  2540. fh->size = len;
  2541. READ_BUF(len);
  2542. COPYMEM(fh->data, len);
  2543. return 0;
  2544. }
  2545. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2546. {
  2547. int status;
  2548. status = decode_op_hdr(xdr, OP_LINK);
  2549. if (status)
  2550. return status;
  2551. return decode_change_info(xdr, cinfo);
  2552. }
  2553. /*
  2554. * We create the owner, so we know a proper owner.id length is 4.
  2555. */
  2556. static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
  2557. {
  2558. uint32_t *p;
  2559. uint32_t namelen;
  2560. READ_BUF(32);
  2561. READ64(denied->offset);
  2562. READ64(denied->length);
  2563. READ32(denied->type);
  2564. READ64(denied->owner.clientid);
  2565. READ32(namelen);
  2566. READ_BUF(namelen);
  2567. if (namelen == 4)
  2568. READ32(denied->owner.id);
  2569. return -NFS4ERR_DENIED;
  2570. }
  2571. static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
  2572. {
  2573. uint32_t *p;
  2574. int status;
  2575. status = decode_op_hdr(xdr, OP_LOCK);
  2576. if (status == 0) {
  2577. READ_BUF(sizeof(res->u.stateid.data));
  2578. COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
  2579. } else if (status == -NFS4ERR_DENIED)
  2580. return decode_lock_denied(xdr, &res->u.denied);
  2581. return status;
  2582. }
  2583. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
  2584. {
  2585. int status;
  2586. status = decode_op_hdr(xdr, OP_LOCKT);
  2587. if (status == -NFS4ERR_DENIED)
  2588. return decode_lock_denied(xdr, &res->u.denied);
  2589. return status;
  2590. }
  2591. static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
  2592. {
  2593. uint32_t *p;
  2594. int status;
  2595. status = decode_op_hdr(xdr, OP_LOCKU);
  2596. if (status == 0) {
  2597. READ_BUF(sizeof(res->u.stateid.data));
  2598. COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
  2599. }
  2600. return status;
  2601. }
  2602. static int decode_lookup(struct xdr_stream *xdr)
  2603. {
  2604. return decode_op_hdr(xdr, OP_LOOKUP);
  2605. }
  2606. /* This is too sick! */
  2607. static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
  2608. {
  2609. uint32_t *p;
  2610. uint32_t limit_type, nblocks, blocksize;
  2611. READ_BUF(12);
  2612. READ32(limit_type);
  2613. switch (limit_type) {
  2614. case 1:
  2615. READ64(*maxsize);
  2616. break;
  2617. case 2:
  2618. READ32(nblocks);
  2619. READ32(blocksize);
  2620. *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  2621. }
  2622. return 0;
  2623. }
  2624. static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  2625. {
  2626. uint32_t *p;
  2627. uint32_t delegation_type;
  2628. READ_BUF(4);
  2629. READ32(delegation_type);
  2630. if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
  2631. res->delegation_type = 0;
  2632. return 0;
  2633. }
  2634. READ_BUF(20);
  2635. COPYMEM(res->delegation.data, sizeof(res->delegation.data));
  2636. READ32(res->do_recall);
  2637. switch (delegation_type) {
  2638. case NFS4_OPEN_DELEGATE_READ:
  2639. res->delegation_type = FMODE_READ;
  2640. break;
  2641. case NFS4_OPEN_DELEGATE_WRITE:
  2642. res->delegation_type = FMODE_WRITE|FMODE_READ;
  2643. if (decode_space_limit(xdr, &res->maxsize) < 0)
  2644. return -EIO;
  2645. }
  2646. return decode_ace(xdr, NULL, res->server->nfs4_state);
  2647. }
  2648. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  2649. {
  2650. uint32_t *p;
  2651. uint32_t bmlen;
  2652. int status;
  2653. status = decode_op_hdr(xdr, OP_OPEN);
  2654. if (status)
  2655. return status;
  2656. READ_BUF(sizeof(res->stateid.data));
  2657. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2658. decode_change_info(xdr, &res->cinfo);
  2659. READ_BUF(8);
  2660. READ32(res->rflags);
  2661. READ32(bmlen);
  2662. if (bmlen > 10)
  2663. goto xdr_error;
  2664. READ_BUF(bmlen << 2);
  2665. p += bmlen;
  2666. return decode_delegation(xdr, res);
  2667. xdr_error:
  2668. printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
  2669. return -EIO;
  2670. }
  2671. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  2672. {
  2673. uint32_t *p;
  2674. int status;
  2675. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  2676. if (status)
  2677. return status;
  2678. READ_BUF(sizeof(res->stateid.data));
  2679. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2680. return 0;
  2681. }
  2682. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  2683. {
  2684. uint32_t *p;
  2685. int status;
  2686. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  2687. if (status)
  2688. return status;
  2689. READ_BUF(sizeof(res->stateid.data));
  2690. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2691. return 0;
  2692. }
  2693. static int decode_putfh(struct xdr_stream *xdr)
  2694. {
  2695. return decode_op_hdr(xdr, OP_PUTFH);
  2696. }
  2697. static int decode_putrootfh(struct xdr_stream *xdr)
  2698. {
  2699. return decode_op_hdr(xdr, OP_PUTROOTFH);
  2700. }
  2701. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
  2702. {
  2703. struct kvec *iov = req->rq_rcv_buf.head;
  2704. uint32_t *p;
  2705. uint32_t count, eof, recvd, hdrlen;
  2706. int status;
  2707. status = decode_op_hdr(xdr, OP_READ);
  2708. if (status)
  2709. return status;
  2710. READ_BUF(8);
  2711. READ32(eof);
  2712. READ32(count);
  2713. hdrlen = (u8 *) p - (u8 *) iov->iov_base;
  2714. recvd = req->rq_rcv_buf.len - hdrlen;
  2715. if (count > recvd) {
  2716. printk(KERN_WARNING "NFS: server cheating in read reply: "
  2717. "count %u > recvd %u\n", count, recvd);
  2718. count = recvd;
  2719. eof = 0;
  2720. }
  2721. xdr_read_pages(xdr, count);
  2722. res->eof = eof;
  2723. res->count = count;
  2724. return 0;
  2725. }
  2726. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  2727. {
  2728. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  2729. struct page *page = *rcvbuf->pages;
  2730. struct kvec *iov = rcvbuf->head;
  2731. unsigned int nr, pglen = rcvbuf->page_len;
  2732. uint32_t *end, *entry, *p, *kaddr;
  2733. uint32_t len, attrlen;
  2734. int hdrlen, recvd, status;
  2735. status = decode_op_hdr(xdr, OP_READDIR);
  2736. if (status)
  2737. return status;
  2738. READ_BUF(8);
  2739. COPYMEM(readdir->verifier.data, 8);
  2740. dprintk("%s: verifier = 0x%x%x\n",
  2741. __FUNCTION__,
  2742. ((u32 *)readdir->verifier.data)[0],
  2743. ((u32 *)readdir->verifier.data)[1]);
  2744. hdrlen = (char *) p - (char *) iov->iov_base;
  2745. recvd = rcvbuf->len - hdrlen;
  2746. if (pglen > recvd)
  2747. pglen = recvd;
  2748. xdr_read_pages(xdr, pglen);
  2749. BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
  2750. kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
  2751. end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
  2752. entry = p;
  2753. for (nr = 0; *p++; nr++) {
  2754. if (p + 3 > end)
  2755. goto short_pkt;
  2756. dprintk("cookie = %Lu, ", *((unsigned long long *)p));
  2757. p += 2; /* cookie */
  2758. len = ntohl(*p++); /* filename length */
  2759. if (len > NFS4_MAXNAMLEN) {
  2760. printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
  2761. goto err_unmap;
  2762. }
  2763. dprintk("filename = %*s\n", len, (char *)p);
  2764. p += XDR_QUADLEN(len);
  2765. if (p + 1 > end)
  2766. goto short_pkt;
  2767. len = ntohl(*p++); /* bitmap length */
  2768. p += len;
  2769. if (p + 1 > end)
  2770. goto short_pkt;
  2771. attrlen = XDR_QUADLEN(ntohl(*p++));
  2772. p += attrlen; /* attributes */
  2773. if (p + 2 > end)
  2774. goto short_pkt;
  2775. entry = p;
  2776. }
  2777. if (!nr && (entry[0] != 0 || entry[1] == 0))
  2778. goto short_pkt;
  2779. out:
  2780. kunmap_atomic(kaddr, KM_USER0);
  2781. return 0;
  2782. short_pkt:
  2783. dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
  2784. entry[0] = entry[1] = 0;
  2785. /* truncate listing ? */
  2786. if (!nr) {
  2787. printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
  2788. entry[1] = 1;
  2789. }
  2790. goto out;
  2791. err_unmap:
  2792. kunmap_atomic(kaddr, KM_USER0);
  2793. return -errno_NFSERR_IO;
  2794. }
  2795. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  2796. {
  2797. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  2798. struct kvec *iov = rcvbuf->head;
  2799. int hdrlen, len, recvd;
  2800. uint32_t *p;
  2801. char *kaddr;
  2802. int status;
  2803. status = decode_op_hdr(xdr, OP_READLINK);
  2804. if (status)
  2805. return status;
  2806. /* Convert length of symlink */
  2807. READ_BUF(4);
  2808. READ32(len);
  2809. if (len >= rcvbuf->page_len || len <= 0) {
  2810. dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
  2811. return -ENAMETOOLONG;
  2812. }
  2813. hdrlen = (char *) xdr->p - (char *) iov->iov_base;
  2814. recvd = req->rq_rcv_buf.len - hdrlen;
  2815. if (recvd < len) {
  2816. printk(KERN_WARNING "NFS: server cheating in readlink reply: "
  2817. "count %u > recvd %u\n", len, recvd);
  2818. return -EIO;
  2819. }
  2820. xdr_read_pages(xdr, len);
  2821. /*
  2822. * The XDR encode routine has set things up so that
  2823. * the link text will be copied directly into the
  2824. * buffer. We just have to do overflow-checking,
  2825. * and and null-terminate the text (the VFS expects
  2826. * null-termination).
  2827. */
  2828. kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
  2829. kaddr[len+rcvbuf->page_base] = '\0';
  2830. kunmap_atomic(kaddr, KM_USER0);
  2831. return 0;
  2832. }
  2833. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2834. {
  2835. int status;
  2836. status = decode_op_hdr(xdr, OP_REMOVE);
  2837. if (status)
  2838. goto out;
  2839. status = decode_change_info(xdr, cinfo);
  2840. out:
  2841. return status;
  2842. }
  2843. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  2844. struct nfs4_change_info *new_cinfo)
  2845. {
  2846. int status;
  2847. status = decode_op_hdr(xdr, OP_RENAME);
  2848. if (status)
  2849. goto out;
  2850. if ((status = decode_change_info(xdr, old_cinfo)))
  2851. goto out;
  2852. status = decode_change_info(xdr, new_cinfo);
  2853. out:
  2854. return status;
  2855. }
  2856. static int decode_renew(struct xdr_stream *xdr)
  2857. {
  2858. return decode_op_hdr(xdr, OP_RENEW);
  2859. }
  2860. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  2861. size_t *acl_len)
  2862. {
  2863. uint32_t *savep;
  2864. uint32_t attrlen,
  2865. bitmap[2] = {0};
  2866. struct kvec *iov = req->rq_rcv_buf.head;
  2867. int status;
  2868. *acl_len = 0;
  2869. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2870. goto out;
  2871. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2872. goto out;
  2873. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2874. goto out;
  2875. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  2876. return -EIO;
  2877. if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
  2878. int hdrlen, recvd;
  2879. /* We ignore &savep and don't do consistency checks on
  2880. * the attr length. Let userspace figure it out.... */
  2881. hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
  2882. recvd = req->rq_rcv_buf.len - hdrlen;
  2883. if (attrlen > recvd) {
  2884. printk(KERN_WARNING "NFS: server cheating in getattr"
  2885. " acl reply: attrlen %u > recvd %u\n",
  2886. attrlen, recvd);
  2887. return -EINVAL;
  2888. }
  2889. if (attrlen <= *acl_len)
  2890. xdr_read_pages(xdr, attrlen);
  2891. *acl_len = attrlen;
  2892. } else
  2893. status = -EOPNOTSUPP;
  2894. out:
  2895. return status;
  2896. }
  2897. static int
  2898. decode_savefh(struct xdr_stream *xdr)
  2899. {
  2900. return decode_op_hdr(xdr, OP_SAVEFH);
  2901. }
  2902. static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
  2903. {
  2904. uint32_t *p;
  2905. uint32_t bmlen;
  2906. int status;
  2907. status = decode_op_hdr(xdr, OP_SETATTR);
  2908. if (status)
  2909. return status;
  2910. READ_BUF(4);
  2911. READ32(bmlen);
  2912. READ_BUF(bmlen << 2);
  2913. return 0;
  2914. }
  2915. static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
  2916. {
  2917. uint32_t *p;
  2918. uint32_t opnum;
  2919. int32_t nfserr;
  2920. READ_BUF(8);
  2921. READ32(opnum);
  2922. if (opnum != OP_SETCLIENTID) {
  2923. printk(KERN_NOTICE
  2924. "nfs4_decode_setclientid: Server returned operation"
  2925. " %d\n", opnum);
  2926. return -EIO;
  2927. }
  2928. READ32(nfserr);
  2929. if (nfserr == NFS_OK) {
  2930. READ_BUF(8 + sizeof(clp->cl_confirm.data));
  2931. READ64(clp->cl_clientid);
  2932. COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
  2933. } else if (nfserr == NFSERR_CLID_INUSE) {
  2934. uint32_t len;
  2935. /* skip netid string */
  2936. READ_BUF(4);
  2937. READ32(len);
  2938. READ_BUF(len);
  2939. /* skip uaddr string */
  2940. READ_BUF(4);
  2941. READ32(len);
  2942. READ_BUF(len);
  2943. return -NFSERR_CLID_INUSE;
  2944. } else
  2945. return -nfs_stat_to_errno(nfserr);
  2946. return 0;
  2947. }
  2948. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  2949. {
  2950. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  2951. }
  2952. static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
  2953. {
  2954. uint32_t *p;
  2955. int status;
  2956. status = decode_op_hdr(xdr, OP_WRITE);
  2957. if (status)
  2958. return status;
  2959. READ_BUF(16);
  2960. READ32(res->count);
  2961. READ32(res->verf->committed);
  2962. COPYMEM(res->verf->verifier, 8);
  2963. return 0;
  2964. }
  2965. static int decode_delegreturn(struct xdr_stream *xdr)
  2966. {
  2967. return decode_op_hdr(xdr, OP_DELEGRETURN);
  2968. }
  2969. /*
  2970. * Decode OPEN_DOWNGRADE response
  2971. */
  2972. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
  2973. {
  2974. struct xdr_stream xdr;
  2975. struct compound_hdr hdr;
  2976. int status;
  2977. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  2978. status = decode_compound_hdr(&xdr, &hdr);
  2979. if (status)
  2980. goto out;
  2981. status = decode_putfh(&xdr);
  2982. if (status)
  2983. goto out;
  2984. status = decode_open_downgrade(&xdr, res);
  2985. out:
  2986. return status;
  2987. }
  2988. /*
  2989. * END OF "GENERIC" DECODE ROUTINES.
  2990. */
  2991. /*
  2992. * Decode ACCESS response
  2993. */
  2994. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
  2995. {
  2996. struct xdr_stream xdr;
  2997. struct compound_hdr hdr;
  2998. int status;
  2999. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3000. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3001. goto out;
  3002. if ((status = decode_putfh(&xdr)) == 0)
  3003. status = decode_access(&xdr, res);
  3004. out:
  3005. return status;
  3006. }
  3007. /*
  3008. * Decode LOOKUP response
  3009. */
  3010. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
  3011. {
  3012. struct xdr_stream xdr;
  3013. struct compound_hdr hdr;
  3014. int status;
  3015. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3016. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3017. goto out;
  3018. if ((status = decode_putfh(&xdr)) != 0)
  3019. goto out;
  3020. if ((status = decode_lookup(&xdr)) != 0)
  3021. goto out;
  3022. if ((status = decode_getfh(&xdr, res->fh)) != 0)
  3023. goto out;
  3024. status = decode_getfattr(&xdr, res->fattr, res->server);
  3025. out:
  3026. return status;
  3027. }
  3028. /*
  3029. * Decode LOOKUP_ROOT response
  3030. */
  3031. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
  3032. {
  3033. struct xdr_stream xdr;
  3034. struct compound_hdr hdr;
  3035. int status;
  3036. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3037. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3038. goto out;
  3039. if ((status = decode_putrootfh(&xdr)) != 0)
  3040. goto out;
  3041. if ((status = decode_getfh(&xdr, res->fh)) == 0)
  3042. status = decode_getfattr(&xdr, res->fattr, res->server);
  3043. out:
  3044. return status;
  3045. }
  3046. /*
  3047. * Decode REMOVE response
  3048. */
  3049. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
  3050. {
  3051. struct xdr_stream xdr;
  3052. struct compound_hdr hdr;
  3053. int status;
  3054. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3055. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3056. goto out;
  3057. if ((status = decode_putfh(&xdr)) == 0)
  3058. status = decode_remove(&xdr, cinfo);
  3059. out:
  3060. return status;
  3061. }
  3062. /*
  3063. * Decode RENAME response
  3064. */
  3065. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
  3066. {
  3067. struct xdr_stream xdr;
  3068. struct compound_hdr hdr;
  3069. int status;
  3070. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3071. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3072. goto out;
  3073. if ((status = decode_putfh(&xdr)) != 0)
  3074. goto out;
  3075. if ((status = decode_savefh(&xdr)) != 0)
  3076. goto out;
  3077. if ((status = decode_putfh(&xdr)) != 0)
  3078. goto out;
  3079. status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
  3080. out:
  3081. return status;
  3082. }
  3083. /*
  3084. * Decode LINK response
  3085. */
  3086. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
  3087. {
  3088. struct xdr_stream xdr;
  3089. struct compound_hdr hdr;
  3090. int status;
  3091. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3092. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3093. goto out;
  3094. if ((status = decode_putfh(&xdr)) != 0)
  3095. goto out;
  3096. if ((status = decode_savefh(&xdr)) != 0)
  3097. goto out;
  3098. if ((status = decode_putfh(&xdr)) != 0)
  3099. goto out;
  3100. status = decode_link(&xdr, cinfo);
  3101. out:
  3102. return status;
  3103. }
  3104. /*
  3105. * Decode CREATE response
  3106. */
  3107. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
  3108. {
  3109. struct xdr_stream xdr;
  3110. struct compound_hdr hdr;
  3111. int status;
  3112. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3113. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3114. goto out;
  3115. if ((status = decode_putfh(&xdr)) != 0)
  3116. goto out;
  3117. if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
  3118. goto out;
  3119. if ((status = decode_getfh(&xdr, res->fh)) != 0)
  3120. goto out;
  3121. status = decode_getfattr(&xdr, res->fattr, res->server);
  3122. if (status == NFS4ERR_DELAY)
  3123. status = 0;
  3124. out:
  3125. return status;
  3126. }
  3127. /*
  3128. * Decode SYMLINK response
  3129. */
  3130. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
  3131. {
  3132. return nfs4_xdr_dec_create(rqstp, p, res);
  3133. }
  3134. /*
  3135. * Decode GETATTR response
  3136. */
  3137. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
  3138. {
  3139. struct xdr_stream xdr;
  3140. struct compound_hdr hdr;
  3141. int status;
  3142. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3143. status = decode_compound_hdr(&xdr, &hdr);
  3144. if (status)
  3145. goto out;
  3146. status = decode_putfh(&xdr);
  3147. if (status)
  3148. goto out;
  3149. status = decode_getfattr(&xdr, res->fattr, res->server);
  3150. out:
  3151. return status;
  3152. }
  3153. /*
  3154. * Encode an SETACL request
  3155. */
  3156. static int
  3157. nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args)
  3158. {
  3159. struct xdr_stream xdr;
  3160. struct compound_hdr hdr = {
  3161. .nops = 2,
  3162. };
  3163. int status;
  3164. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  3165. encode_compound_hdr(&xdr, &hdr);
  3166. status = encode_putfh(&xdr, args->fh);
  3167. if (status)
  3168. goto out;
  3169. status = encode_setacl(&xdr, args);
  3170. out:
  3171. return status;
  3172. }
  3173. /*
  3174. * Decode SETACL response
  3175. */
  3176. static int
  3177. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res)
  3178. {
  3179. struct xdr_stream xdr;
  3180. struct compound_hdr hdr;
  3181. int status;
  3182. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3183. status = decode_compound_hdr(&xdr, &hdr);
  3184. if (status)
  3185. goto out;
  3186. status = decode_putfh(&xdr);
  3187. if (status)
  3188. goto out;
  3189. status = decode_setattr(&xdr, res);
  3190. out:
  3191. return status;
  3192. }
  3193. /*
  3194. * Decode GETACL response
  3195. */
  3196. static int
  3197. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len)
  3198. {
  3199. struct xdr_stream xdr;
  3200. struct compound_hdr hdr;
  3201. int status;
  3202. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3203. status = decode_compound_hdr(&xdr, &hdr);
  3204. if (status)
  3205. goto out;
  3206. status = decode_putfh(&xdr);
  3207. if (status)
  3208. goto out;
  3209. status = decode_getacl(&xdr, rqstp, acl_len);
  3210. out:
  3211. return status;
  3212. }
  3213. /*
  3214. * Decode CLOSE response
  3215. */
  3216. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
  3217. {
  3218. struct xdr_stream xdr;
  3219. struct compound_hdr hdr;
  3220. int status;
  3221. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3222. status = decode_compound_hdr(&xdr, &hdr);
  3223. if (status)
  3224. goto out;
  3225. status = decode_putfh(&xdr);
  3226. if (status)
  3227. goto out;
  3228. status = decode_close(&xdr, res);
  3229. out:
  3230. return status;
  3231. }
  3232. /*
  3233. * Decode OPEN response
  3234. */
  3235. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
  3236. {
  3237. struct xdr_stream xdr;
  3238. struct compound_hdr hdr;
  3239. int status;
  3240. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3241. status = decode_compound_hdr(&xdr, &hdr);
  3242. if (status)
  3243. goto out;
  3244. status = decode_putfh(&xdr);
  3245. if (status)
  3246. goto out;
  3247. status = decode_open(&xdr, res);
  3248. if (status)
  3249. goto out;
  3250. status = decode_getfh(&xdr, &res->fh);
  3251. if (status)
  3252. goto out;
  3253. status = decode_getfattr(&xdr, res->f_attr, res->server);
  3254. if (status == NFS4ERR_DELAY)
  3255. status = 0;
  3256. out:
  3257. return status;
  3258. }
  3259. /*
  3260. * Decode OPEN_CONFIRM response
  3261. */
  3262. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
  3263. {
  3264. struct xdr_stream xdr;
  3265. struct compound_hdr hdr;
  3266. int status;
  3267. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3268. status = decode_compound_hdr(&xdr, &hdr);
  3269. if (status)
  3270. goto out;
  3271. status = decode_putfh(&xdr);
  3272. if (status)
  3273. goto out;
  3274. status = decode_open_confirm(&xdr, res);
  3275. out:
  3276. return status;
  3277. }
  3278. /*
  3279. * Decode OPEN response
  3280. */
  3281. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
  3282. {
  3283. struct xdr_stream xdr;
  3284. struct compound_hdr hdr;
  3285. int status;
  3286. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3287. status = decode_compound_hdr(&xdr, &hdr);
  3288. if (status)
  3289. goto out;
  3290. status = decode_putfh(&xdr);
  3291. if (status)
  3292. goto out;
  3293. status = decode_open(&xdr, res);
  3294. out:
  3295. return status;
  3296. }
  3297. /*
  3298. * Decode SETATTR response
  3299. */
  3300. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
  3301. {
  3302. struct xdr_stream xdr;
  3303. struct compound_hdr hdr;
  3304. int status;
  3305. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3306. status = decode_compound_hdr(&xdr, &hdr);
  3307. if (status)
  3308. goto out;
  3309. status = decode_putfh(&xdr);
  3310. if (status)
  3311. goto out;
  3312. status = decode_setattr(&xdr, res);
  3313. if (status)
  3314. goto out;
  3315. status = decode_getfattr(&xdr, res->fattr, res->server);
  3316. if (status == NFS4ERR_DELAY)
  3317. status = 0;
  3318. out:
  3319. return status;
  3320. }
  3321. /*
  3322. * Decode LOCK response
  3323. */
  3324. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
  3325. {
  3326. struct xdr_stream xdr;
  3327. struct compound_hdr hdr;
  3328. int status;
  3329. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3330. status = decode_compound_hdr(&xdr, &hdr);
  3331. if (status)
  3332. goto out;
  3333. status = decode_putfh(&xdr);
  3334. if (status)
  3335. goto out;
  3336. status = decode_lock(&xdr, res);
  3337. out:
  3338. return status;
  3339. }
  3340. /*
  3341. * Decode LOCKT response
  3342. */
  3343. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
  3344. {
  3345. struct xdr_stream xdr;
  3346. struct compound_hdr hdr;
  3347. int status;
  3348. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3349. status = decode_compound_hdr(&xdr, &hdr);
  3350. if (status)
  3351. goto out;
  3352. status = decode_putfh(&xdr);
  3353. if (status)
  3354. goto out;
  3355. status = decode_lockt(&xdr, res);
  3356. out:
  3357. return status;
  3358. }
  3359. /*
  3360. * Decode LOCKU response
  3361. */
  3362. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
  3363. {
  3364. struct xdr_stream xdr;
  3365. struct compound_hdr hdr;
  3366. int status;
  3367. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3368. status = decode_compound_hdr(&xdr, &hdr);
  3369. if (status)
  3370. goto out;
  3371. status = decode_putfh(&xdr);
  3372. if (status)
  3373. goto out;
  3374. status = decode_locku(&xdr, res);
  3375. out:
  3376. return status;
  3377. }
  3378. /*
  3379. * Decode READLINK response
  3380. */
  3381. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
  3382. {
  3383. struct xdr_stream xdr;
  3384. struct compound_hdr hdr;
  3385. int status;
  3386. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3387. status = decode_compound_hdr(&xdr, &hdr);
  3388. if (status)
  3389. goto out;
  3390. status = decode_putfh(&xdr);
  3391. if (status)
  3392. goto out;
  3393. status = decode_readlink(&xdr, rqstp);
  3394. out:
  3395. return status;
  3396. }
  3397. /*
  3398. * Decode READDIR response
  3399. */
  3400. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
  3401. {
  3402. struct xdr_stream xdr;
  3403. struct compound_hdr hdr;
  3404. int status;
  3405. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3406. status = decode_compound_hdr(&xdr, &hdr);
  3407. if (status)
  3408. goto out;
  3409. status = decode_putfh(&xdr);
  3410. if (status)
  3411. goto out;
  3412. status = decode_readdir(&xdr, rqstp, res);
  3413. out:
  3414. return status;
  3415. }
  3416. /*
  3417. * Decode Read response
  3418. */
  3419. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
  3420. {
  3421. struct xdr_stream xdr;
  3422. struct compound_hdr hdr;
  3423. int status;
  3424. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3425. status = decode_compound_hdr(&xdr, &hdr);
  3426. if (status)
  3427. goto out;
  3428. status = decode_putfh(&xdr);
  3429. if (status)
  3430. goto out;
  3431. status = decode_read(&xdr, rqstp, res);
  3432. if (!status)
  3433. status = res->count;
  3434. out:
  3435. return status;
  3436. }
  3437. /*
  3438. * Decode WRITE response
  3439. */
  3440. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
  3441. {
  3442. struct xdr_stream xdr;
  3443. struct compound_hdr hdr;
  3444. int status;
  3445. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3446. status = decode_compound_hdr(&xdr, &hdr);
  3447. if (status)
  3448. goto out;
  3449. status = decode_putfh(&xdr);
  3450. if (status)
  3451. goto out;
  3452. status = decode_write(&xdr, res);
  3453. if (!status)
  3454. status = res->count;
  3455. out:
  3456. return status;
  3457. }
  3458. /*
  3459. * Decode COMMIT response
  3460. */
  3461. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
  3462. {
  3463. struct xdr_stream xdr;
  3464. struct compound_hdr hdr;
  3465. int status;
  3466. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3467. status = decode_compound_hdr(&xdr, &hdr);
  3468. if (status)
  3469. goto out;
  3470. status = decode_putfh(&xdr);
  3471. if (status)
  3472. goto out;
  3473. status = decode_commit(&xdr, res);
  3474. out:
  3475. return status;
  3476. }
  3477. /*
  3478. * FSINFO request
  3479. */
  3480. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
  3481. {
  3482. struct xdr_stream xdr;
  3483. struct compound_hdr hdr;
  3484. int status;
  3485. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3486. status = decode_compound_hdr(&xdr, &hdr);
  3487. if (!status)
  3488. status = decode_putfh(&xdr);
  3489. if (!status)
  3490. status = decode_fsinfo(&xdr, fsinfo);
  3491. if (!status)
  3492. status = -nfs_stat_to_errno(hdr.status);
  3493. return status;
  3494. }
  3495. /*
  3496. * PATHCONF request
  3497. */
  3498. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
  3499. {
  3500. struct xdr_stream xdr;
  3501. struct compound_hdr hdr;
  3502. int status;
  3503. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3504. status = decode_compound_hdr(&xdr, &hdr);
  3505. if (!status)
  3506. status = decode_putfh(&xdr);
  3507. if (!status)
  3508. status = decode_pathconf(&xdr, pathconf);
  3509. return status;
  3510. }
  3511. /*
  3512. * STATFS request
  3513. */
  3514. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
  3515. {
  3516. struct xdr_stream xdr;
  3517. struct compound_hdr hdr;
  3518. int status;
  3519. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3520. status = decode_compound_hdr(&xdr, &hdr);
  3521. if (!status)
  3522. status = decode_putfh(&xdr);
  3523. if (!status)
  3524. status = decode_statfs(&xdr, fsstat);
  3525. return status;
  3526. }
  3527. /*
  3528. * GETATTR_BITMAP request
  3529. */
  3530. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
  3531. {
  3532. struct xdr_stream xdr;
  3533. struct compound_hdr hdr;
  3534. int status;
  3535. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3536. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3537. goto out;
  3538. if ((status = decode_putfh(&xdr)) != 0)
  3539. goto out;
  3540. status = decode_server_caps(&xdr, res);
  3541. out:
  3542. return status;
  3543. }
  3544. /*
  3545. * Decode RENEW response
  3546. */
  3547. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
  3548. {
  3549. struct xdr_stream xdr;
  3550. struct compound_hdr hdr;
  3551. int status;
  3552. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3553. status = decode_compound_hdr(&xdr, &hdr);
  3554. if (!status)
  3555. status = decode_renew(&xdr);
  3556. return status;
  3557. }
  3558. /*
  3559. * a SETCLIENTID request
  3560. */
  3561. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
  3562. struct nfs4_client *clp)
  3563. {
  3564. struct xdr_stream xdr;
  3565. struct compound_hdr hdr;
  3566. int status;
  3567. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3568. status = decode_compound_hdr(&xdr, &hdr);
  3569. if (!status)
  3570. status = decode_setclientid(&xdr, clp);
  3571. if (!status)
  3572. status = -nfs_stat_to_errno(hdr.status);
  3573. return status;
  3574. }
  3575. /*
  3576. * a SETCLIENTID_CONFIRM request
  3577. */
  3578. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
  3579. {
  3580. struct xdr_stream xdr;
  3581. struct compound_hdr hdr;
  3582. int status;
  3583. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3584. status = decode_compound_hdr(&xdr, &hdr);
  3585. if (!status)
  3586. status = decode_setclientid_confirm(&xdr);
  3587. if (!status)
  3588. status = decode_putrootfh(&xdr);
  3589. if (!status)
  3590. status = decode_fsinfo(&xdr, fsinfo);
  3591. if (!status)
  3592. status = -nfs_stat_to_errno(hdr.status);
  3593. return status;
  3594. }
  3595. /*
  3596. * DELEGRETURN request
  3597. */
  3598. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
  3599. {
  3600. struct xdr_stream xdr;
  3601. struct compound_hdr hdr;
  3602. int status;
  3603. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3604. status = decode_compound_hdr(&xdr, &hdr);
  3605. if (status == 0) {
  3606. status = decode_putfh(&xdr);
  3607. if (status == 0)
  3608. status = decode_delegreturn(&xdr);
  3609. }
  3610. return status;
  3611. }
  3612. uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
  3613. {
  3614. uint32_t bitmap[2] = {0};
  3615. uint32_t len;
  3616. if (!*p++) {
  3617. if (!*p)
  3618. return ERR_PTR(-EAGAIN);
  3619. entry->eof = 1;
  3620. return ERR_PTR(-EBADCOOKIE);
  3621. }
  3622. entry->prev_cookie = entry->cookie;
  3623. p = xdr_decode_hyper(p, &entry->cookie);
  3624. entry->len = ntohl(*p++);
  3625. entry->name = (const char *) p;
  3626. p += XDR_QUADLEN(entry->len);
  3627. /*
  3628. * In case the server doesn't return an inode number,
  3629. * we fake one here. (We don't use inode number 0,
  3630. * since glibc seems to choke on it...)
  3631. */
  3632. entry->ino = 1;
  3633. len = ntohl(*p++); /* bitmap length */
  3634. if (len-- > 0) {
  3635. bitmap[0] = ntohl(*p++);
  3636. if (len-- > 0) {
  3637. bitmap[1] = ntohl(*p++);
  3638. p += len;
  3639. }
  3640. }
  3641. len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
  3642. if (len > 0) {
  3643. if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
  3644. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  3645. /* Ignore the return value of rdattr_error for now */
  3646. p++;
  3647. len--;
  3648. }
  3649. if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
  3650. xdr_decode_hyper(p, &entry->ino);
  3651. else if (bitmap[0] == FATTR4_WORD0_FILEID)
  3652. xdr_decode_hyper(p, &entry->ino);
  3653. p += len;
  3654. }
  3655. entry->eof = !p[0] && p[1];
  3656. return p;
  3657. }
  3658. /*
  3659. * We need to translate between nfs status return values and
  3660. * the local errno values which may not be the same.
  3661. */
  3662. static struct {
  3663. int stat;
  3664. int errno;
  3665. } nfs_errtbl[] = {
  3666. { NFS4_OK, 0 },
  3667. { NFS4ERR_PERM, EPERM },
  3668. { NFS4ERR_NOENT, ENOENT },
  3669. { NFS4ERR_IO, errno_NFSERR_IO },
  3670. { NFS4ERR_NXIO, ENXIO },
  3671. { NFS4ERR_ACCESS, EACCES },
  3672. { NFS4ERR_EXIST, EEXIST },
  3673. { NFS4ERR_XDEV, EXDEV },
  3674. { NFS4ERR_NOTDIR, ENOTDIR },
  3675. { NFS4ERR_ISDIR, EISDIR },
  3676. { NFS4ERR_INVAL, EINVAL },
  3677. { NFS4ERR_FBIG, EFBIG },
  3678. { NFS4ERR_NOSPC, ENOSPC },
  3679. { NFS4ERR_ROFS, EROFS },
  3680. { NFS4ERR_MLINK, EMLINK },
  3681. { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
  3682. { NFS4ERR_NOTEMPTY, ENOTEMPTY },
  3683. { NFS4ERR_DQUOT, EDQUOT },
  3684. { NFS4ERR_STALE, ESTALE },
  3685. { NFS4ERR_BADHANDLE, EBADHANDLE },
  3686. { NFS4ERR_BADOWNER, EINVAL },
  3687. { NFS4ERR_BADNAME, EINVAL },
  3688. { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
  3689. { NFS4ERR_NOTSUPP, ENOTSUPP },
  3690. { NFS4ERR_TOOSMALL, ETOOSMALL },
  3691. { NFS4ERR_SERVERFAULT, ESERVERFAULT },
  3692. { NFS4ERR_BADTYPE, EBADTYPE },
  3693. { NFS4ERR_LOCKED, EAGAIN },
  3694. { NFS4ERR_RESOURCE, EREMOTEIO },
  3695. { NFS4ERR_SYMLINK, ELOOP },
  3696. { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
  3697. { NFS4ERR_DEADLOCK, EDEADLK },
  3698. { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
  3699. * to be handled by a
  3700. * middle-layer.
  3701. */
  3702. { -1, EIO }
  3703. };
  3704. /*
  3705. * Convert an NFS error code to a local one.
  3706. * This one is used jointly by NFSv2 and NFSv3.
  3707. */
  3708. static int
  3709. nfs_stat_to_errno(int stat)
  3710. {
  3711. int i;
  3712. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  3713. if (nfs_errtbl[i].stat == stat)
  3714. return nfs_errtbl[i].errno;
  3715. }
  3716. if (stat <= 10000 || stat > 10100) {
  3717. /* The server is looney tunes. */
  3718. return ESERVERFAULT;
  3719. }
  3720. /* If we cannot translate the error, the recovery routines should
  3721. * handle it.
  3722. * Note: remaining NFSv4 error codes have values > 10000, so should
  3723. * not conflict with native Linux error codes.
  3724. */
  3725. return stat;
  3726. }
  3727. #ifndef MAX
  3728. # define MAX(a, b) (((a) > (b))? (a) : (b))
  3729. #endif
  3730. #define PROC(proc, argtype, restype) \
  3731. [NFSPROC4_CLNT_##proc] = { \
  3732. .p_proc = NFSPROC4_COMPOUND, \
  3733. .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
  3734. .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
  3735. .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
  3736. }
  3737. struct rpc_procinfo nfs4_procedures[] = {
  3738. PROC(READ, enc_read, dec_read),
  3739. PROC(WRITE, enc_write, dec_write),
  3740. PROC(COMMIT, enc_commit, dec_commit),
  3741. PROC(OPEN, enc_open, dec_open),
  3742. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  3743. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  3744. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  3745. PROC(CLOSE, enc_close, dec_close),
  3746. PROC(SETATTR, enc_setattr, dec_setattr),
  3747. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  3748. PROC(RENEW, enc_renew, dec_renew),
  3749. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  3750. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  3751. PROC(LOCK, enc_lock, dec_lock),
  3752. PROC(LOCKT, enc_lockt, dec_lockt),
  3753. PROC(LOCKU, enc_locku, dec_locku),
  3754. PROC(ACCESS, enc_access, dec_access),
  3755. PROC(GETATTR, enc_getattr, dec_getattr),
  3756. PROC(LOOKUP, enc_lookup, dec_lookup),
  3757. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  3758. PROC(REMOVE, enc_remove, dec_remove),
  3759. PROC(RENAME, enc_rename, dec_rename),
  3760. PROC(LINK, enc_link, dec_link),
  3761. PROC(SYMLINK, enc_symlink, dec_symlink),
  3762. PROC(CREATE, enc_create, dec_create),
  3763. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  3764. PROC(STATFS, enc_statfs, dec_statfs),
  3765. PROC(READLINK, enc_readlink, dec_readlink),
  3766. PROC(READDIR, enc_readdir, dec_readdir),
  3767. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  3768. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  3769. PROC(GETACL, enc_getacl, dec_getacl),
  3770. PROC(SETACL, enc_setacl, dec_setacl),
  3771. };
  3772. struct rpc_version nfs_version4 = {
  3773. .number = 4,
  3774. .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
  3775. .procs = nfs4_procedures
  3776. };
  3777. /*
  3778. * Local variables:
  3779. * c-basic-offset: 8
  3780. * End:
  3781. */