nfs4xdr.c 109 KB

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