nfs4xdr.c 100 KB

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