nfs4xdr.c 104 KB

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