nfs4xdr.c 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231
  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);
  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);
  682. WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid));
  683. WRITE32(ol->lock_seqid);
  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);
  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);
  718. WRITEMEM(&opargs->stateid, sizeof(opargs->stateid));
  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);
  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);
  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);
  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. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1277. encode_compound_hdr(&xdr, &hdr);
  1278. status = encode_putfh(&xdr, args->fh);
  1279. if (status)
  1280. goto out;
  1281. status = encode_open(&xdr, args);
  1282. if (status)
  1283. goto out;
  1284. status = encode_getfh(&xdr);
  1285. if (status)
  1286. goto out;
  1287. status = encode_getfattr(&xdr, args->bitmask);
  1288. out:
  1289. return status;
  1290. }
  1291. /*
  1292. * Encode an OPEN_CONFIRM request
  1293. */
  1294. static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
  1295. {
  1296. struct xdr_stream xdr;
  1297. struct compound_hdr hdr = {
  1298. .nops = 2,
  1299. };
  1300. int status;
  1301. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1302. encode_compound_hdr(&xdr, &hdr);
  1303. status = encode_putfh(&xdr, args->fh);
  1304. if(status)
  1305. goto out;
  1306. status = encode_open_confirm(&xdr, args);
  1307. out:
  1308. return status;
  1309. }
  1310. /*
  1311. * Encode an OPEN request with no attributes.
  1312. */
  1313. static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
  1314. {
  1315. struct xdr_stream xdr;
  1316. struct compound_hdr hdr = {
  1317. .nops = 2,
  1318. };
  1319. int status;
  1320. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1321. encode_compound_hdr(&xdr, &hdr);
  1322. status = encode_putfh(&xdr, args->fh);
  1323. if (status)
  1324. goto out;
  1325. status = encode_open(&xdr, args);
  1326. out:
  1327. return status;
  1328. }
  1329. /*
  1330. * Encode an OPEN_DOWNGRADE request
  1331. */
  1332. static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
  1333. {
  1334. struct xdr_stream xdr;
  1335. struct compound_hdr hdr = {
  1336. .nops = 2,
  1337. };
  1338. int status;
  1339. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1340. encode_compound_hdr(&xdr, &hdr);
  1341. status = encode_putfh(&xdr, args->fh);
  1342. if (status)
  1343. goto out;
  1344. status = encode_open_downgrade(&xdr, args);
  1345. out:
  1346. return status;
  1347. }
  1348. /*
  1349. * Encode a LOCK request
  1350. */
  1351. static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
  1352. {
  1353. struct xdr_stream xdr;
  1354. struct compound_hdr hdr = {
  1355. .nops = 2,
  1356. };
  1357. int status;
  1358. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1359. encode_compound_hdr(&xdr, &hdr);
  1360. status = encode_putfh(&xdr, args->fh);
  1361. if(status)
  1362. goto out;
  1363. status = encode_lock(&xdr, args);
  1364. out:
  1365. return status;
  1366. }
  1367. /*
  1368. * Encode a LOCKT request
  1369. */
  1370. static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
  1371. {
  1372. struct xdr_stream xdr;
  1373. struct compound_hdr hdr = {
  1374. .nops = 2,
  1375. };
  1376. int status;
  1377. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1378. encode_compound_hdr(&xdr, &hdr);
  1379. status = encode_putfh(&xdr, args->fh);
  1380. if(status)
  1381. goto out;
  1382. status = encode_lockt(&xdr, args);
  1383. out:
  1384. return status;
  1385. }
  1386. /*
  1387. * Encode a LOCKU request
  1388. */
  1389. static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
  1390. {
  1391. struct xdr_stream xdr;
  1392. struct compound_hdr hdr = {
  1393. .nops = 2,
  1394. };
  1395. int status;
  1396. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1397. encode_compound_hdr(&xdr, &hdr);
  1398. status = encode_putfh(&xdr, args->fh);
  1399. if(status)
  1400. goto out;
  1401. status = encode_locku(&xdr, args);
  1402. out:
  1403. return status;
  1404. }
  1405. /*
  1406. * Encode a READLINK request
  1407. */
  1408. static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
  1409. {
  1410. struct xdr_stream xdr;
  1411. struct compound_hdr hdr = {
  1412. .nops = 2,
  1413. };
  1414. int status;
  1415. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1416. encode_compound_hdr(&xdr, &hdr);
  1417. status = encode_putfh(&xdr, args->fh);
  1418. if(status)
  1419. goto out;
  1420. status = encode_readlink(&xdr, args, req);
  1421. out:
  1422. return status;
  1423. }
  1424. /*
  1425. * Encode a READDIR request
  1426. */
  1427. static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
  1428. {
  1429. struct xdr_stream xdr;
  1430. struct compound_hdr hdr = {
  1431. .nops = 2,
  1432. };
  1433. int status;
  1434. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1435. encode_compound_hdr(&xdr, &hdr);
  1436. status = encode_putfh(&xdr, args->fh);
  1437. if(status)
  1438. goto out;
  1439. status = encode_readdir(&xdr, args, req);
  1440. out:
  1441. return status;
  1442. }
  1443. /*
  1444. * Encode a READ request
  1445. */
  1446. static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
  1447. {
  1448. struct rpc_auth *auth = req->rq_task->tk_auth;
  1449. struct xdr_stream xdr;
  1450. struct compound_hdr hdr = {
  1451. .nops = 2,
  1452. };
  1453. int replen, status;
  1454. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1455. encode_compound_hdr(&xdr, &hdr);
  1456. status = encode_putfh(&xdr, args->fh);
  1457. if (status)
  1458. goto out;
  1459. status = encode_read(&xdr, args);
  1460. if (status)
  1461. goto out;
  1462. /* set up reply kvec
  1463. * toplevel status + taglen=0 + rescount + OP_PUTFH + status
  1464. * + OP_READ + status + eof + datalen = 9
  1465. */
  1466. replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
  1467. xdr_inline_pages(&req->rq_rcv_buf, replen,
  1468. args->pages, args->pgbase, args->count);
  1469. out:
  1470. return status;
  1471. }
  1472. /*
  1473. * Encode an SETATTR request
  1474. */
  1475. static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
  1476. {
  1477. struct xdr_stream xdr;
  1478. struct compound_hdr hdr = {
  1479. .nops = 3,
  1480. };
  1481. int status;
  1482. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1483. encode_compound_hdr(&xdr, &hdr);
  1484. status = encode_putfh(&xdr, args->fh);
  1485. if(status)
  1486. goto out;
  1487. status = encode_setattr(&xdr, args, args->server);
  1488. if(status)
  1489. goto out;
  1490. status = encode_getfattr(&xdr, args->bitmask);
  1491. out:
  1492. return status;
  1493. }
  1494. /*
  1495. * Encode a GETACL request
  1496. */
  1497. static int
  1498. nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p,
  1499. struct nfs_getaclargs *args)
  1500. {
  1501. struct xdr_stream xdr;
  1502. struct rpc_auth *auth = req->rq_task->tk_auth;
  1503. struct compound_hdr hdr = {
  1504. .nops = 2,
  1505. };
  1506. int replen, status;
  1507. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1508. encode_compound_hdr(&xdr, &hdr);
  1509. status = encode_putfh(&xdr, args->fh);
  1510. if (status)
  1511. goto out;
  1512. status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
  1513. /* set up reply buffer: */
  1514. replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
  1515. xdr_inline_pages(&req->rq_rcv_buf, replen,
  1516. args->acl_pages, args->acl_pgbase, args->acl_len);
  1517. out:
  1518. return status;
  1519. }
  1520. /*
  1521. * Encode a WRITE request
  1522. */
  1523. static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
  1524. {
  1525. struct xdr_stream xdr;
  1526. struct compound_hdr hdr = {
  1527. .nops = 2,
  1528. };
  1529. int status;
  1530. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1531. encode_compound_hdr(&xdr, &hdr);
  1532. status = encode_putfh(&xdr, args->fh);
  1533. if (status)
  1534. goto out;
  1535. status = encode_write(&xdr, args);
  1536. out:
  1537. return status;
  1538. }
  1539. /*
  1540. * a COMMIT request
  1541. */
  1542. static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
  1543. {
  1544. struct xdr_stream xdr;
  1545. struct compound_hdr hdr = {
  1546. .nops = 2,
  1547. };
  1548. int status;
  1549. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1550. encode_compound_hdr(&xdr, &hdr);
  1551. status = encode_putfh(&xdr, args->fh);
  1552. if (status)
  1553. goto out;
  1554. status = encode_commit(&xdr, args);
  1555. out:
  1556. return status;
  1557. }
  1558. /*
  1559. * FSINFO request
  1560. */
  1561. static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
  1562. {
  1563. struct xdr_stream xdr;
  1564. struct compound_hdr hdr = {
  1565. .nops = 2,
  1566. };
  1567. int status;
  1568. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1569. encode_compound_hdr(&xdr, &hdr);
  1570. status = encode_putfh(&xdr, args->fh);
  1571. if (!status)
  1572. status = encode_fsinfo(&xdr, args->bitmask);
  1573. return status;
  1574. }
  1575. /*
  1576. * a PATHCONF request
  1577. */
  1578. static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
  1579. {
  1580. struct xdr_stream xdr;
  1581. struct compound_hdr hdr = {
  1582. .nops = 2,
  1583. };
  1584. int status;
  1585. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1586. encode_compound_hdr(&xdr, &hdr);
  1587. status = encode_putfh(&xdr, args->fh);
  1588. if (!status)
  1589. status = encode_getattr_one(&xdr,
  1590. args->bitmask[0] & nfs4_pathconf_bitmap[0]);
  1591. return status;
  1592. }
  1593. /*
  1594. * a STATFS request
  1595. */
  1596. static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_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 == 0)
  1607. status = encode_getattr_two(&xdr,
  1608. args->bitmask[0] & nfs4_statfs_bitmap[0],
  1609. args->bitmask[1] & nfs4_statfs_bitmap[1]);
  1610. return status;
  1611. }
  1612. /*
  1613. * GETATTR_BITMAP request
  1614. */
  1615. static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
  1616. {
  1617. struct xdr_stream xdr;
  1618. struct compound_hdr hdr = {
  1619. .nops = 2,
  1620. };
  1621. int status;
  1622. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1623. encode_compound_hdr(&xdr, &hdr);
  1624. status = encode_putfh(&xdr, fhandle);
  1625. if (status == 0)
  1626. status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
  1627. FATTR4_WORD0_LINK_SUPPORT|
  1628. FATTR4_WORD0_SYMLINK_SUPPORT|
  1629. FATTR4_WORD0_ACLSUPPORT);
  1630. return status;
  1631. }
  1632. /*
  1633. * a RENEW request
  1634. */
  1635. static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
  1636. {
  1637. struct xdr_stream xdr;
  1638. struct compound_hdr hdr = {
  1639. .nops = 1,
  1640. };
  1641. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1642. encode_compound_hdr(&xdr, &hdr);
  1643. return encode_renew(&xdr, clp);
  1644. }
  1645. /*
  1646. * a SETCLIENTID request
  1647. */
  1648. static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
  1649. {
  1650. struct xdr_stream xdr;
  1651. struct compound_hdr hdr = {
  1652. .nops = 1,
  1653. };
  1654. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1655. encode_compound_hdr(&xdr, &hdr);
  1656. return encode_setclientid(&xdr, sc);
  1657. }
  1658. /*
  1659. * a SETCLIENTID_CONFIRM request
  1660. */
  1661. static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
  1662. {
  1663. struct xdr_stream xdr;
  1664. struct compound_hdr hdr = {
  1665. .nops = 3,
  1666. };
  1667. const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
  1668. int status;
  1669. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1670. encode_compound_hdr(&xdr, &hdr);
  1671. status = encode_setclientid_confirm(&xdr, clp);
  1672. if (!status)
  1673. status = encode_putrootfh(&xdr);
  1674. if (!status)
  1675. status = encode_fsinfo(&xdr, lease_bitmap);
  1676. return status;
  1677. }
  1678. /*
  1679. * DELEGRETURN request
  1680. */
  1681. static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
  1682. {
  1683. struct xdr_stream xdr;
  1684. struct compound_hdr hdr = {
  1685. .nops = 2,
  1686. };
  1687. int status;
  1688. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1689. encode_compound_hdr(&xdr, &hdr);
  1690. if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
  1691. status = encode_delegreturn(&xdr, args->stateid);
  1692. return status;
  1693. }
  1694. /*
  1695. * START OF "GENERIC" DECODE ROUTINES.
  1696. * These may look a little ugly since they are imported from a "generic"
  1697. * set of XDR encode/decode routines which are intended to be shared by
  1698. * all of our NFSv4 implementations (OpenBSD, MacOS X...).
  1699. *
  1700. * If the pain of reading these is too great, it should be a straightforward
  1701. * task to translate them into Linux-specific versions which are more
  1702. * consistent with the style used in NFSv2/v3...
  1703. */
  1704. #define READ32(x) (x) = ntohl(*p++)
  1705. #define READ64(x) do { \
  1706. (x) = (u64)ntohl(*p++) << 32; \
  1707. (x) |= ntohl(*p++); \
  1708. } while (0)
  1709. #define READTIME(x) do { \
  1710. p++; \
  1711. (x.tv_sec) = ntohl(*p++); \
  1712. (x.tv_nsec) = ntohl(*p++); \
  1713. } while (0)
  1714. #define COPYMEM(x,nbytes) do { \
  1715. memcpy((x), p, nbytes); \
  1716. p += XDR_QUADLEN(nbytes); \
  1717. } while (0)
  1718. #define READ_BUF(nbytes) do { \
  1719. p = xdr_inline_decode(xdr, nbytes); \
  1720. if (!p) { \
  1721. printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
  1722. __FUNCTION__, __LINE__); \
  1723. return -EIO; \
  1724. } \
  1725. } while (0)
  1726. static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
  1727. {
  1728. uint32_t *p;
  1729. READ_BUF(4);
  1730. READ32(*len);
  1731. READ_BUF(*len);
  1732. *string = (char *)p;
  1733. return 0;
  1734. }
  1735. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1736. {
  1737. uint32_t *p;
  1738. READ_BUF(8);
  1739. READ32(hdr->status);
  1740. READ32(hdr->taglen);
  1741. READ_BUF(hdr->taglen + 4);
  1742. hdr->tag = (char *)p;
  1743. p += XDR_QUADLEN(hdr->taglen);
  1744. READ32(hdr->nops);
  1745. return 0;
  1746. }
  1747. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  1748. {
  1749. uint32_t *p;
  1750. uint32_t opnum;
  1751. int32_t nfserr;
  1752. READ_BUF(8);
  1753. READ32(opnum);
  1754. if (opnum != expected) {
  1755. printk(KERN_NOTICE
  1756. "nfs4_decode_op_hdr: Server returned operation"
  1757. " %d but we issued a request for %d\n",
  1758. opnum, expected);
  1759. return -EIO;
  1760. }
  1761. READ32(nfserr);
  1762. if (nfserr != NFS_OK)
  1763. return -nfs_stat_to_errno(nfserr);
  1764. return 0;
  1765. }
  1766. /* Dummy routine */
  1767. static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
  1768. {
  1769. uint32_t *p;
  1770. uint32_t strlen;
  1771. char *str;
  1772. READ_BUF(12);
  1773. return decode_opaque_inline(xdr, &strlen, &str);
  1774. }
  1775. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  1776. {
  1777. uint32_t bmlen, *p;
  1778. READ_BUF(4);
  1779. READ32(bmlen);
  1780. bitmap[0] = bitmap[1] = 0;
  1781. READ_BUF((bmlen << 2));
  1782. if (bmlen > 0) {
  1783. READ32(bitmap[0]);
  1784. if (bmlen > 1)
  1785. READ32(bitmap[1]);
  1786. }
  1787. return 0;
  1788. }
  1789. static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
  1790. {
  1791. uint32_t *p;
  1792. READ_BUF(4);
  1793. READ32(*attrlen);
  1794. *savep = xdr->p;
  1795. return 0;
  1796. }
  1797. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  1798. {
  1799. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  1800. decode_attr_bitmap(xdr, bitmask);
  1801. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  1802. } else
  1803. bitmask[0] = bitmask[1] = 0;
  1804. dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
  1805. return 0;
  1806. }
  1807. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  1808. {
  1809. uint32_t *p;
  1810. *type = 0;
  1811. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  1812. return -EIO;
  1813. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  1814. READ_BUF(4);
  1815. READ32(*type);
  1816. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  1817. dprintk("%s: bad type %d\n", __FUNCTION__, *type);
  1818. return -EIO;
  1819. }
  1820. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  1821. }
  1822. dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
  1823. return 0;
  1824. }
  1825. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  1826. {
  1827. uint32_t *p;
  1828. *change = 0;
  1829. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  1830. return -EIO;
  1831. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  1832. READ_BUF(8);
  1833. READ64(*change);
  1834. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  1835. }
  1836. dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
  1837. (unsigned long long)*change);
  1838. return 0;
  1839. }
  1840. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  1841. {
  1842. uint32_t *p;
  1843. *size = 0;
  1844. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  1845. return -EIO;
  1846. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  1847. READ_BUF(8);
  1848. READ64(*size);
  1849. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  1850. }
  1851. dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
  1852. return 0;
  1853. }
  1854. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  1855. {
  1856. uint32_t *p;
  1857. *res = 0;
  1858. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  1859. return -EIO;
  1860. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  1861. READ_BUF(4);
  1862. READ32(*res);
  1863. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  1864. }
  1865. dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
  1866. return 0;
  1867. }
  1868. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  1869. {
  1870. uint32_t *p;
  1871. *res = 0;
  1872. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  1873. return -EIO;
  1874. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  1875. READ_BUF(4);
  1876. READ32(*res);
  1877. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  1878. }
  1879. dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
  1880. return 0;
  1881. }
  1882. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
  1883. {
  1884. uint32_t *p;
  1885. fsid->major = 0;
  1886. fsid->minor = 0;
  1887. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  1888. return -EIO;
  1889. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  1890. READ_BUF(16);
  1891. READ64(fsid->major);
  1892. READ64(fsid->minor);
  1893. bitmap[0] &= ~FATTR4_WORD0_FSID;
  1894. }
  1895. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
  1896. (unsigned long long)fsid->major,
  1897. (unsigned long long)fsid->minor);
  1898. return 0;
  1899. }
  1900. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  1901. {
  1902. uint32_t *p;
  1903. *res = 60;
  1904. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  1905. return -EIO;
  1906. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  1907. READ_BUF(4);
  1908. READ32(*res);
  1909. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  1910. }
  1911. dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
  1912. return 0;
  1913. }
  1914. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  1915. {
  1916. uint32_t *p;
  1917. *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
  1918. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  1919. return -EIO;
  1920. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  1921. READ_BUF(4);
  1922. READ32(*res);
  1923. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  1924. }
  1925. dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
  1926. return 0;
  1927. }
  1928. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  1929. {
  1930. uint32_t *p;
  1931. *fileid = 0;
  1932. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  1933. return -EIO;
  1934. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  1935. READ_BUF(8);
  1936. READ64(*fileid);
  1937. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  1938. }
  1939. dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
  1940. return 0;
  1941. }
  1942. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  1943. {
  1944. uint32_t *p;
  1945. int status = 0;
  1946. *res = 0;
  1947. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  1948. return -EIO;
  1949. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  1950. READ_BUF(8);
  1951. READ64(*res);
  1952. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  1953. }
  1954. dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  1955. return status;
  1956. }
  1957. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  1958. {
  1959. uint32_t *p;
  1960. int status = 0;
  1961. *res = 0;
  1962. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  1963. return -EIO;
  1964. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  1965. READ_BUF(8);
  1966. READ64(*res);
  1967. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  1968. }
  1969. dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  1970. return status;
  1971. }
  1972. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  1973. {
  1974. uint32_t *p;
  1975. int status = 0;
  1976. *res = 0;
  1977. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  1978. return -EIO;
  1979. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  1980. READ_BUF(8);
  1981. READ64(*res);
  1982. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  1983. }
  1984. dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  1985. return status;
  1986. }
  1987. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  1988. {
  1989. uint32_t *p;
  1990. int status = 0;
  1991. *res = 0;
  1992. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  1993. return -EIO;
  1994. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  1995. READ_BUF(8);
  1996. READ64(*res);
  1997. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  1998. }
  1999. dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2000. return status;
  2001. }
  2002. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  2003. {
  2004. uint32_t *p;
  2005. int status = 0;
  2006. *maxlink = 1;
  2007. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  2008. return -EIO;
  2009. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  2010. READ_BUF(4);
  2011. READ32(*maxlink);
  2012. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  2013. }
  2014. dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
  2015. return status;
  2016. }
  2017. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  2018. {
  2019. uint32_t *p;
  2020. int status = 0;
  2021. *maxname = 1024;
  2022. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  2023. return -EIO;
  2024. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  2025. READ_BUF(4);
  2026. READ32(*maxname);
  2027. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  2028. }
  2029. dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
  2030. return status;
  2031. }
  2032. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2033. {
  2034. uint32_t *p;
  2035. int status = 0;
  2036. *res = 1024;
  2037. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  2038. return -EIO;
  2039. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  2040. uint64_t maxread;
  2041. READ_BUF(8);
  2042. READ64(maxread);
  2043. if (maxread > 0x7FFFFFFF)
  2044. maxread = 0x7FFFFFFF;
  2045. *res = (uint32_t)maxread;
  2046. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  2047. }
  2048. dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
  2049. return status;
  2050. }
  2051. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2052. {
  2053. uint32_t *p;
  2054. int status = 0;
  2055. *res = 1024;
  2056. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  2057. return -EIO;
  2058. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  2059. uint64_t maxwrite;
  2060. READ_BUF(8);
  2061. READ64(maxwrite);
  2062. if (maxwrite > 0x7FFFFFFF)
  2063. maxwrite = 0x7FFFFFFF;
  2064. *res = (uint32_t)maxwrite;
  2065. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  2066. }
  2067. dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
  2068. return status;
  2069. }
  2070. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
  2071. {
  2072. uint32_t *p;
  2073. *mode = 0;
  2074. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  2075. return -EIO;
  2076. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  2077. READ_BUF(4);
  2078. READ32(*mode);
  2079. *mode &= ~S_IFMT;
  2080. bitmap[1] &= ~FATTR4_WORD1_MODE;
  2081. }
  2082. dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
  2083. return 0;
  2084. }
  2085. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  2086. {
  2087. uint32_t *p;
  2088. *nlink = 1;
  2089. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  2090. return -EIO;
  2091. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  2092. READ_BUF(4);
  2093. READ32(*nlink);
  2094. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  2095. }
  2096. dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
  2097. return 0;
  2098. }
  2099. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
  2100. {
  2101. uint32_t len, *p;
  2102. *uid = -2;
  2103. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  2104. return -EIO;
  2105. if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
  2106. READ_BUF(4);
  2107. READ32(len);
  2108. READ_BUF(len);
  2109. if (len < XDR_MAX_NETOBJ) {
  2110. if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
  2111. dprintk("%s: nfs_map_name_to_uid failed!\n",
  2112. __FUNCTION__);
  2113. } else
  2114. printk(KERN_WARNING "%s: name too long (%u)!\n",
  2115. __FUNCTION__, len);
  2116. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  2117. }
  2118. dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
  2119. return 0;
  2120. }
  2121. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
  2122. {
  2123. uint32_t len, *p;
  2124. *gid = -2;
  2125. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  2126. return -EIO;
  2127. if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
  2128. READ_BUF(4);
  2129. READ32(len);
  2130. READ_BUF(len);
  2131. if (len < XDR_MAX_NETOBJ) {
  2132. if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
  2133. dprintk("%s: nfs_map_group_to_gid failed!\n",
  2134. __FUNCTION__);
  2135. } else
  2136. printk(KERN_WARNING "%s: name too long (%u)!\n",
  2137. __FUNCTION__, len);
  2138. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  2139. }
  2140. dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
  2141. return 0;
  2142. }
  2143. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  2144. {
  2145. uint32_t major = 0, minor = 0, *p;
  2146. *rdev = MKDEV(0,0);
  2147. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  2148. return -EIO;
  2149. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  2150. dev_t tmp;
  2151. READ_BUF(8);
  2152. READ32(major);
  2153. READ32(minor);
  2154. tmp = MKDEV(major, minor);
  2155. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  2156. *rdev = tmp;
  2157. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  2158. }
  2159. dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
  2160. return 0;
  2161. }
  2162. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2163. {
  2164. uint32_t *p;
  2165. int status = 0;
  2166. *res = 0;
  2167. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  2168. return -EIO;
  2169. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  2170. READ_BUF(8);
  2171. READ64(*res);
  2172. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  2173. }
  2174. dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2175. return status;
  2176. }
  2177. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2178. {
  2179. uint32_t *p;
  2180. int status = 0;
  2181. *res = 0;
  2182. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  2183. return -EIO;
  2184. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  2185. READ_BUF(8);
  2186. READ64(*res);
  2187. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  2188. }
  2189. dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2190. return status;
  2191. }
  2192. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2193. {
  2194. uint32_t *p;
  2195. int status = 0;
  2196. *res = 0;
  2197. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  2198. return -EIO;
  2199. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  2200. READ_BUF(8);
  2201. READ64(*res);
  2202. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  2203. }
  2204. dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2205. return status;
  2206. }
  2207. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  2208. {
  2209. uint32_t *p;
  2210. *used = 0;
  2211. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  2212. return -EIO;
  2213. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  2214. READ_BUF(8);
  2215. READ64(*used);
  2216. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  2217. }
  2218. dprintk("%s: space used=%Lu\n", __FUNCTION__,
  2219. (unsigned long long)*used);
  2220. return 0;
  2221. }
  2222. static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
  2223. {
  2224. uint32_t *p;
  2225. uint64_t sec;
  2226. uint32_t nsec;
  2227. READ_BUF(12);
  2228. READ64(sec);
  2229. READ32(nsec);
  2230. time->tv_sec = (time_t)sec;
  2231. time->tv_nsec = (long)nsec;
  2232. return 0;
  2233. }
  2234. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2235. {
  2236. int status = 0;
  2237. time->tv_sec = 0;
  2238. time->tv_nsec = 0;
  2239. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  2240. return -EIO;
  2241. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  2242. status = decode_attr_time(xdr, time);
  2243. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  2244. }
  2245. dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
  2246. return status;
  2247. }
  2248. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2249. {
  2250. int status = 0;
  2251. time->tv_sec = 0;
  2252. time->tv_nsec = 0;
  2253. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  2254. return -EIO;
  2255. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  2256. status = decode_attr_time(xdr, time);
  2257. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  2258. }
  2259. dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
  2260. return status;
  2261. }
  2262. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2263. {
  2264. int status = 0;
  2265. time->tv_sec = 0;
  2266. time->tv_nsec = 0;
  2267. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  2268. return -EIO;
  2269. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  2270. status = decode_attr_time(xdr, time);
  2271. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  2272. }
  2273. dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
  2274. return status;
  2275. }
  2276. static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
  2277. {
  2278. unsigned int attrwords = XDR_QUADLEN(attrlen);
  2279. unsigned int nwords = xdr->p - savep;
  2280. if (unlikely(attrwords != nwords)) {
  2281. printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
  2282. __FUNCTION__,
  2283. attrwords << 2,
  2284. (attrwords < nwords) ? '<' : '>',
  2285. nwords << 2);
  2286. return -EIO;
  2287. }
  2288. return 0;
  2289. }
  2290. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2291. {
  2292. uint32_t *p;
  2293. READ_BUF(20);
  2294. READ32(cinfo->atomic);
  2295. READ64(cinfo->before);
  2296. READ64(cinfo->after);
  2297. return 0;
  2298. }
  2299. static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
  2300. {
  2301. uint32_t *p;
  2302. uint32_t supp, acc;
  2303. int status;
  2304. status = decode_op_hdr(xdr, OP_ACCESS);
  2305. if (status)
  2306. return status;
  2307. READ_BUF(8);
  2308. READ32(supp);
  2309. READ32(acc);
  2310. access->supported = supp;
  2311. access->access = acc;
  2312. return 0;
  2313. }
  2314. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  2315. {
  2316. uint32_t *p;
  2317. int status;
  2318. status = decode_op_hdr(xdr, OP_CLOSE);
  2319. if (status)
  2320. return status;
  2321. READ_BUF(sizeof(res->stateid.data));
  2322. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2323. return 0;
  2324. }
  2325. static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
  2326. {
  2327. uint32_t *p;
  2328. int status;
  2329. status = decode_op_hdr(xdr, OP_COMMIT);
  2330. if (status)
  2331. return status;
  2332. READ_BUF(8);
  2333. COPYMEM(res->verf->verifier, 8);
  2334. return 0;
  2335. }
  2336. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2337. {
  2338. uint32_t *p;
  2339. uint32_t bmlen;
  2340. int status;
  2341. status = decode_op_hdr(xdr, OP_CREATE);
  2342. if (status)
  2343. return status;
  2344. if ((status = decode_change_info(xdr, cinfo)))
  2345. return status;
  2346. READ_BUF(4);
  2347. READ32(bmlen);
  2348. READ_BUF(bmlen << 2);
  2349. return 0;
  2350. }
  2351. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  2352. {
  2353. uint32_t *savep;
  2354. uint32_t attrlen,
  2355. bitmap[2] = {0};
  2356. int status;
  2357. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2358. goto xdr_error;
  2359. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2360. goto xdr_error;
  2361. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2362. goto xdr_error;
  2363. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  2364. goto xdr_error;
  2365. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  2366. goto xdr_error;
  2367. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  2368. goto xdr_error;
  2369. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  2370. goto xdr_error;
  2371. status = verify_attr_len(xdr, savep, attrlen);
  2372. xdr_error:
  2373. if (status != 0)
  2374. printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
  2375. return status;
  2376. }
  2377. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  2378. {
  2379. uint32_t *savep;
  2380. uint32_t attrlen,
  2381. bitmap[2] = {0};
  2382. int status;
  2383. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2384. goto xdr_error;
  2385. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2386. goto xdr_error;
  2387. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2388. goto xdr_error;
  2389. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  2390. goto xdr_error;
  2391. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  2392. goto xdr_error;
  2393. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  2394. goto xdr_error;
  2395. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  2396. goto xdr_error;
  2397. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  2398. goto xdr_error;
  2399. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  2400. goto xdr_error;
  2401. status = verify_attr_len(xdr, savep, attrlen);
  2402. xdr_error:
  2403. if (status != 0)
  2404. printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
  2405. return status;
  2406. }
  2407. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  2408. {
  2409. uint32_t *savep;
  2410. uint32_t attrlen,
  2411. bitmap[2] = {0};
  2412. int status;
  2413. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2414. goto xdr_error;
  2415. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2416. goto xdr_error;
  2417. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2418. goto xdr_error;
  2419. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  2420. goto xdr_error;
  2421. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
  2422. goto xdr_error;
  2423. status = verify_attr_len(xdr, savep, attrlen);
  2424. xdr_error:
  2425. if (status != 0)
  2426. printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
  2427. return status;
  2428. }
  2429. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
  2430. {
  2431. uint32_t *savep;
  2432. uint32_t attrlen,
  2433. bitmap[2] = {0},
  2434. type;
  2435. int status, fmode = 0;
  2436. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2437. goto xdr_error;
  2438. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2439. goto xdr_error;
  2440. fattr->bitmap[0] = bitmap[0];
  2441. fattr->bitmap[1] = bitmap[1];
  2442. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2443. goto xdr_error;
  2444. if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
  2445. goto xdr_error;
  2446. fattr->type = nfs_type2fmt[type].nfs2type;
  2447. fmode = nfs_type2fmt[type].mode;
  2448. if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
  2449. goto xdr_error;
  2450. if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
  2451. goto xdr_error;
  2452. if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
  2453. goto xdr_error;
  2454. if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
  2455. goto xdr_error;
  2456. if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
  2457. goto xdr_error;
  2458. fattr->mode |= fmode;
  2459. if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
  2460. goto xdr_error;
  2461. if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
  2462. goto xdr_error;
  2463. if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
  2464. goto xdr_error;
  2465. if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
  2466. goto xdr_error;
  2467. if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
  2468. goto xdr_error;
  2469. if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
  2470. goto xdr_error;
  2471. if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
  2472. goto xdr_error;
  2473. if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
  2474. goto xdr_error;
  2475. if ((status = verify_attr_len(xdr, savep, attrlen)) == 0) {
  2476. fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
  2477. fattr->timestamp = jiffies;
  2478. }
  2479. xdr_error:
  2480. if (status != 0)
  2481. printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
  2482. return status;
  2483. }
  2484. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  2485. {
  2486. uint32_t *savep;
  2487. uint32_t attrlen, bitmap[2];
  2488. int status;
  2489. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2490. goto xdr_error;
  2491. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2492. goto xdr_error;
  2493. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2494. goto xdr_error;
  2495. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  2496. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  2497. goto xdr_error;
  2498. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  2499. goto xdr_error;
  2500. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  2501. goto xdr_error;
  2502. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  2503. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  2504. goto xdr_error;
  2505. fsinfo->wtpref = fsinfo->wtmax;
  2506. status = verify_attr_len(xdr, savep, attrlen);
  2507. xdr_error:
  2508. if (status != 0)
  2509. printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
  2510. return status;
  2511. }
  2512. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  2513. {
  2514. uint32_t *p;
  2515. uint32_t len;
  2516. int status;
  2517. status = decode_op_hdr(xdr, OP_GETFH);
  2518. if (status)
  2519. return status;
  2520. /* Zero handle first to allow comparisons */
  2521. memset(fh, 0, sizeof(*fh));
  2522. READ_BUF(4);
  2523. READ32(len);
  2524. if (len > NFS4_FHSIZE)
  2525. return -EIO;
  2526. fh->size = len;
  2527. READ_BUF(len);
  2528. COPYMEM(fh->data, len);
  2529. return 0;
  2530. }
  2531. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2532. {
  2533. int status;
  2534. status = decode_op_hdr(xdr, OP_LINK);
  2535. if (status)
  2536. return status;
  2537. return decode_change_info(xdr, cinfo);
  2538. }
  2539. /*
  2540. * We create the owner, so we know a proper owner.id length is 4.
  2541. */
  2542. static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
  2543. {
  2544. uint32_t *p;
  2545. uint32_t namelen;
  2546. READ_BUF(32);
  2547. READ64(denied->offset);
  2548. READ64(denied->length);
  2549. READ32(denied->type);
  2550. READ64(denied->owner.clientid);
  2551. READ32(namelen);
  2552. READ_BUF(namelen);
  2553. if (namelen == 4)
  2554. READ32(denied->owner.id);
  2555. return -NFS4ERR_DENIED;
  2556. }
  2557. static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
  2558. {
  2559. uint32_t *p;
  2560. int status;
  2561. status = decode_op_hdr(xdr, OP_LOCK);
  2562. if (status == 0) {
  2563. READ_BUF(sizeof(nfs4_stateid));
  2564. COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
  2565. } else if (status == -NFS4ERR_DENIED)
  2566. return decode_lock_denied(xdr, &res->u.denied);
  2567. return status;
  2568. }
  2569. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
  2570. {
  2571. int status;
  2572. status = decode_op_hdr(xdr, OP_LOCKT);
  2573. if (status == -NFS4ERR_DENIED)
  2574. return decode_lock_denied(xdr, &res->u.denied);
  2575. return status;
  2576. }
  2577. static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
  2578. {
  2579. uint32_t *p;
  2580. int status;
  2581. status = decode_op_hdr(xdr, OP_LOCKU);
  2582. if (status == 0) {
  2583. READ_BUF(sizeof(nfs4_stateid));
  2584. COPYMEM(&res->u.stateid, sizeof(res->u.stateid));
  2585. }
  2586. return status;
  2587. }
  2588. static int decode_lookup(struct xdr_stream *xdr)
  2589. {
  2590. return decode_op_hdr(xdr, OP_LOOKUP);
  2591. }
  2592. /* This is too sick! */
  2593. static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
  2594. {
  2595. uint32_t *p;
  2596. uint32_t limit_type, nblocks, blocksize;
  2597. READ_BUF(12);
  2598. READ32(limit_type);
  2599. switch (limit_type) {
  2600. case 1:
  2601. READ64(*maxsize);
  2602. break;
  2603. case 2:
  2604. READ32(nblocks);
  2605. READ32(blocksize);
  2606. *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  2607. }
  2608. return 0;
  2609. }
  2610. static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  2611. {
  2612. uint32_t *p;
  2613. uint32_t delegation_type;
  2614. READ_BUF(4);
  2615. READ32(delegation_type);
  2616. if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
  2617. res->delegation_type = 0;
  2618. return 0;
  2619. }
  2620. READ_BUF(20);
  2621. COPYMEM(res->delegation.data, sizeof(res->delegation.data));
  2622. READ32(res->do_recall);
  2623. switch (delegation_type) {
  2624. case NFS4_OPEN_DELEGATE_READ:
  2625. res->delegation_type = FMODE_READ;
  2626. break;
  2627. case NFS4_OPEN_DELEGATE_WRITE:
  2628. res->delegation_type = FMODE_WRITE|FMODE_READ;
  2629. if (decode_space_limit(xdr, &res->maxsize) < 0)
  2630. return -EIO;
  2631. }
  2632. return decode_ace(xdr, NULL, res->server->nfs4_state);
  2633. }
  2634. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  2635. {
  2636. uint32_t *p;
  2637. uint32_t bmlen;
  2638. int status;
  2639. status = decode_op_hdr(xdr, OP_OPEN);
  2640. if (status)
  2641. return status;
  2642. READ_BUF(sizeof(res->stateid.data));
  2643. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2644. decode_change_info(xdr, &res->cinfo);
  2645. READ_BUF(8);
  2646. READ32(res->rflags);
  2647. READ32(bmlen);
  2648. if (bmlen > 10)
  2649. goto xdr_error;
  2650. READ_BUF(bmlen << 2);
  2651. p += bmlen;
  2652. return decode_delegation(xdr, res);
  2653. xdr_error:
  2654. printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
  2655. return -EIO;
  2656. }
  2657. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  2658. {
  2659. uint32_t *p;
  2660. int status;
  2661. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  2662. if (status)
  2663. return status;
  2664. READ_BUF(sizeof(res->stateid.data));
  2665. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2666. return 0;
  2667. }
  2668. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  2669. {
  2670. uint32_t *p;
  2671. int status;
  2672. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  2673. if (status)
  2674. return status;
  2675. READ_BUF(sizeof(res->stateid.data));
  2676. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2677. return 0;
  2678. }
  2679. static int decode_putfh(struct xdr_stream *xdr)
  2680. {
  2681. return decode_op_hdr(xdr, OP_PUTFH);
  2682. }
  2683. static int decode_putrootfh(struct xdr_stream *xdr)
  2684. {
  2685. return decode_op_hdr(xdr, OP_PUTROOTFH);
  2686. }
  2687. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
  2688. {
  2689. struct kvec *iov = req->rq_rcv_buf.head;
  2690. uint32_t *p;
  2691. uint32_t count, eof, recvd, hdrlen;
  2692. int status;
  2693. status = decode_op_hdr(xdr, OP_READ);
  2694. if (status)
  2695. return status;
  2696. READ_BUF(8);
  2697. READ32(eof);
  2698. READ32(count);
  2699. hdrlen = (u8 *) p - (u8 *) iov->iov_base;
  2700. recvd = req->rq_rcv_buf.len - hdrlen;
  2701. if (count > recvd) {
  2702. printk(KERN_WARNING "NFS: server cheating in read reply: "
  2703. "count %u > recvd %u\n", count, recvd);
  2704. count = recvd;
  2705. eof = 0;
  2706. }
  2707. xdr_read_pages(xdr, count);
  2708. res->eof = eof;
  2709. res->count = count;
  2710. return 0;
  2711. }
  2712. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  2713. {
  2714. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  2715. struct page *page = *rcvbuf->pages;
  2716. struct kvec *iov = rcvbuf->head;
  2717. unsigned int nr, pglen = rcvbuf->page_len;
  2718. uint32_t *end, *entry, *p, *kaddr;
  2719. uint32_t len, attrlen;
  2720. int hdrlen, recvd, status;
  2721. status = decode_op_hdr(xdr, OP_READDIR);
  2722. if (status)
  2723. return status;
  2724. READ_BUF(8);
  2725. COPYMEM(readdir->verifier.data, 8);
  2726. dprintk("%s: verifier = 0x%x%x\n",
  2727. __FUNCTION__,
  2728. ((u32 *)readdir->verifier.data)[0],
  2729. ((u32 *)readdir->verifier.data)[1]);
  2730. hdrlen = (char *) p - (char *) iov->iov_base;
  2731. recvd = rcvbuf->len - hdrlen;
  2732. if (pglen > recvd)
  2733. pglen = recvd;
  2734. xdr_read_pages(xdr, pglen);
  2735. BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
  2736. kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
  2737. end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
  2738. entry = p;
  2739. for (nr = 0; *p++; nr++) {
  2740. if (p + 3 > end)
  2741. goto short_pkt;
  2742. dprintk("cookie = %Lu, ", *((unsigned long long *)p));
  2743. p += 2; /* cookie */
  2744. len = ntohl(*p++); /* filename length */
  2745. if (len > NFS4_MAXNAMLEN) {
  2746. printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
  2747. goto err_unmap;
  2748. }
  2749. dprintk("filename = %*s\n", len, (char *)p);
  2750. p += XDR_QUADLEN(len);
  2751. if (p + 1 > end)
  2752. goto short_pkt;
  2753. len = ntohl(*p++); /* bitmap length */
  2754. p += len;
  2755. if (p + 1 > end)
  2756. goto short_pkt;
  2757. attrlen = XDR_QUADLEN(ntohl(*p++));
  2758. p += attrlen; /* attributes */
  2759. if (p + 2 > end)
  2760. goto short_pkt;
  2761. entry = p;
  2762. }
  2763. if (!nr && (entry[0] != 0 || entry[1] == 0))
  2764. goto short_pkt;
  2765. out:
  2766. kunmap_atomic(kaddr, KM_USER0);
  2767. return 0;
  2768. short_pkt:
  2769. dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
  2770. entry[0] = entry[1] = 0;
  2771. /* truncate listing ? */
  2772. if (!nr) {
  2773. printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
  2774. entry[1] = 1;
  2775. }
  2776. goto out;
  2777. err_unmap:
  2778. kunmap_atomic(kaddr, KM_USER0);
  2779. return -errno_NFSERR_IO;
  2780. }
  2781. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  2782. {
  2783. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  2784. struct kvec *iov = rcvbuf->head;
  2785. int hdrlen, len, recvd;
  2786. uint32_t *p;
  2787. char *kaddr;
  2788. int status;
  2789. status = decode_op_hdr(xdr, OP_READLINK);
  2790. if (status)
  2791. return status;
  2792. /* Convert length of symlink */
  2793. READ_BUF(4);
  2794. READ32(len);
  2795. if (len >= rcvbuf->page_len || len <= 0) {
  2796. dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
  2797. return -ENAMETOOLONG;
  2798. }
  2799. hdrlen = (char *) xdr->p - (char *) iov->iov_base;
  2800. recvd = req->rq_rcv_buf.len - hdrlen;
  2801. if (recvd < len) {
  2802. printk(KERN_WARNING "NFS: server cheating in readlink reply: "
  2803. "count %u > recvd %u\n", len, recvd);
  2804. return -EIO;
  2805. }
  2806. xdr_read_pages(xdr, len);
  2807. /*
  2808. * The XDR encode routine has set things up so that
  2809. * the link text will be copied directly into the
  2810. * buffer. We just have to do overflow-checking,
  2811. * and and null-terminate the text (the VFS expects
  2812. * null-termination).
  2813. */
  2814. kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
  2815. kaddr[len+rcvbuf->page_base] = '\0';
  2816. kunmap_atomic(kaddr, KM_USER0);
  2817. return 0;
  2818. }
  2819. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2820. {
  2821. int status;
  2822. status = decode_op_hdr(xdr, OP_REMOVE);
  2823. if (status)
  2824. goto out;
  2825. status = decode_change_info(xdr, cinfo);
  2826. out:
  2827. return status;
  2828. }
  2829. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  2830. struct nfs4_change_info *new_cinfo)
  2831. {
  2832. int status;
  2833. status = decode_op_hdr(xdr, OP_RENAME);
  2834. if (status)
  2835. goto out;
  2836. if ((status = decode_change_info(xdr, old_cinfo)))
  2837. goto out;
  2838. status = decode_change_info(xdr, new_cinfo);
  2839. out:
  2840. return status;
  2841. }
  2842. static int decode_renew(struct xdr_stream *xdr)
  2843. {
  2844. return decode_op_hdr(xdr, OP_RENEW);
  2845. }
  2846. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  2847. size_t *acl_len)
  2848. {
  2849. uint32_t *savep;
  2850. uint32_t attrlen,
  2851. bitmap[2] = {0};
  2852. struct kvec *iov = req->rq_rcv_buf.head;
  2853. int status;
  2854. *acl_len = 0;
  2855. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2856. goto out;
  2857. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2858. goto out;
  2859. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2860. goto out;
  2861. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  2862. return -EIO;
  2863. if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
  2864. int hdrlen, recvd;
  2865. /* We ignore &savep and don't do consistency checks on
  2866. * the attr length. Let userspace figure it out.... */
  2867. hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
  2868. recvd = req->rq_rcv_buf.len - hdrlen;
  2869. if (attrlen > recvd) {
  2870. printk(KERN_WARNING "NFS: server cheating in getattr"
  2871. " acl reply: attrlen %u > recvd %u\n",
  2872. attrlen, recvd);
  2873. return -EINVAL;
  2874. }
  2875. if (attrlen <= *acl_len)
  2876. xdr_read_pages(xdr, attrlen);
  2877. *acl_len = attrlen;
  2878. }
  2879. out:
  2880. return status;
  2881. }
  2882. static int
  2883. decode_savefh(struct xdr_stream *xdr)
  2884. {
  2885. return decode_op_hdr(xdr, OP_SAVEFH);
  2886. }
  2887. static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
  2888. {
  2889. uint32_t *p;
  2890. uint32_t bmlen;
  2891. int status;
  2892. status = decode_op_hdr(xdr, OP_SETATTR);
  2893. if (status)
  2894. return status;
  2895. READ_BUF(4);
  2896. READ32(bmlen);
  2897. READ_BUF(bmlen << 2);
  2898. return 0;
  2899. }
  2900. static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
  2901. {
  2902. uint32_t *p;
  2903. uint32_t opnum;
  2904. int32_t nfserr;
  2905. READ_BUF(8);
  2906. READ32(opnum);
  2907. if (opnum != OP_SETCLIENTID) {
  2908. printk(KERN_NOTICE
  2909. "nfs4_decode_setclientid: Server returned operation"
  2910. " %d\n", opnum);
  2911. return -EIO;
  2912. }
  2913. READ32(nfserr);
  2914. if (nfserr == NFS_OK) {
  2915. READ_BUF(8 + sizeof(clp->cl_confirm.data));
  2916. READ64(clp->cl_clientid);
  2917. COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
  2918. } else if (nfserr == NFSERR_CLID_INUSE) {
  2919. uint32_t len;
  2920. /* skip netid string */
  2921. READ_BUF(4);
  2922. READ32(len);
  2923. READ_BUF(len);
  2924. /* skip uaddr string */
  2925. READ_BUF(4);
  2926. READ32(len);
  2927. READ_BUF(len);
  2928. return -NFSERR_CLID_INUSE;
  2929. } else
  2930. return -nfs_stat_to_errno(nfserr);
  2931. return 0;
  2932. }
  2933. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  2934. {
  2935. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  2936. }
  2937. static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
  2938. {
  2939. uint32_t *p;
  2940. int status;
  2941. status = decode_op_hdr(xdr, OP_WRITE);
  2942. if (status)
  2943. return status;
  2944. READ_BUF(16);
  2945. READ32(res->count);
  2946. READ32(res->verf->committed);
  2947. COPYMEM(res->verf->verifier, 8);
  2948. return 0;
  2949. }
  2950. static int decode_delegreturn(struct xdr_stream *xdr)
  2951. {
  2952. return decode_op_hdr(xdr, OP_DELEGRETURN);
  2953. }
  2954. /*
  2955. * Decode OPEN_DOWNGRADE response
  2956. */
  2957. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
  2958. {
  2959. struct xdr_stream xdr;
  2960. struct compound_hdr hdr;
  2961. int status;
  2962. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  2963. status = decode_compound_hdr(&xdr, &hdr);
  2964. if (status)
  2965. goto out;
  2966. status = decode_putfh(&xdr);
  2967. if (status)
  2968. goto out;
  2969. status = decode_open_downgrade(&xdr, res);
  2970. out:
  2971. return status;
  2972. }
  2973. /*
  2974. * END OF "GENERIC" DECODE ROUTINES.
  2975. */
  2976. /*
  2977. * Decode ACCESS response
  2978. */
  2979. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
  2980. {
  2981. struct xdr_stream xdr;
  2982. struct compound_hdr hdr;
  2983. int status;
  2984. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  2985. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  2986. goto out;
  2987. if ((status = decode_putfh(&xdr)) == 0)
  2988. status = decode_access(&xdr, res);
  2989. out:
  2990. return status;
  2991. }
  2992. /*
  2993. * Decode LOOKUP response
  2994. */
  2995. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
  2996. {
  2997. struct xdr_stream xdr;
  2998. struct compound_hdr hdr;
  2999. int status;
  3000. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3001. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3002. goto out;
  3003. if ((status = decode_putfh(&xdr)) != 0)
  3004. goto out;
  3005. if ((status = decode_lookup(&xdr)) != 0)
  3006. goto out;
  3007. if ((status = decode_getfh(&xdr, res->fh)) != 0)
  3008. goto out;
  3009. status = decode_getfattr(&xdr, res->fattr, res->server);
  3010. out:
  3011. return status;
  3012. }
  3013. /*
  3014. * Decode LOOKUP_ROOT response
  3015. */
  3016. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
  3017. {
  3018. struct xdr_stream xdr;
  3019. struct compound_hdr hdr;
  3020. int status;
  3021. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3022. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3023. goto out;
  3024. if ((status = decode_putrootfh(&xdr)) != 0)
  3025. goto out;
  3026. if ((status = decode_getfh(&xdr, res->fh)) == 0)
  3027. status = decode_getfattr(&xdr, res->fattr, res->server);
  3028. out:
  3029. return status;
  3030. }
  3031. /*
  3032. * Decode REMOVE response
  3033. */
  3034. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
  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_putfh(&xdr)) == 0)
  3043. status = decode_remove(&xdr, cinfo);
  3044. out:
  3045. return status;
  3046. }
  3047. /*
  3048. * Decode RENAME response
  3049. */
  3050. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
  3051. {
  3052. struct xdr_stream xdr;
  3053. struct compound_hdr hdr;
  3054. int status;
  3055. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3056. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3057. goto out;
  3058. if ((status = decode_putfh(&xdr)) != 0)
  3059. goto out;
  3060. if ((status = decode_savefh(&xdr)) != 0)
  3061. goto out;
  3062. if ((status = decode_putfh(&xdr)) != 0)
  3063. goto out;
  3064. status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo);
  3065. out:
  3066. return status;
  3067. }
  3068. /*
  3069. * Decode LINK response
  3070. */
  3071. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_change_info *cinfo)
  3072. {
  3073. struct xdr_stream xdr;
  3074. struct compound_hdr hdr;
  3075. int status;
  3076. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3077. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3078. goto out;
  3079. if ((status = decode_putfh(&xdr)) != 0)
  3080. goto out;
  3081. if ((status = decode_savefh(&xdr)) != 0)
  3082. goto out;
  3083. if ((status = decode_putfh(&xdr)) != 0)
  3084. goto out;
  3085. status = decode_link(&xdr, cinfo);
  3086. out:
  3087. return status;
  3088. }
  3089. /*
  3090. * Decode CREATE response
  3091. */
  3092. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
  3093. {
  3094. struct xdr_stream xdr;
  3095. struct compound_hdr hdr;
  3096. int status;
  3097. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3098. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3099. goto out;
  3100. if ((status = decode_putfh(&xdr)) != 0)
  3101. goto out;
  3102. if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
  3103. goto out;
  3104. if ((status = decode_getfh(&xdr, res->fh)) != 0)
  3105. goto out;
  3106. status = decode_getfattr(&xdr, res->fattr, res->server);
  3107. if (status == NFS4ERR_DELAY)
  3108. status = 0;
  3109. out:
  3110. return status;
  3111. }
  3112. /*
  3113. * Decode SYMLINK response
  3114. */
  3115. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
  3116. {
  3117. return nfs4_xdr_dec_create(rqstp, p, res);
  3118. }
  3119. /*
  3120. * Decode GETATTR response
  3121. */
  3122. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
  3123. {
  3124. struct xdr_stream xdr;
  3125. struct compound_hdr hdr;
  3126. int status;
  3127. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3128. status = decode_compound_hdr(&xdr, &hdr);
  3129. if (status)
  3130. goto out;
  3131. status = decode_putfh(&xdr);
  3132. if (status)
  3133. goto out;
  3134. status = decode_getfattr(&xdr, res->fattr, res->server);
  3135. out:
  3136. return status;
  3137. }
  3138. /*
  3139. * Encode an SETACL request
  3140. */
  3141. static int
  3142. nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args)
  3143. {
  3144. struct xdr_stream xdr;
  3145. struct compound_hdr hdr = {
  3146. .nops = 2,
  3147. };
  3148. int status;
  3149. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  3150. encode_compound_hdr(&xdr, &hdr);
  3151. status = encode_putfh(&xdr, args->fh);
  3152. if (status)
  3153. goto out;
  3154. status = encode_setacl(&xdr, args);
  3155. out:
  3156. return status;
  3157. }
  3158. /*
  3159. * Decode SETACL response
  3160. */
  3161. static int
  3162. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res)
  3163. {
  3164. struct xdr_stream xdr;
  3165. struct compound_hdr hdr;
  3166. int status;
  3167. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3168. status = decode_compound_hdr(&xdr, &hdr);
  3169. if (status)
  3170. goto out;
  3171. status = decode_putfh(&xdr);
  3172. if (status)
  3173. goto out;
  3174. status = decode_setattr(&xdr, res);
  3175. out:
  3176. return status;
  3177. }
  3178. /*
  3179. * Decode GETACL response
  3180. */
  3181. static int
  3182. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len)
  3183. {
  3184. struct xdr_stream xdr;
  3185. struct compound_hdr hdr;
  3186. int status;
  3187. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3188. status = decode_compound_hdr(&xdr, &hdr);
  3189. if (status)
  3190. goto out;
  3191. status = decode_putfh(&xdr);
  3192. if (status)
  3193. goto out;
  3194. status = decode_getacl(&xdr, rqstp, acl_len);
  3195. out:
  3196. return status;
  3197. }
  3198. /*
  3199. * Decode CLOSE response
  3200. */
  3201. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
  3202. {
  3203. struct xdr_stream xdr;
  3204. struct compound_hdr hdr;
  3205. int status;
  3206. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3207. status = decode_compound_hdr(&xdr, &hdr);
  3208. if (status)
  3209. goto out;
  3210. status = decode_putfh(&xdr);
  3211. if (status)
  3212. goto out;
  3213. status = decode_close(&xdr, res);
  3214. out:
  3215. return status;
  3216. }
  3217. /*
  3218. * Decode OPEN response
  3219. */
  3220. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
  3221. {
  3222. struct xdr_stream xdr;
  3223. struct compound_hdr hdr;
  3224. int status;
  3225. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3226. status = decode_compound_hdr(&xdr, &hdr);
  3227. if (status)
  3228. goto out;
  3229. status = decode_putfh(&xdr);
  3230. if (status)
  3231. goto out;
  3232. status = decode_open(&xdr, res);
  3233. if (status)
  3234. goto out;
  3235. status = decode_getfh(&xdr, &res->fh);
  3236. if (status)
  3237. goto out;
  3238. status = decode_getfattr(&xdr, res->f_attr, res->server);
  3239. if (status == NFS4ERR_DELAY)
  3240. status = 0;
  3241. out:
  3242. return status;
  3243. }
  3244. /*
  3245. * Decode OPEN_CONFIRM response
  3246. */
  3247. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
  3248. {
  3249. struct xdr_stream xdr;
  3250. struct compound_hdr hdr;
  3251. int status;
  3252. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3253. status = decode_compound_hdr(&xdr, &hdr);
  3254. if (status)
  3255. goto out;
  3256. status = decode_putfh(&xdr);
  3257. if (status)
  3258. goto out;
  3259. status = decode_open_confirm(&xdr, res);
  3260. out:
  3261. return status;
  3262. }
  3263. /*
  3264. * Decode OPEN response
  3265. */
  3266. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
  3267. {
  3268. struct xdr_stream xdr;
  3269. struct compound_hdr hdr;
  3270. int status;
  3271. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3272. status = decode_compound_hdr(&xdr, &hdr);
  3273. if (status)
  3274. goto out;
  3275. status = decode_putfh(&xdr);
  3276. if (status)
  3277. goto out;
  3278. status = decode_open(&xdr, res);
  3279. out:
  3280. return status;
  3281. }
  3282. /*
  3283. * Decode SETATTR response
  3284. */
  3285. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
  3286. {
  3287. struct xdr_stream xdr;
  3288. struct compound_hdr hdr;
  3289. int status;
  3290. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3291. status = decode_compound_hdr(&xdr, &hdr);
  3292. if (status)
  3293. goto out;
  3294. status = decode_putfh(&xdr);
  3295. if (status)
  3296. goto out;
  3297. status = decode_setattr(&xdr, res);
  3298. if (status)
  3299. goto out;
  3300. status = decode_getfattr(&xdr, res->fattr, res->server);
  3301. if (status == NFS4ERR_DELAY)
  3302. status = 0;
  3303. out:
  3304. return status;
  3305. }
  3306. /*
  3307. * Decode LOCK response
  3308. */
  3309. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
  3310. {
  3311. struct xdr_stream xdr;
  3312. struct compound_hdr hdr;
  3313. int status;
  3314. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3315. status = decode_compound_hdr(&xdr, &hdr);
  3316. if (status)
  3317. goto out;
  3318. status = decode_putfh(&xdr);
  3319. if (status)
  3320. goto out;
  3321. status = decode_lock(&xdr, res);
  3322. out:
  3323. return status;
  3324. }
  3325. /*
  3326. * Decode LOCKT response
  3327. */
  3328. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
  3329. {
  3330. struct xdr_stream xdr;
  3331. struct compound_hdr hdr;
  3332. int status;
  3333. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3334. status = decode_compound_hdr(&xdr, &hdr);
  3335. if (status)
  3336. goto out;
  3337. status = decode_putfh(&xdr);
  3338. if (status)
  3339. goto out;
  3340. status = decode_lockt(&xdr, res);
  3341. out:
  3342. return status;
  3343. }
  3344. /*
  3345. * Decode LOCKU response
  3346. */
  3347. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
  3348. {
  3349. struct xdr_stream xdr;
  3350. struct compound_hdr hdr;
  3351. int status;
  3352. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3353. status = decode_compound_hdr(&xdr, &hdr);
  3354. if (status)
  3355. goto out;
  3356. status = decode_putfh(&xdr);
  3357. if (status)
  3358. goto out;
  3359. status = decode_locku(&xdr, res);
  3360. out:
  3361. return status;
  3362. }
  3363. /*
  3364. * Decode READLINK response
  3365. */
  3366. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
  3367. {
  3368. struct xdr_stream xdr;
  3369. struct compound_hdr hdr;
  3370. int status;
  3371. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3372. status = decode_compound_hdr(&xdr, &hdr);
  3373. if (status)
  3374. goto out;
  3375. status = decode_putfh(&xdr);
  3376. if (status)
  3377. goto out;
  3378. status = decode_readlink(&xdr, rqstp);
  3379. out:
  3380. return status;
  3381. }
  3382. /*
  3383. * Decode READDIR response
  3384. */
  3385. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
  3386. {
  3387. struct xdr_stream xdr;
  3388. struct compound_hdr hdr;
  3389. int status;
  3390. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3391. status = decode_compound_hdr(&xdr, &hdr);
  3392. if (status)
  3393. goto out;
  3394. status = decode_putfh(&xdr);
  3395. if (status)
  3396. goto out;
  3397. status = decode_readdir(&xdr, rqstp, res);
  3398. out:
  3399. return status;
  3400. }
  3401. /*
  3402. * Decode Read response
  3403. */
  3404. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
  3405. {
  3406. struct xdr_stream xdr;
  3407. struct compound_hdr hdr;
  3408. int status;
  3409. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3410. status = decode_compound_hdr(&xdr, &hdr);
  3411. if (status)
  3412. goto out;
  3413. status = decode_putfh(&xdr);
  3414. if (status)
  3415. goto out;
  3416. status = decode_read(&xdr, rqstp, res);
  3417. if (!status)
  3418. status = res->count;
  3419. out:
  3420. return status;
  3421. }
  3422. /*
  3423. * Decode WRITE response
  3424. */
  3425. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
  3426. {
  3427. struct xdr_stream xdr;
  3428. struct compound_hdr hdr;
  3429. int status;
  3430. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3431. status = decode_compound_hdr(&xdr, &hdr);
  3432. if (status)
  3433. goto out;
  3434. status = decode_putfh(&xdr);
  3435. if (status)
  3436. goto out;
  3437. status = decode_write(&xdr, res);
  3438. if (!status)
  3439. status = res->count;
  3440. out:
  3441. return status;
  3442. }
  3443. /*
  3444. * Decode COMMIT response
  3445. */
  3446. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
  3447. {
  3448. struct xdr_stream xdr;
  3449. struct compound_hdr hdr;
  3450. int status;
  3451. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3452. status = decode_compound_hdr(&xdr, &hdr);
  3453. if (status)
  3454. goto out;
  3455. status = decode_putfh(&xdr);
  3456. if (status)
  3457. goto out;
  3458. status = decode_commit(&xdr, res);
  3459. out:
  3460. return status;
  3461. }
  3462. /*
  3463. * FSINFO request
  3464. */
  3465. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
  3466. {
  3467. struct xdr_stream xdr;
  3468. struct compound_hdr hdr;
  3469. int status;
  3470. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3471. status = decode_compound_hdr(&xdr, &hdr);
  3472. if (!status)
  3473. status = decode_putfh(&xdr);
  3474. if (!status)
  3475. status = decode_fsinfo(&xdr, fsinfo);
  3476. if (!status)
  3477. status = -nfs_stat_to_errno(hdr.status);
  3478. return status;
  3479. }
  3480. /*
  3481. * PATHCONF request
  3482. */
  3483. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
  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_pathconf(&xdr, pathconf);
  3494. return status;
  3495. }
  3496. /*
  3497. * STATFS request
  3498. */
  3499. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
  3500. {
  3501. struct xdr_stream xdr;
  3502. struct compound_hdr hdr;
  3503. int status;
  3504. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3505. status = decode_compound_hdr(&xdr, &hdr);
  3506. if (!status)
  3507. status = decode_putfh(&xdr);
  3508. if (!status)
  3509. status = decode_statfs(&xdr, fsstat);
  3510. return status;
  3511. }
  3512. /*
  3513. * GETATTR_BITMAP request
  3514. */
  3515. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
  3516. {
  3517. struct xdr_stream xdr;
  3518. struct compound_hdr hdr;
  3519. int status;
  3520. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3521. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3522. goto out;
  3523. if ((status = decode_putfh(&xdr)) != 0)
  3524. goto out;
  3525. status = decode_server_caps(&xdr, res);
  3526. out:
  3527. return status;
  3528. }
  3529. /*
  3530. * Decode RENEW response
  3531. */
  3532. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
  3533. {
  3534. struct xdr_stream xdr;
  3535. struct compound_hdr hdr;
  3536. int status;
  3537. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3538. status = decode_compound_hdr(&xdr, &hdr);
  3539. if (!status)
  3540. status = decode_renew(&xdr);
  3541. return status;
  3542. }
  3543. /*
  3544. * a SETCLIENTID request
  3545. */
  3546. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
  3547. struct nfs4_client *clp)
  3548. {
  3549. struct xdr_stream xdr;
  3550. struct compound_hdr hdr;
  3551. int status;
  3552. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3553. status = decode_compound_hdr(&xdr, &hdr);
  3554. if (!status)
  3555. status = decode_setclientid(&xdr, clp);
  3556. if (!status)
  3557. status = -nfs_stat_to_errno(hdr.status);
  3558. return status;
  3559. }
  3560. /*
  3561. * a SETCLIENTID_CONFIRM request
  3562. */
  3563. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
  3564. {
  3565. struct xdr_stream xdr;
  3566. struct compound_hdr hdr;
  3567. int status;
  3568. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3569. status = decode_compound_hdr(&xdr, &hdr);
  3570. if (!status)
  3571. status = decode_setclientid_confirm(&xdr);
  3572. if (!status)
  3573. status = decode_putrootfh(&xdr);
  3574. if (!status)
  3575. status = decode_fsinfo(&xdr, fsinfo);
  3576. if (!status)
  3577. status = -nfs_stat_to_errno(hdr.status);
  3578. return status;
  3579. }
  3580. /*
  3581. * DELEGRETURN request
  3582. */
  3583. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
  3584. {
  3585. struct xdr_stream xdr;
  3586. struct compound_hdr hdr;
  3587. int status;
  3588. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3589. status = decode_compound_hdr(&xdr, &hdr);
  3590. if (status == 0) {
  3591. status = decode_putfh(&xdr);
  3592. if (status == 0)
  3593. status = decode_delegreturn(&xdr);
  3594. }
  3595. return status;
  3596. }
  3597. uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
  3598. {
  3599. uint32_t bitmap[2] = {0};
  3600. uint32_t len;
  3601. if (!*p++) {
  3602. if (!*p)
  3603. return ERR_PTR(-EAGAIN);
  3604. entry->eof = 1;
  3605. return ERR_PTR(-EBADCOOKIE);
  3606. }
  3607. entry->prev_cookie = entry->cookie;
  3608. p = xdr_decode_hyper(p, &entry->cookie);
  3609. entry->len = ntohl(*p++);
  3610. entry->name = (const char *) p;
  3611. p += XDR_QUADLEN(entry->len);
  3612. /*
  3613. * In case the server doesn't return an inode number,
  3614. * we fake one here. (We don't use inode number 0,
  3615. * since glibc seems to choke on it...)
  3616. */
  3617. entry->ino = 1;
  3618. len = ntohl(*p++); /* bitmap length */
  3619. if (len-- > 0) {
  3620. bitmap[0] = ntohl(*p++);
  3621. if (len-- > 0) {
  3622. bitmap[1] = ntohl(*p++);
  3623. p += len;
  3624. }
  3625. }
  3626. len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
  3627. if (len > 0) {
  3628. if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
  3629. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  3630. /* Ignore the return value of rdattr_error for now */
  3631. p++;
  3632. len--;
  3633. }
  3634. if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
  3635. xdr_decode_hyper(p, &entry->ino);
  3636. else if (bitmap[0] == FATTR4_WORD0_FILEID)
  3637. xdr_decode_hyper(p, &entry->ino);
  3638. p += len;
  3639. }
  3640. entry->eof = !p[0] && p[1];
  3641. return p;
  3642. }
  3643. /*
  3644. * We need to translate between nfs status return values and
  3645. * the local errno values which may not be the same.
  3646. */
  3647. static struct {
  3648. int stat;
  3649. int errno;
  3650. } nfs_errtbl[] = {
  3651. { NFS4_OK, 0 },
  3652. { NFS4ERR_PERM, EPERM },
  3653. { NFS4ERR_NOENT, ENOENT },
  3654. { NFS4ERR_IO, errno_NFSERR_IO },
  3655. { NFS4ERR_NXIO, ENXIO },
  3656. { NFS4ERR_ACCESS, EACCES },
  3657. { NFS4ERR_EXIST, EEXIST },
  3658. { NFS4ERR_XDEV, EXDEV },
  3659. { NFS4ERR_NOTDIR, ENOTDIR },
  3660. { NFS4ERR_ISDIR, EISDIR },
  3661. { NFS4ERR_INVAL, EINVAL },
  3662. { NFS4ERR_FBIG, EFBIG },
  3663. { NFS4ERR_NOSPC, ENOSPC },
  3664. { NFS4ERR_ROFS, EROFS },
  3665. { NFS4ERR_MLINK, EMLINK },
  3666. { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
  3667. { NFS4ERR_NOTEMPTY, ENOTEMPTY },
  3668. { NFS4ERR_DQUOT, EDQUOT },
  3669. { NFS4ERR_STALE, ESTALE },
  3670. { NFS4ERR_BADHANDLE, EBADHANDLE },
  3671. { NFS4ERR_BADOWNER, EINVAL },
  3672. { NFS4ERR_BADNAME, EINVAL },
  3673. { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
  3674. { NFS4ERR_NOTSUPP, ENOTSUPP },
  3675. { NFS4ERR_TOOSMALL, ETOOSMALL },
  3676. { NFS4ERR_SERVERFAULT, ESERVERFAULT },
  3677. { NFS4ERR_BADTYPE, EBADTYPE },
  3678. { NFS4ERR_LOCKED, EAGAIN },
  3679. { NFS4ERR_RESOURCE, EREMOTEIO },
  3680. { NFS4ERR_SYMLINK, ELOOP },
  3681. { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
  3682. { NFS4ERR_DEADLOCK, EDEADLK },
  3683. { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
  3684. * to be handled by a
  3685. * middle-layer.
  3686. */
  3687. { -1, EIO }
  3688. };
  3689. /*
  3690. * Convert an NFS error code to a local one.
  3691. * This one is used jointly by NFSv2 and NFSv3.
  3692. */
  3693. static int
  3694. nfs_stat_to_errno(int stat)
  3695. {
  3696. int i;
  3697. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  3698. if (nfs_errtbl[i].stat == stat)
  3699. return nfs_errtbl[i].errno;
  3700. }
  3701. if (stat <= 10000 || stat > 10100) {
  3702. /* The server is looney tunes. */
  3703. return ESERVERFAULT;
  3704. }
  3705. /* If we cannot translate the error, the recovery routines should
  3706. * handle it.
  3707. * Note: remaining NFSv4 error codes have values > 10000, so should
  3708. * not conflict with native Linux error codes.
  3709. */
  3710. return stat;
  3711. }
  3712. #ifndef MAX
  3713. # define MAX(a, b) (((a) > (b))? (a) : (b))
  3714. #endif
  3715. #define PROC(proc, argtype, restype) \
  3716. [NFSPROC4_CLNT_##proc] = { \
  3717. .p_proc = NFSPROC4_COMPOUND, \
  3718. .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
  3719. .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
  3720. .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
  3721. }
  3722. struct rpc_procinfo nfs4_procedures[] = {
  3723. PROC(READ, enc_read, dec_read),
  3724. PROC(WRITE, enc_write, dec_write),
  3725. PROC(COMMIT, enc_commit, dec_commit),
  3726. PROC(OPEN, enc_open, dec_open),
  3727. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  3728. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  3729. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  3730. PROC(CLOSE, enc_close, dec_close),
  3731. PROC(SETATTR, enc_setattr, dec_setattr),
  3732. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  3733. PROC(RENEW, enc_renew, dec_renew),
  3734. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  3735. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  3736. PROC(LOCK, enc_lock, dec_lock),
  3737. PROC(LOCKT, enc_lockt, dec_lockt),
  3738. PROC(LOCKU, enc_locku, dec_locku),
  3739. PROC(ACCESS, enc_access, dec_access),
  3740. PROC(GETATTR, enc_getattr, dec_getattr),
  3741. PROC(LOOKUP, enc_lookup, dec_lookup),
  3742. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  3743. PROC(REMOVE, enc_remove, dec_remove),
  3744. PROC(RENAME, enc_rename, dec_rename),
  3745. PROC(LINK, enc_link, dec_link),
  3746. PROC(SYMLINK, enc_symlink, dec_symlink),
  3747. PROC(CREATE, enc_create, dec_create),
  3748. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  3749. PROC(STATFS, enc_statfs, dec_statfs),
  3750. PROC(READLINK, enc_readlink, dec_readlink),
  3751. PROC(READDIR, enc_readdir, dec_readdir),
  3752. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  3753. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  3754. PROC(GETACL, enc_getacl, dec_getacl),
  3755. PROC(SETACL, enc_setacl, dec_setacl),
  3756. };
  3757. struct rpc_version nfs_version4 = {
  3758. .number = 4,
  3759. .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
  3760. .procs = nfs4_procedures
  3761. };
  3762. /*
  3763. * Local variables:
  3764. * c-basic-offset: 8
  3765. * End:
  3766. */