nfs4xdr.c 114 KB

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