nfs4xdr.c 106 KB

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