nfs4xdr.c 102 KB

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