nfs4xdr.c 107 KB

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