nfs4xdr.c 106 KB

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