nfs3xdr.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618
  1. /*
  2. * linux/fs/nfs/nfs3xdr.c
  3. *
  4. * XDR functions to encode/decode NFSv3 RPC arguments and results.
  5. *
  6. * Copyright (C) 1996, 1997 Olaf Kirch
  7. */
  8. #include <linux/param.h>
  9. #include <linux/time.h>
  10. #include <linux/mm.h>
  11. #include <linux/errno.h>
  12. #include <linux/string.h>
  13. #include <linux/in.h>
  14. #include <linux/pagemap.h>
  15. #include <linux/proc_fs.h>
  16. #include <linux/kdev_t.h>
  17. #include <linux/sunrpc/clnt.h>
  18. #include <linux/nfs.h>
  19. #include <linux/nfs3.h>
  20. #include <linux/nfs_fs.h>
  21. #include <linux/nfsacl.h>
  22. #include "internal.h"
  23. #define NFSDBG_FACILITY NFSDBG_XDR
  24. /* Mapping from NFS error code to "errno" error code. */
  25. #define errno_NFSERR_IO EIO
  26. /*
  27. * Declare the space requirements for NFS arguments and replies as
  28. * number of 32bit-words
  29. */
  30. #define NFS3_fhandle_sz (1+16)
  31. #define NFS3_fh_sz (NFS3_fhandle_sz) /* shorthand */
  32. #define NFS3_sattr_sz (15)
  33. #define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2))
  34. #define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2))
  35. #define NFS3_fattr_sz (21)
  36. #define NFS3_cookieverf_sz (NFS3_COOKIEVERFSIZE>>2)
  37. #define NFS3_wcc_attr_sz (6)
  38. #define NFS3_pre_op_attr_sz (1+NFS3_wcc_attr_sz)
  39. #define NFS3_post_op_attr_sz (1+NFS3_fattr_sz)
  40. #define NFS3_wcc_data_sz (NFS3_pre_op_attr_sz+NFS3_post_op_attr_sz)
  41. #define NFS3_diropargs_sz (NFS3_fh_sz+NFS3_filename_sz)
  42. #define NFS3_getattrargs_sz (NFS3_fh_sz)
  43. #define NFS3_setattrargs_sz (NFS3_fh_sz+NFS3_sattr_sz+3)
  44. #define NFS3_lookupargs_sz (NFS3_fh_sz+NFS3_filename_sz)
  45. #define NFS3_accessargs_sz (NFS3_fh_sz+1)
  46. #define NFS3_readlinkargs_sz (NFS3_fh_sz)
  47. #define NFS3_readargs_sz (NFS3_fh_sz+3)
  48. #define NFS3_writeargs_sz (NFS3_fh_sz+5)
  49. #define NFS3_createargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
  50. #define NFS3_mkdirargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
  51. #define NFS3_symlinkargs_sz (NFS3_diropargs_sz+1+NFS3_sattr_sz)
  52. #define NFS3_mknodargs_sz (NFS3_diropargs_sz+2+NFS3_sattr_sz)
  53. #define NFS3_removeargs_sz (NFS3_fh_sz+NFS3_filename_sz)
  54. #define NFS3_renameargs_sz (NFS3_diropargs_sz+NFS3_diropargs_sz)
  55. #define NFS3_linkargs_sz (NFS3_fh_sz+NFS3_diropargs_sz)
  56. #define NFS3_readdirargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+3)
  57. #define NFS3_readdirplusargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+4)
  58. #define NFS3_commitargs_sz (NFS3_fh_sz+3)
  59. #define NFS3_getattrres_sz (1+NFS3_fattr_sz)
  60. #define NFS3_setattrres_sz (1+NFS3_wcc_data_sz)
  61. #define NFS3_removeres_sz (NFS3_setattrres_sz)
  62. #define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
  63. #define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1)
  64. #define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1)
  65. #define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3)
  66. #define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4)
  67. #define NFS3_createres_sz (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
  68. #define NFS3_renameres_sz (1+(2 * NFS3_wcc_data_sz))
  69. #define NFS3_linkres_sz (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
  70. #define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2)
  71. #define NFS3_fsstatres_sz (1+NFS3_post_op_attr_sz+13)
  72. #define NFS3_fsinfores_sz (1+NFS3_post_op_attr_sz+12)
  73. #define NFS3_pathconfres_sz (1+NFS3_post_op_attr_sz+6)
  74. #define NFS3_commitres_sz (1+NFS3_wcc_data_sz+2)
  75. #define ACL3_getaclargs_sz (NFS3_fh_sz+1)
  76. #define ACL3_setaclargs_sz (NFS3_fh_sz+1+ \
  77. XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
  78. #define ACL3_getaclres_sz (1+NFS3_post_op_attr_sz+1+ \
  79. XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
  80. #define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
  81. static int nfs3_stat_to_errno(enum nfs_stat);
  82. /*
  83. * Map file type to S_IFMT bits
  84. */
  85. static const umode_t nfs_type2fmt[] = {
  86. [NF3BAD] = 0,
  87. [NF3REG] = S_IFREG,
  88. [NF3DIR] = S_IFDIR,
  89. [NF3BLK] = S_IFBLK,
  90. [NF3CHR] = S_IFCHR,
  91. [NF3LNK] = S_IFLNK,
  92. [NF3SOCK] = S_IFSOCK,
  93. [NF3FIFO] = S_IFIFO,
  94. };
  95. /*
  96. * While encoding arguments, set up the reply buffer in advance to
  97. * receive reply data directly into the page cache.
  98. */
  99. static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages,
  100. unsigned int base, unsigned int len,
  101. unsigned int bufsize)
  102. {
  103. struct rpc_auth *auth = req->rq_cred->cr_auth;
  104. unsigned int replen;
  105. replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize;
  106. xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len);
  107. }
  108. /*
  109. * Handle decode buffer overflows out-of-line.
  110. */
  111. static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
  112. {
  113. dprintk("NFS: %s prematurely hit the end of our receive buffer. "
  114. "Remaining buffer length is %tu words.\n",
  115. func, xdr->end - xdr->p);
  116. }
  117. /*
  118. * Encode/decode NFSv3 basic data types
  119. *
  120. * Basic NFSv3 data types are defined in section 2.5 of RFC 1813:
  121. * "NFS Version 3 Protocol Specification".
  122. *
  123. * Not all basic data types have their own encoding and decoding
  124. * functions. For run-time efficiency, some data types are encoded
  125. * or decoded inline.
  126. */
  127. static void encode_uint32(struct xdr_stream *xdr, u32 value)
  128. {
  129. __be32 *p = xdr_reserve_space(xdr, 4);
  130. *p = cpu_to_be32(value);
  131. }
  132. static int decode_uint32(struct xdr_stream *xdr, u32 *value)
  133. {
  134. __be32 *p;
  135. p = xdr_inline_decode(xdr, 4);
  136. if (unlikely(p == NULL))
  137. goto out_overflow;
  138. *value = be32_to_cpup(p);
  139. return 0;
  140. out_overflow:
  141. print_overflow_msg(__func__, xdr);
  142. return -EIO;
  143. }
  144. static int decode_uint64(struct xdr_stream *xdr, u64 *value)
  145. {
  146. __be32 *p;
  147. p = xdr_inline_decode(xdr, 8);
  148. if (unlikely(p == NULL))
  149. goto out_overflow;
  150. xdr_decode_hyper(p, value);
  151. return 0;
  152. out_overflow:
  153. print_overflow_msg(__func__, xdr);
  154. return -EIO;
  155. }
  156. /*
  157. * fileid3
  158. *
  159. * typedef uint64 fileid3;
  160. */
  161. static __be32 *xdr_decode_fileid3(__be32 *p, u64 *fileid)
  162. {
  163. return xdr_decode_hyper(p, fileid);
  164. }
  165. static int decode_fileid3(struct xdr_stream *xdr, u64 *fileid)
  166. {
  167. return decode_uint64(xdr, fileid);
  168. }
  169. /*
  170. * filename3
  171. *
  172. * typedef string filename3<>;
  173. */
  174. static void encode_filename3(struct xdr_stream *xdr,
  175. const char *name, u32 length)
  176. {
  177. __be32 *p;
  178. WARN_ON_ONCE(length > NFS3_MAXNAMLEN);
  179. p = xdr_reserve_space(xdr, 4 + length);
  180. xdr_encode_opaque(p, name, length);
  181. }
  182. static int decode_inline_filename3(struct xdr_stream *xdr,
  183. const char **name, u32 *length)
  184. {
  185. __be32 *p;
  186. u32 count;
  187. p = xdr_inline_decode(xdr, 4);
  188. if (unlikely(p == NULL))
  189. goto out_overflow;
  190. count = be32_to_cpup(p);
  191. if (count > NFS3_MAXNAMLEN)
  192. goto out_nametoolong;
  193. p = xdr_inline_decode(xdr, count);
  194. if (unlikely(p == NULL))
  195. goto out_overflow;
  196. *name = (const char *)p;
  197. *length = count;
  198. return 0;
  199. out_nametoolong:
  200. dprintk("NFS: returned filename too long: %u\n", count);
  201. return -ENAMETOOLONG;
  202. out_overflow:
  203. print_overflow_msg(__func__, xdr);
  204. return -EIO;
  205. }
  206. /*
  207. * nfspath3
  208. *
  209. * typedef string nfspath3<>;
  210. */
  211. static void encode_nfspath3(struct xdr_stream *xdr, struct page **pages,
  212. const u32 length)
  213. {
  214. encode_uint32(xdr, length);
  215. xdr_write_pages(xdr, pages, 0, length);
  216. }
  217. static int decode_nfspath3(struct xdr_stream *xdr)
  218. {
  219. u32 recvd, count;
  220. __be32 *p;
  221. p = xdr_inline_decode(xdr, 4);
  222. if (unlikely(p == NULL))
  223. goto out_overflow;
  224. count = be32_to_cpup(p);
  225. if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN))
  226. goto out_nametoolong;
  227. recvd = xdr_read_pages(xdr, count);
  228. if (unlikely(count > recvd))
  229. goto out_cheating;
  230. xdr_terminate_string(xdr->buf, count);
  231. return 0;
  232. out_nametoolong:
  233. dprintk("NFS: returned pathname too long: %u\n", count);
  234. return -ENAMETOOLONG;
  235. out_cheating:
  236. dprintk("NFS: server cheating in pathname result: "
  237. "count %u > recvd %u\n", count, recvd);
  238. return -EIO;
  239. out_overflow:
  240. print_overflow_msg(__func__, xdr);
  241. return -EIO;
  242. }
  243. /*
  244. * cookie3
  245. *
  246. * typedef uint64 cookie3
  247. */
  248. static __be32 *xdr_encode_cookie3(__be32 *p, u64 cookie)
  249. {
  250. return xdr_encode_hyper(p, cookie);
  251. }
  252. static int decode_cookie3(struct xdr_stream *xdr, u64 *cookie)
  253. {
  254. return decode_uint64(xdr, cookie);
  255. }
  256. /*
  257. * cookieverf3
  258. *
  259. * typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
  260. */
  261. static __be32 *xdr_encode_cookieverf3(__be32 *p, const __be32 *verifier)
  262. {
  263. memcpy(p, verifier, NFS3_COOKIEVERFSIZE);
  264. return p + XDR_QUADLEN(NFS3_COOKIEVERFSIZE);
  265. }
  266. static int decode_cookieverf3(struct xdr_stream *xdr, __be32 *verifier)
  267. {
  268. __be32 *p;
  269. p = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE);
  270. if (unlikely(p == NULL))
  271. goto out_overflow;
  272. memcpy(verifier, p, NFS3_COOKIEVERFSIZE);
  273. return 0;
  274. out_overflow:
  275. print_overflow_msg(__func__, xdr);
  276. return -EIO;
  277. }
  278. /*
  279. * createverf3
  280. *
  281. * typedef opaque createverf3[NFS3_CREATEVERFSIZE];
  282. */
  283. static void encode_createverf3(struct xdr_stream *xdr, const __be32 *verifier)
  284. {
  285. __be32 *p;
  286. p = xdr_reserve_space(xdr, NFS3_CREATEVERFSIZE);
  287. memcpy(p, verifier, NFS3_CREATEVERFSIZE);
  288. }
  289. static int decode_writeverf3(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
  290. {
  291. __be32 *p;
  292. p = xdr_inline_decode(xdr, NFS3_WRITEVERFSIZE);
  293. if (unlikely(p == NULL))
  294. goto out_overflow;
  295. memcpy(verifier->data, p, NFS3_WRITEVERFSIZE);
  296. return 0;
  297. out_overflow:
  298. print_overflow_msg(__func__, xdr);
  299. return -EIO;
  300. }
  301. /*
  302. * size3
  303. *
  304. * typedef uint64 size3;
  305. */
  306. static __be32 *xdr_decode_size3(__be32 *p, u64 *size)
  307. {
  308. return xdr_decode_hyper(p, size);
  309. }
  310. /*
  311. * nfsstat3
  312. *
  313. * enum nfsstat3 {
  314. * NFS3_OK = 0,
  315. * ...
  316. * }
  317. */
  318. #define NFS3_OK NFS_OK
  319. static int decode_nfsstat3(struct xdr_stream *xdr, enum nfs_stat *status)
  320. {
  321. __be32 *p;
  322. p = xdr_inline_decode(xdr, 4);
  323. if (unlikely(p == NULL))
  324. goto out_overflow;
  325. *status = be32_to_cpup(p);
  326. return 0;
  327. out_overflow:
  328. print_overflow_msg(__func__, xdr);
  329. return -EIO;
  330. }
  331. /*
  332. * ftype3
  333. *
  334. * enum ftype3 {
  335. * NF3REG = 1,
  336. * NF3DIR = 2,
  337. * NF3BLK = 3,
  338. * NF3CHR = 4,
  339. * NF3LNK = 5,
  340. * NF3SOCK = 6,
  341. * NF3FIFO = 7
  342. * };
  343. */
  344. static void encode_ftype3(struct xdr_stream *xdr, const u32 type)
  345. {
  346. encode_uint32(xdr, type);
  347. }
  348. static __be32 *xdr_decode_ftype3(__be32 *p, umode_t *mode)
  349. {
  350. u32 type;
  351. type = be32_to_cpup(p++);
  352. if (type > NF3FIFO)
  353. type = NF3NON;
  354. *mode = nfs_type2fmt[type];
  355. return p;
  356. }
  357. /*
  358. * specdata3
  359. *
  360. * struct specdata3 {
  361. * uint32 specdata1;
  362. * uint32 specdata2;
  363. * };
  364. */
  365. static void encode_specdata3(struct xdr_stream *xdr, const dev_t rdev)
  366. {
  367. __be32 *p;
  368. p = xdr_reserve_space(xdr, 8);
  369. *p++ = cpu_to_be32(MAJOR(rdev));
  370. *p = cpu_to_be32(MINOR(rdev));
  371. }
  372. static __be32 *xdr_decode_specdata3(__be32 *p, dev_t *rdev)
  373. {
  374. unsigned int major, minor;
  375. major = be32_to_cpup(p++);
  376. minor = be32_to_cpup(p++);
  377. *rdev = MKDEV(major, minor);
  378. if (MAJOR(*rdev) != major || MINOR(*rdev) != minor)
  379. *rdev = 0;
  380. return p;
  381. }
  382. /*
  383. * nfs_fh3
  384. *
  385. * struct nfs_fh3 {
  386. * opaque data<NFS3_FHSIZE>;
  387. * };
  388. */
  389. static void encode_nfs_fh3(struct xdr_stream *xdr, const struct nfs_fh *fh)
  390. {
  391. __be32 *p;
  392. WARN_ON_ONCE(fh->size > NFS3_FHSIZE);
  393. p = xdr_reserve_space(xdr, 4 + fh->size);
  394. xdr_encode_opaque(p, fh->data, fh->size);
  395. }
  396. static int decode_nfs_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
  397. {
  398. u32 length;
  399. __be32 *p;
  400. p = xdr_inline_decode(xdr, 4);
  401. if (unlikely(p == NULL))
  402. goto out_overflow;
  403. length = be32_to_cpup(p++);
  404. if (unlikely(length > NFS3_FHSIZE))
  405. goto out_toobig;
  406. p = xdr_inline_decode(xdr, length);
  407. if (unlikely(p == NULL))
  408. goto out_overflow;
  409. fh->size = length;
  410. memcpy(fh->data, p, length);
  411. return 0;
  412. out_toobig:
  413. dprintk("NFS: file handle size (%u) too big\n", length);
  414. return -E2BIG;
  415. out_overflow:
  416. print_overflow_msg(__func__, xdr);
  417. return -EIO;
  418. }
  419. static void zero_nfs_fh3(struct nfs_fh *fh)
  420. {
  421. memset(fh, 0, sizeof(*fh));
  422. }
  423. /*
  424. * nfstime3
  425. *
  426. * struct nfstime3 {
  427. * uint32 seconds;
  428. * uint32 nseconds;
  429. * };
  430. */
  431. static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec *timep)
  432. {
  433. *p++ = cpu_to_be32(timep->tv_sec);
  434. *p++ = cpu_to_be32(timep->tv_nsec);
  435. return p;
  436. }
  437. static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec *timep)
  438. {
  439. timep->tv_sec = be32_to_cpup(p++);
  440. timep->tv_nsec = be32_to_cpup(p++);
  441. return p;
  442. }
  443. /*
  444. * sattr3
  445. *
  446. * enum time_how {
  447. * DONT_CHANGE = 0,
  448. * SET_TO_SERVER_TIME = 1,
  449. * SET_TO_CLIENT_TIME = 2
  450. * };
  451. *
  452. * union set_mode3 switch (bool set_it) {
  453. * case TRUE:
  454. * mode3 mode;
  455. * default:
  456. * void;
  457. * };
  458. *
  459. * union set_uid3 switch (bool set_it) {
  460. * case TRUE:
  461. * uid3 uid;
  462. * default:
  463. * void;
  464. * };
  465. *
  466. * union set_gid3 switch (bool set_it) {
  467. * case TRUE:
  468. * gid3 gid;
  469. * default:
  470. * void;
  471. * };
  472. *
  473. * union set_size3 switch (bool set_it) {
  474. * case TRUE:
  475. * size3 size;
  476. * default:
  477. * void;
  478. * };
  479. *
  480. * union set_atime switch (time_how set_it) {
  481. * case SET_TO_CLIENT_TIME:
  482. * nfstime3 atime;
  483. * default:
  484. * void;
  485. * };
  486. *
  487. * union set_mtime switch (time_how set_it) {
  488. * case SET_TO_CLIENT_TIME:
  489. * nfstime3 mtime;
  490. * default:
  491. * void;
  492. * };
  493. *
  494. * struct sattr3 {
  495. * set_mode3 mode;
  496. * set_uid3 uid;
  497. * set_gid3 gid;
  498. * set_size3 size;
  499. * set_atime atime;
  500. * set_mtime mtime;
  501. * };
  502. */
  503. static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
  504. {
  505. u32 nbytes;
  506. __be32 *p;
  507. /*
  508. * In order to make only a single xdr_reserve_space() call,
  509. * pre-compute the total number of bytes to be reserved.
  510. * Six boolean values, one for each set_foo field, are always
  511. * present in the encoded result, so start there.
  512. */
  513. nbytes = 6 * 4;
  514. if (attr->ia_valid & ATTR_MODE)
  515. nbytes += 4;
  516. if (attr->ia_valid & ATTR_UID)
  517. nbytes += 4;
  518. if (attr->ia_valid & ATTR_GID)
  519. nbytes += 4;
  520. if (attr->ia_valid & ATTR_SIZE)
  521. nbytes += 8;
  522. if (attr->ia_valid & ATTR_ATIME_SET)
  523. nbytes += 8;
  524. if (attr->ia_valid & ATTR_MTIME_SET)
  525. nbytes += 8;
  526. p = xdr_reserve_space(xdr, nbytes);
  527. if (attr->ia_valid & ATTR_MODE) {
  528. *p++ = xdr_one;
  529. *p++ = cpu_to_be32(attr->ia_mode & S_IALLUGO);
  530. } else
  531. *p++ = xdr_zero;
  532. if (attr->ia_valid & ATTR_UID) {
  533. *p++ = xdr_one;
  534. *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
  535. } else
  536. *p++ = xdr_zero;
  537. if (attr->ia_valid & ATTR_GID) {
  538. *p++ = xdr_one;
  539. *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
  540. } else
  541. *p++ = xdr_zero;
  542. if (attr->ia_valid & ATTR_SIZE) {
  543. *p++ = xdr_one;
  544. p = xdr_encode_hyper(p, (u64)attr->ia_size);
  545. } else
  546. *p++ = xdr_zero;
  547. if (attr->ia_valid & ATTR_ATIME_SET) {
  548. *p++ = xdr_two;
  549. p = xdr_encode_nfstime3(p, &attr->ia_atime);
  550. } else if (attr->ia_valid & ATTR_ATIME) {
  551. *p++ = xdr_one;
  552. } else
  553. *p++ = xdr_zero;
  554. if (attr->ia_valid & ATTR_MTIME_SET) {
  555. *p++ = xdr_two;
  556. xdr_encode_nfstime3(p, &attr->ia_mtime);
  557. } else if (attr->ia_valid & ATTR_MTIME) {
  558. *p = xdr_one;
  559. } else
  560. *p = xdr_zero;
  561. }
  562. /*
  563. * fattr3
  564. *
  565. * struct fattr3 {
  566. * ftype3 type;
  567. * mode3 mode;
  568. * uint32 nlink;
  569. * uid3 uid;
  570. * gid3 gid;
  571. * size3 size;
  572. * size3 used;
  573. * specdata3 rdev;
  574. * uint64 fsid;
  575. * fileid3 fileid;
  576. * nfstime3 atime;
  577. * nfstime3 mtime;
  578. * nfstime3 ctime;
  579. * };
  580. */
  581. static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr)
  582. {
  583. umode_t fmode;
  584. __be32 *p;
  585. p = xdr_inline_decode(xdr, NFS3_fattr_sz << 2);
  586. if (unlikely(p == NULL))
  587. goto out_overflow;
  588. p = xdr_decode_ftype3(p, &fmode);
  589. fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode;
  590. fattr->nlink = be32_to_cpup(p++);
  591. fattr->uid = make_kuid(&init_user_ns, be32_to_cpup(p++));
  592. if (!uid_valid(fattr->uid))
  593. goto out_uid;
  594. fattr->gid = make_kgid(&init_user_ns, be32_to_cpup(p++));
  595. if (!gid_valid(fattr->gid))
  596. goto out_gid;
  597. p = xdr_decode_size3(p, &fattr->size);
  598. p = xdr_decode_size3(p, &fattr->du.nfs3.used);
  599. p = xdr_decode_specdata3(p, &fattr->rdev);
  600. p = xdr_decode_hyper(p, &fattr->fsid.major);
  601. fattr->fsid.minor = 0;
  602. p = xdr_decode_fileid3(p, &fattr->fileid);
  603. p = xdr_decode_nfstime3(p, &fattr->atime);
  604. p = xdr_decode_nfstime3(p, &fattr->mtime);
  605. xdr_decode_nfstime3(p, &fattr->ctime);
  606. fattr->change_attr = nfs_timespec_to_change_attr(&fattr->ctime);
  607. fattr->valid |= NFS_ATTR_FATTR_V3;
  608. return 0;
  609. out_uid:
  610. dprintk("NFS: returned invalid uid\n");
  611. return -EINVAL;
  612. out_gid:
  613. dprintk("NFS: returned invalid gid\n");
  614. return -EINVAL;
  615. out_overflow:
  616. print_overflow_msg(__func__, xdr);
  617. return -EIO;
  618. }
  619. /*
  620. * post_op_attr
  621. *
  622. * union post_op_attr switch (bool attributes_follow) {
  623. * case TRUE:
  624. * fattr3 attributes;
  625. * case FALSE:
  626. * void;
  627. * };
  628. */
  629. static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
  630. {
  631. __be32 *p;
  632. p = xdr_inline_decode(xdr, 4);
  633. if (unlikely(p == NULL))
  634. goto out_overflow;
  635. if (*p != xdr_zero)
  636. return decode_fattr3(xdr, fattr);
  637. return 0;
  638. out_overflow:
  639. print_overflow_msg(__func__, xdr);
  640. return -EIO;
  641. }
  642. /*
  643. * wcc_attr
  644. * struct wcc_attr {
  645. * size3 size;
  646. * nfstime3 mtime;
  647. * nfstime3 ctime;
  648. * };
  649. */
  650. static int decode_wcc_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
  651. {
  652. __be32 *p;
  653. p = xdr_inline_decode(xdr, NFS3_wcc_attr_sz << 2);
  654. if (unlikely(p == NULL))
  655. goto out_overflow;
  656. fattr->valid |= NFS_ATTR_FATTR_PRESIZE
  657. | NFS_ATTR_FATTR_PRECHANGE
  658. | NFS_ATTR_FATTR_PREMTIME
  659. | NFS_ATTR_FATTR_PRECTIME;
  660. p = xdr_decode_size3(p, &fattr->pre_size);
  661. p = xdr_decode_nfstime3(p, &fattr->pre_mtime);
  662. xdr_decode_nfstime3(p, &fattr->pre_ctime);
  663. fattr->pre_change_attr = nfs_timespec_to_change_attr(&fattr->pre_ctime);
  664. return 0;
  665. out_overflow:
  666. print_overflow_msg(__func__, xdr);
  667. return -EIO;
  668. }
  669. /*
  670. * pre_op_attr
  671. * union pre_op_attr switch (bool attributes_follow) {
  672. * case TRUE:
  673. * wcc_attr attributes;
  674. * case FALSE:
  675. * void;
  676. * };
  677. *
  678. * wcc_data
  679. *
  680. * struct wcc_data {
  681. * pre_op_attr before;
  682. * post_op_attr after;
  683. * };
  684. */
  685. static int decode_pre_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
  686. {
  687. __be32 *p;
  688. p = xdr_inline_decode(xdr, 4);
  689. if (unlikely(p == NULL))
  690. goto out_overflow;
  691. if (*p != xdr_zero)
  692. return decode_wcc_attr(xdr, fattr);
  693. return 0;
  694. out_overflow:
  695. print_overflow_msg(__func__, xdr);
  696. return -EIO;
  697. }
  698. static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr)
  699. {
  700. int error;
  701. error = decode_pre_op_attr(xdr, fattr);
  702. if (unlikely(error))
  703. goto out;
  704. error = decode_post_op_attr(xdr, fattr);
  705. out:
  706. return error;
  707. }
  708. /*
  709. * post_op_fh3
  710. *
  711. * union post_op_fh3 switch (bool handle_follows) {
  712. * case TRUE:
  713. * nfs_fh3 handle;
  714. * case FALSE:
  715. * void;
  716. * };
  717. */
  718. static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
  719. {
  720. __be32 *p = xdr_inline_decode(xdr, 4);
  721. if (unlikely(p == NULL))
  722. goto out_overflow;
  723. if (*p != xdr_zero)
  724. return decode_nfs_fh3(xdr, fh);
  725. zero_nfs_fh3(fh);
  726. return 0;
  727. out_overflow:
  728. print_overflow_msg(__func__, xdr);
  729. return -EIO;
  730. }
  731. /*
  732. * diropargs3
  733. *
  734. * struct diropargs3 {
  735. * nfs_fh3 dir;
  736. * filename3 name;
  737. * };
  738. */
  739. static void encode_diropargs3(struct xdr_stream *xdr, const struct nfs_fh *fh,
  740. const char *name, u32 length)
  741. {
  742. encode_nfs_fh3(xdr, fh);
  743. encode_filename3(xdr, name, length);
  744. }
  745. /*
  746. * NFSv3 XDR encode functions
  747. *
  748. * NFSv3 argument types are defined in section 3.3 of RFC 1813:
  749. * "NFS Version 3 Protocol Specification".
  750. */
  751. /*
  752. * 3.3.1 GETATTR3args
  753. *
  754. * struct GETATTR3args {
  755. * nfs_fh3 object;
  756. * };
  757. */
  758. static void nfs3_xdr_enc_getattr3args(struct rpc_rqst *req,
  759. struct xdr_stream *xdr,
  760. const void *data)
  761. {
  762. const struct nfs_fh *fh = data;
  763. encode_nfs_fh3(xdr, fh);
  764. }
  765. /*
  766. * 3.3.2 SETATTR3args
  767. *
  768. * union sattrguard3 switch (bool check) {
  769. * case TRUE:
  770. * nfstime3 obj_ctime;
  771. * case FALSE:
  772. * void;
  773. * };
  774. *
  775. * struct SETATTR3args {
  776. * nfs_fh3 object;
  777. * sattr3 new_attributes;
  778. * sattrguard3 guard;
  779. * };
  780. */
  781. static void encode_sattrguard3(struct xdr_stream *xdr,
  782. const struct nfs3_sattrargs *args)
  783. {
  784. __be32 *p;
  785. if (args->guard) {
  786. p = xdr_reserve_space(xdr, 4 + 8);
  787. *p++ = xdr_one;
  788. xdr_encode_nfstime3(p, &args->guardtime);
  789. } else {
  790. p = xdr_reserve_space(xdr, 4);
  791. *p = xdr_zero;
  792. }
  793. }
  794. static void nfs3_xdr_enc_setattr3args(struct rpc_rqst *req,
  795. struct xdr_stream *xdr,
  796. const void *data)
  797. {
  798. const struct nfs3_sattrargs *args = data;
  799. encode_nfs_fh3(xdr, args->fh);
  800. encode_sattr3(xdr, args->sattr);
  801. encode_sattrguard3(xdr, args);
  802. }
  803. /*
  804. * 3.3.3 LOOKUP3args
  805. *
  806. * struct LOOKUP3args {
  807. * diropargs3 what;
  808. * };
  809. */
  810. static void nfs3_xdr_enc_lookup3args(struct rpc_rqst *req,
  811. struct xdr_stream *xdr,
  812. const void *data)
  813. {
  814. const struct nfs3_diropargs *args = data;
  815. encode_diropargs3(xdr, args->fh, args->name, args->len);
  816. }
  817. /*
  818. * 3.3.4 ACCESS3args
  819. *
  820. * struct ACCESS3args {
  821. * nfs_fh3 object;
  822. * uint32 access;
  823. * };
  824. */
  825. static void encode_access3args(struct xdr_stream *xdr,
  826. const struct nfs3_accessargs *args)
  827. {
  828. encode_nfs_fh3(xdr, args->fh);
  829. encode_uint32(xdr, args->access);
  830. }
  831. static void nfs3_xdr_enc_access3args(struct rpc_rqst *req,
  832. struct xdr_stream *xdr,
  833. const void *data)
  834. {
  835. const struct nfs3_accessargs *args = data;
  836. encode_access3args(xdr, args);
  837. }
  838. /*
  839. * 3.3.5 READLINK3args
  840. *
  841. * struct READLINK3args {
  842. * nfs_fh3 symlink;
  843. * };
  844. */
  845. static void nfs3_xdr_enc_readlink3args(struct rpc_rqst *req,
  846. struct xdr_stream *xdr,
  847. const void *data)
  848. {
  849. const struct nfs3_readlinkargs *args = data;
  850. encode_nfs_fh3(xdr, args->fh);
  851. prepare_reply_buffer(req, args->pages, args->pgbase,
  852. args->pglen, NFS3_readlinkres_sz);
  853. }
  854. /*
  855. * 3.3.6 READ3args
  856. *
  857. * struct READ3args {
  858. * nfs_fh3 file;
  859. * offset3 offset;
  860. * count3 count;
  861. * };
  862. */
  863. static void encode_read3args(struct xdr_stream *xdr,
  864. const struct nfs_pgio_args *args)
  865. {
  866. __be32 *p;
  867. encode_nfs_fh3(xdr, args->fh);
  868. p = xdr_reserve_space(xdr, 8 + 4);
  869. p = xdr_encode_hyper(p, args->offset);
  870. *p = cpu_to_be32(args->count);
  871. }
  872. static void nfs3_xdr_enc_read3args(struct rpc_rqst *req,
  873. struct xdr_stream *xdr,
  874. const void *data)
  875. {
  876. const struct nfs_pgio_args *args = data;
  877. encode_read3args(xdr, args);
  878. prepare_reply_buffer(req, args->pages, args->pgbase,
  879. args->count, NFS3_readres_sz);
  880. req->rq_rcv_buf.flags |= XDRBUF_READ;
  881. }
  882. /*
  883. * 3.3.7 WRITE3args
  884. *
  885. * enum stable_how {
  886. * UNSTABLE = 0,
  887. * DATA_SYNC = 1,
  888. * FILE_SYNC = 2
  889. * };
  890. *
  891. * struct WRITE3args {
  892. * nfs_fh3 file;
  893. * offset3 offset;
  894. * count3 count;
  895. * stable_how stable;
  896. * opaque data<>;
  897. * };
  898. */
  899. static void encode_write3args(struct xdr_stream *xdr,
  900. const struct nfs_pgio_args *args)
  901. {
  902. __be32 *p;
  903. encode_nfs_fh3(xdr, args->fh);
  904. p = xdr_reserve_space(xdr, 8 + 4 + 4 + 4);
  905. p = xdr_encode_hyper(p, args->offset);
  906. *p++ = cpu_to_be32(args->count);
  907. *p++ = cpu_to_be32(args->stable);
  908. *p = cpu_to_be32(args->count);
  909. xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
  910. }
  911. static void nfs3_xdr_enc_write3args(struct rpc_rqst *req,
  912. struct xdr_stream *xdr,
  913. const void *data)
  914. {
  915. const struct nfs_pgio_args *args = data;
  916. encode_write3args(xdr, args);
  917. xdr->buf->flags |= XDRBUF_WRITE;
  918. }
  919. /*
  920. * 3.3.8 CREATE3args
  921. *
  922. * enum createmode3 {
  923. * UNCHECKED = 0,
  924. * GUARDED = 1,
  925. * EXCLUSIVE = 2
  926. * };
  927. *
  928. * union createhow3 switch (createmode3 mode) {
  929. * case UNCHECKED:
  930. * case GUARDED:
  931. * sattr3 obj_attributes;
  932. * case EXCLUSIVE:
  933. * createverf3 verf;
  934. * };
  935. *
  936. * struct CREATE3args {
  937. * diropargs3 where;
  938. * createhow3 how;
  939. * };
  940. */
  941. static void encode_createhow3(struct xdr_stream *xdr,
  942. const struct nfs3_createargs *args)
  943. {
  944. encode_uint32(xdr, args->createmode);
  945. switch (args->createmode) {
  946. case NFS3_CREATE_UNCHECKED:
  947. case NFS3_CREATE_GUARDED:
  948. encode_sattr3(xdr, args->sattr);
  949. break;
  950. case NFS3_CREATE_EXCLUSIVE:
  951. encode_createverf3(xdr, args->verifier);
  952. break;
  953. default:
  954. BUG();
  955. }
  956. }
  957. static void nfs3_xdr_enc_create3args(struct rpc_rqst *req,
  958. struct xdr_stream *xdr,
  959. const void *data)
  960. {
  961. const struct nfs3_createargs *args = data;
  962. encode_diropargs3(xdr, args->fh, args->name, args->len);
  963. encode_createhow3(xdr, args);
  964. }
  965. /*
  966. * 3.3.9 MKDIR3args
  967. *
  968. * struct MKDIR3args {
  969. * diropargs3 where;
  970. * sattr3 attributes;
  971. * };
  972. */
  973. static void nfs3_xdr_enc_mkdir3args(struct rpc_rqst *req,
  974. struct xdr_stream *xdr,
  975. const void *data)
  976. {
  977. const struct nfs3_mkdirargs *args = data;
  978. encode_diropargs3(xdr, args->fh, args->name, args->len);
  979. encode_sattr3(xdr, args->sattr);
  980. }
  981. /*
  982. * 3.3.10 SYMLINK3args
  983. *
  984. * struct symlinkdata3 {
  985. * sattr3 symlink_attributes;
  986. * nfspath3 symlink_data;
  987. * };
  988. *
  989. * struct SYMLINK3args {
  990. * diropargs3 where;
  991. * symlinkdata3 symlink;
  992. * };
  993. */
  994. static void encode_symlinkdata3(struct xdr_stream *xdr,
  995. const void *data)
  996. {
  997. const struct nfs3_symlinkargs *args = data;
  998. encode_sattr3(xdr, args->sattr);
  999. encode_nfspath3(xdr, args->pages, args->pathlen);
  1000. }
  1001. static void nfs3_xdr_enc_symlink3args(struct rpc_rqst *req,
  1002. struct xdr_stream *xdr,
  1003. const void *data)
  1004. {
  1005. const struct nfs3_symlinkargs *args = data;
  1006. encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
  1007. encode_symlinkdata3(xdr, args);
  1008. xdr->buf->flags |= XDRBUF_WRITE;
  1009. }
  1010. /*
  1011. * 3.3.11 MKNOD3args
  1012. *
  1013. * struct devicedata3 {
  1014. * sattr3 dev_attributes;
  1015. * specdata3 spec;
  1016. * };
  1017. *
  1018. * union mknoddata3 switch (ftype3 type) {
  1019. * case NF3CHR:
  1020. * case NF3BLK:
  1021. * devicedata3 device;
  1022. * case NF3SOCK:
  1023. * case NF3FIFO:
  1024. * sattr3 pipe_attributes;
  1025. * default:
  1026. * void;
  1027. * };
  1028. *
  1029. * struct MKNOD3args {
  1030. * diropargs3 where;
  1031. * mknoddata3 what;
  1032. * };
  1033. */
  1034. static void encode_devicedata3(struct xdr_stream *xdr,
  1035. const struct nfs3_mknodargs *args)
  1036. {
  1037. encode_sattr3(xdr, args->sattr);
  1038. encode_specdata3(xdr, args->rdev);
  1039. }
  1040. static void encode_mknoddata3(struct xdr_stream *xdr,
  1041. const struct nfs3_mknodargs *args)
  1042. {
  1043. encode_ftype3(xdr, args->type);
  1044. switch (args->type) {
  1045. case NF3CHR:
  1046. case NF3BLK:
  1047. encode_devicedata3(xdr, args);
  1048. break;
  1049. case NF3SOCK:
  1050. case NF3FIFO:
  1051. encode_sattr3(xdr, args->sattr);
  1052. break;
  1053. case NF3REG:
  1054. case NF3DIR:
  1055. break;
  1056. default:
  1057. BUG();
  1058. }
  1059. }
  1060. static void nfs3_xdr_enc_mknod3args(struct rpc_rqst *req,
  1061. struct xdr_stream *xdr,
  1062. const void *data)
  1063. {
  1064. const struct nfs3_mknodargs *args = data;
  1065. encode_diropargs3(xdr, args->fh, args->name, args->len);
  1066. encode_mknoddata3(xdr, args);
  1067. }
  1068. /*
  1069. * 3.3.12 REMOVE3args
  1070. *
  1071. * struct REMOVE3args {
  1072. * diropargs3 object;
  1073. * };
  1074. */
  1075. static void nfs3_xdr_enc_remove3args(struct rpc_rqst *req,
  1076. struct xdr_stream *xdr,
  1077. const void *data)
  1078. {
  1079. const struct nfs_removeargs *args = data;
  1080. encode_diropargs3(xdr, args->fh, args->name.name, args->name.len);
  1081. }
  1082. /*
  1083. * 3.3.14 RENAME3args
  1084. *
  1085. * struct RENAME3args {
  1086. * diropargs3 from;
  1087. * diropargs3 to;
  1088. * };
  1089. */
  1090. static void nfs3_xdr_enc_rename3args(struct rpc_rqst *req,
  1091. struct xdr_stream *xdr,
  1092. const void *data)
  1093. {
  1094. const struct nfs_renameargs *args = data;
  1095. const struct qstr *old = args->old_name;
  1096. const struct qstr *new = args->new_name;
  1097. encode_diropargs3(xdr, args->old_dir, old->name, old->len);
  1098. encode_diropargs3(xdr, args->new_dir, new->name, new->len);
  1099. }
  1100. /*
  1101. * 3.3.15 LINK3args
  1102. *
  1103. * struct LINK3args {
  1104. * nfs_fh3 file;
  1105. * diropargs3 link;
  1106. * };
  1107. */
  1108. static void nfs3_xdr_enc_link3args(struct rpc_rqst *req,
  1109. struct xdr_stream *xdr,
  1110. const void *data)
  1111. {
  1112. const struct nfs3_linkargs *args = data;
  1113. encode_nfs_fh3(xdr, args->fromfh);
  1114. encode_diropargs3(xdr, args->tofh, args->toname, args->tolen);
  1115. }
  1116. /*
  1117. * 3.3.16 READDIR3args
  1118. *
  1119. * struct READDIR3args {
  1120. * nfs_fh3 dir;
  1121. * cookie3 cookie;
  1122. * cookieverf3 cookieverf;
  1123. * count3 count;
  1124. * };
  1125. */
  1126. static void encode_readdir3args(struct xdr_stream *xdr,
  1127. const struct nfs3_readdirargs *args)
  1128. {
  1129. __be32 *p;
  1130. encode_nfs_fh3(xdr, args->fh);
  1131. p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4);
  1132. p = xdr_encode_cookie3(p, args->cookie);
  1133. p = xdr_encode_cookieverf3(p, args->verf);
  1134. *p = cpu_to_be32(args->count);
  1135. }
  1136. static void nfs3_xdr_enc_readdir3args(struct rpc_rqst *req,
  1137. struct xdr_stream *xdr,
  1138. const void *data)
  1139. {
  1140. const struct nfs3_readdirargs *args = data;
  1141. encode_readdir3args(xdr, args);
  1142. prepare_reply_buffer(req, args->pages, 0,
  1143. args->count, NFS3_readdirres_sz);
  1144. }
  1145. /*
  1146. * 3.3.17 READDIRPLUS3args
  1147. *
  1148. * struct READDIRPLUS3args {
  1149. * nfs_fh3 dir;
  1150. * cookie3 cookie;
  1151. * cookieverf3 cookieverf;
  1152. * count3 dircount;
  1153. * count3 maxcount;
  1154. * };
  1155. */
  1156. static void encode_readdirplus3args(struct xdr_stream *xdr,
  1157. const struct nfs3_readdirargs *args)
  1158. {
  1159. __be32 *p;
  1160. encode_nfs_fh3(xdr, args->fh);
  1161. p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4 + 4);
  1162. p = xdr_encode_cookie3(p, args->cookie);
  1163. p = xdr_encode_cookieverf3(p, args->verf);
  1164. /*
  1165. * readdirplus: need dircount + buffer size.
  1166. * We just make sure we make dircount big enough
  1167. */
  1168. *p++ = cpu_to_be32(args->count >> 3);
  1169. *p = cpu_to_be32(args->count);
  1170. }
  1171. static void nfs3_xdr_enc_readdirplus3args(struct rpc_rqst *req,
  1172. struct xdr_stream *xdr,
  1173. const void *data)
  1174. {
  1175. const struct nfs3_readdirargs *args = data;
  1176. encode_readdirplus3args(xdr, args);
  1177. prepare_reply_buffer(req, args->pages, 0,
  1178. args->count, NFS3_readdirres_sz);
  1179. }
  1180. /*
  1181. * 3.3.21 COMMIT3args
  1182. *
  1183. * struct COMMIT3args {
  1184. * nfs_fh3 file;
  1185. * offset3 offset;
  1186. * count3 count;
  1187. * };
  1188. */
  1189. static void encode_commit3args(struct xdr_stream *xdr,
  1190. const struct nfs_commitargs *args)
  1191. {
  1192. __be32 *p;
  1193. encode_nfs_fh3(xdr, args->fh);
  1194. p = xdr_reserve_space(xdr, 8 + 4);
  1195. p = xdr_encode_hyper(p, args->offset);
  1196. *p = cpu_to_be32(args->count);
  1197. }
  1198. static void nfs3_xdr_enc_commit3args(struct rpc_rqst *req,
  1199. struct xdr_stream *xdr,
  1200. const void *data)
  1201. {
  1202. const struct nfs_commitargs *args = data;
  1203. encode_commit3args(xdr, args);
  1204. }
  1205. #ifdef CONFIG_NFS_V3_ACL
  1206. static void nfs3_xdr_enc_getacl3args(struct rpc_rqst *req,
  1207. struct xdr_stream *xdr,
  1208. const void *data)
  1209. {
  1210. const struct nfs3_getaclargs *args = data;
  1211. encode_nfs_fh3(xdr, args->fh);
  1212. encode_uint32(xdr, args->mask);
  1213. if (args->mask & (NFS_ACL | NFS_DFACL))
  1214. prepare_reply_buffer(req, args->pages, 0,
  1215. NFSACL_MAXPAGES << PAGE_SHIFT,
  1216. ACL3_getaclres_sz);
  1217. }
  1218. static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req,
  1219. struct xdr_stream *xdr,
  1220. const void *data)
  1221. {
  1222. const struct nfs3_setaclargs *args = data;
  1223. unsigned int base;
  1224. int error;
  1225. encode_nfs_fh3(xdr, NFS_FH(args->inode));
  1226. encode_uint32(xdr, args->mask);
  1227. base = req->rq_slen;
  1228. if (args->npages != 0)
  1229. xdr_write_pages(xdr, args->pages, 0, args->len);
  1230. else
  1231. xdr_reserve_space(xdr, args->len);
  1232. error = nfsacl_encode(xdr->buf, base, args->inode,
  1233. (args->mask & NFS_ACL) ?
  1234. args->acl_access : NULL, 1, 0);
  1235. /* FIXME: this is just broken */
  1236. BUG_ON(error < 0);
  1237. error = nfsacl_encode(xdr->buf, base + error, args->inode,
  1238. (args->mask & NFS_DFACL) ?
  1239. args->acl_default : NULL, 1,
  1240. NFS_ACL_DEFAULT);
  1241. BUG_ON(error < 0);
  1242. }
  1243. #endif /* CONFIG_NFS_V3_ACL */
  1244. /*
  1245. * NFSv3 XDR decode functions
  1246. *
  1247. * NFSv3 result types are defined in section 3.3 of RFC 1813:
  1248. * "NFS Version 3 Protocol Specification".
  1249. */
  1250. /*
  1251. * 3.3.1 GETATTR3res
  1252. *
  1253. * struct GETATTR3resok {
  1254. * fattr3 obj_attributes;
  1255. * };
  1256. *
  1257. * union GETATTR3res switch (nfsstat3 status) {
  1258. * case NFS3_OK:
  1259. * GETATTR3resok resok;
  1260. * default:
  1261. * void;
  1262. * };
  1263. */
  1264. static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
  1265. struct xdr_stream *xdr,
  1266. void *result)
  1267. {
  1268. enum nfs_stat status;
  1269. int error;
  1270. error = decode_nfsstat3(xdr, &status);
  1271. if (unlikely(error))
  1272. goto out;
  1273. if (status != NFS3_OK)
  1274. goto out_default;
  1275. error = decode_fattr3(xdr, result);
  1276. out:
  1277. return error;
  1278. out_default:
  1279. return nfs3_stat_to_errno(status);
  1280. }
  1281. /*
  1282. * 3.3.2 SETATTR3res
  1283. *
  1284. * struct SETATTR3resok {
  1285. * wcc_data obj_wcc;
  1286. * };
  1287. *
  1288. * struct SETATTR3resfail {
  1289. * wcc_data obj_wcc;
  1290. * };
  1291. *
  1292. * union SETATTR3res switch (nfsstat3 status) {
  1293. * case NFS3_OK:
  1294. * SETATTR3resok resok;
  1295. * default:
  1296. * SETATTR3resfail resfail;
  1297. * };
  1298. */
  1299. static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
  1300. struct xdr_stream *xdr,
  1301. void *result)
  1302. {
  1303. enum nfs_stat status;
  1304. int error;
  1305. error = decode_nfsstat3(xdr, &status);
  1306. if (unlikely(error))
  1307. goto out;
  1308. error = decode_wcc_data(xdr, result);
  1309. if (unlikely(error))
  1310. goto out;
  1311. if (status != NFS3_OK)
  1312. goto out_status;
  1313. out:
  1314. return error;
  1315. out_status:
  1316. return nfs3_stat_to_errno(status);
  1317. }
  1318. /*
  1319. * 3.3.3 LOOKUP3res
  1320. *
  1321. * struct LOOKUP3resok {
  1322. * nfs_fh3 object;
  1323. * post_op_attr obj_attributes;
  1324. * post_op_attr dir_attributes;
  1325. * };
  1326. *
  1327. * struct LOOKUP3resfail {
  1328. * post_op_attr dir_attributes;
  1329. * };
  1330. *
  1331. * union LOOKUP3res switch (nfsstat3 status) {
  1332. * case NFS3_OK:
  1333. * LOOKUP3resok resok;
  1334. * default:
  1335. * LOOKUP3resfail resfail;
  1336. * };
  1337. */
  1338. static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req,
  1339. struct xdr_stream *xdr,
  1340. void *data)
  1341. {
  1342. struct nfs3_diropres *result = data;
  1343. enum nfs_stat status;
  1344. int error;
  1345. error = decode_nfsstat3(xdr, &status);
  1346. if (unlikely(error))
  1347. goto out;
  1348. if (status != NFS3_OK)
  1349. goto out_default;
  1350. error = decode_nfs_fh3(xdr, result->fh);
  1351. if (unlikely(error))
  1352. goto out;
  1353. error = decode_post_op_attr(xdr, result->fattr);
  1354. if (unlikely(error))
  1355. goto out;
  1356. error = decode_post_op_attr(xdr, result->dir_attr);
  1357. out:
  1358. return error;
  1359. out_default:
  1360. error = decode_post_op_attr(xdr, result->dir_attr);
  1361. if (unlikely(error))
  1362. goto out;
  1363. return nfs3_stat_to_errno(status);
  1364. }
  1365. /*
  1366. * 3.3.4 ACCESS3res
  1367. *
  1368. * struct ACCESS3resok {
  1369. * post_op_attr obj_attributes;
  1370. * uint32 access;
  1371. * };
  1372. *
  1373. * struct ACCESS3resfail {
  1374. * post_op_attr obj_attributes;
  1375. * };
  1376. *
  1377. * union ACCESS3res switch (nfsstat3 status) {
  1378. * case NFS3_OK:
  1379. * ACCESS3resok resok;
  1380. * default:
  1381. * ACCESS3resfail resfail;
  1382. * };
  1383. */
  1384. static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
  1385. struct xdr_stream *xdr,
  1386. void *data)
  1387. {
  1388. struct nfs3_accessres *result = data;
  1389. enum nfs_stat status;
  1390. int error;
  1391. error = decode_nfsstat3(xdr, &status);
  1392. if (unlikely(error))
  1393. goto out;
  1394. error = decode_post_op_attr(xdr, result->fattr);
  1395. if (unlikely(error))
  1396. goto out;
  1397. if (status != NFS3_OK)
  1398. goto out_default;
  1399. error = decode_uint32(xdr, &result->access);
  1400. out:
  1401. return error;
  1402. out_default:
  1403. return nfs3_stat_to_errno(status);
  1404. }
  1405. /*
  1406. * 3.3.5 READLINK3res
  1407. *
  1408. * struct READLINK3resok {
  1409. * post_op_attr symlink_attributes;
  1410. * nfspath3 data;
  1411. * };
  1412. *
  1413. * struct READLINK3resfail {
  1414. * post_op_attr symlink_attributes;
  1415. * };
  1416. *
  1417. * union READLINK3res switch (nfsstat3 status) {
  1418. * case NFS3_OK:
  1419. * READLINK3resok resok;
  1420. * default:
  1421. * READLINK3resfail resfail;
  1422. * };
  1423. */
  1424. static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
  1425. struct xdr_stream *xdr,
  1426. void *result)
  1427. {
  1428. enum nfs_stat status;
  1429. int error;
  1430. error = decode_nfsstat3(xdr, &status);
  1431. if (unlikely(error))
  1432. goto out;
  1433. error = decode_post_op_attr(xdr, result);
  1434. if (unlikely(error))
  1435. goto out;
  1436. if (status != NFS3_OK)
  1437. goto out_default;
  1438. error = decode_nfspath3(xdr);
  1439. out:
  1440. return error;
  1441. out_default:
  1442. return nfs3_stat_to_errno(status);
  1443. }
  1444. /*
  1445. * 3.3.6 READ3res
  1446. *
  1447. * struct READ3resok {
  1448. * post_op_attr file_attributes;
  1449. * count3 count;
  1450. * bool eof;
  1451. * opaque data<>;
  1452. * };
  1453. *
  1454. * struct READ3resfail {
  1455. * post_op_attr file_attributes;
  1456. * };
  1457. *
  1458. * union READ3res switch (nfsstat3 status) {
  1459. * case NFS3_OK:
  1460. * READ3resok resok;
  1461. * default:
  1462. * READ3resfail resfail;
  1463. * };
  1464. */
  1465. static int decode_read3resok(struct xdr_stream *xdr,
  1466. struct nfs_pgio_res *result)
  1467. {
  1468. u32 eof, count, ocount, recvd;
  1469. __be32 *p;
  1470. p = xdr_inline_decode(xdr, 4 + 4 + 4);
  1471. if (unlikely(p == NULL))
  1472. goto out_overflow;
  1473. count = be32_to_cpup(p++);
  1474. eof = be32_to_cpup(p++);
  1475. ocount = be32_to_cpup(p++);
  1476. if (unlikely(ocount != count))
  1477. goto out_mismatch;
  1478. recvd = xdr_read_pages(xdr, count);
  1479. if (unlikely(count > recvd))
  1480. goto out_cheating;
  1481. out:
  1482. result->eof = eof;
  1483. result->count = count;
  1484. return count;
  1485. out_mismatch:
  1486. dprintk("NFS: READ count doesn't match length of opaque: "
  1487. "count %u != ocount %u\n", count, ocount);
  1488. return -EIO;
  1489. out_cheating:
  1490. dprintk("NFS: server cheating in read result: "
  1491. "count %u > recvd %u\n", count, recvd);
  1492. count = recvd;
  1493. eof = 0;
  1494. goto out;
  1495. out_overflow:
  1496. print_overflow_msg(__func__, xdr);
  1497. return -EIO;
  1498. }
  1499. static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
  1500. void *data)
  1501. {
  1502. struct nfs_pgio_res *result = data;
  1503. enum nfs_stat status;
  1504. int error;
  1505. error = decode_nfsstat3(xdr, &status);
  1506. if (unlikely(error))
  1507. goto out;
  1508. error = decode_post_op_attr(xdr, result->fattr);
  1509. if (unlikely(error))
  1510. goto out;
  1511. result->op_status = status;
  1512. if (status != NFS3_OK)
  1513. goto out_status;
  1514. error = decode_read3resok(xdr, result);
  1515. out:
  1516. return error;
  1517. out_status:
  1518. return nfs3_stat_to_errno(status);
  1519. }
  1520. /*
  1521. * 3.3.7 WRITE3res
  1522. *
  1523. * enum stable_how {
  1524. * UNSTABLE = 0,
  1525. * DATA_SYNC = 1,
  1526. * FILE_SYNC = 2
  1527. * };
  1528. *
  1529. * struct WRITE3resok {
  1530. * wcc_data file_wcc;
  1531. * count3 count;
  1532. * stable_how committed;
  1533. * writeverf3 verf;
  1534. * };
  1535. *
  1536. * struct WRITE3resfail {
  1537. * wcc_data file_wcc;
  1538. * };
  1539. *
  1540. * union WRITE3res switch (nfsstat3 status) {
  1541. * case NFS3_OK:
  1542. * WRITE3resok resok;
  1543. * default:
  1544. * WRITE3resfail resfail;
  1545. * };
  1546. */
  1547. static int decode_write3resok(struct xdr_stream *xdr,
  1548. struct nfs_pgio_res *result)
  1549. {
  1550. __be32 *p;
  1551. p = xdr_inline_decode(xdr, 4 + 4);
  1552. if (unlikely(p == NULL))
  1553. goto out_overflow;
  1554. result->count = be32_to_cpup(p++);
  1555. result->verf->committed = be32_to_cpup(p++);
  1556. if (unlikely(result->verf->committed > NFS_FILE_SYNC))
  1557. goto out_badvalue;
  1558. if (decode_writeverf3(xdr, &result->verf->verifier))
  1559. goto out_eio;
  1560. return result->count;
  1561. out_badvalue:
  1562. dprintk("NFS: bad stable_how value: %u\n", result->verf->committed);
  1563. return -EIO;
  1564. out_overflow:
  1565. print_overflow_msg(__func__, xdr);
  1566. out_eio:
  1567. return -EIO;
  1568. }
  1569. static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
  1570. void *data)
  1571. {
  1572. struct nfs_pgio_res *result = data;
  1573. enum nfs_stat status;
  1574. int error;
  1575. error = decode_nfsstat3(xdr, &status);
  1576. if (unlikely(error))
  1577. goto out;
  1578. error = decode_wcc_data(xdr, result->fattr);
  1579. if (unlikely(error))
  1580. goto out;
  1581. result->op_status = status;
  1582. if (status != NFS3_OK)
  1583. goto out_status;
  1584. error = decode_write3resok(xdr, result);
  1585. out:
  1586. return error;
  1587. out_status:
  1588. return nfs3_stat_to_errno(status);
  1589. }
  1590. /*
  1591. * 3.3.8 CREATE3res
  1592. *
  1593. * struct CREATE3resok {
  1594. * post_op_fh3 obj;
  1595. * post_op_attr obj_attributes;
  1596. * wcc_data dir_wcc;
  1597. * };
  1598. *
  1599. * struct CREATE3resfail {
  1600. * wcc_data dir_wcc;
  1601. * };
  1602. *
  1603. * union CREATE3res switch (nfsstat3 status) {
  1604. * case NFS3_OK:
  1605. * CREATE3resok resok;
  1606. * default:
  1607. * CREATE3resfail resfail;
  1608. * };
  1609. */
  1610. static int decode_create3resok(struct xdr_stream *xdr,
  1611. struct nfs3_diropres *result)
  1612. {
  1613. int error;
  1614. error = decode_post_op_fh3(xdr, result->fh);
  1615. if (unlikely(error))
  1616. goto out;
  1617. error = decode_post_op_attr(xdr, result->fattr);
  1618. if (unlikely(error))
  1619. goto out;
  1620. /* The server isn't required to return a file handle.
  1621. * If it didn't, force the client to perform a LOOKUP
  1622. * to determine the correct file handle and attribute
  1623. * values for the new object. */
  1624. if (result->fh->size == 0)
  1625. result->fattr->valid = 0;
  1626. error = decode_wcc_data(xdr, result->dir_attr);
  1627. out:
  1628. return error;
  1629. }
  1630. static int nfs3_xdr_dec_create3res(struct rpc_rqst *req,
  1631. struct xdr_stream *xdr,
  1632. void *data)
  1633. {
  1634. struct nfs3_diropres *result = data;
  1635. enum nfs_stat status;
  1636. int error;
  1637. error = decode_nfsstat3(xdr, &status);
  1638. if (unlikely(error))
  1639. goto out;
  1640. if (status != NFS3_OK)
  1641. goto out_default;
  1642. error = decode_create3resok(xdr, result);
  1643. out:
  1644. return error;
  1645. out_default:
  1646. error = decode_wcc_data(xdr, result->dir_attr);
  1647. if (unlikely(error))
  1648. goto out;
  1649. return nfs3_stat_to_errno(status);
  1650. }
  1651. /*
  1652. * 3.3.12 REMOVE3res
  1653. *
  1654. * struct REMOVE3resok {
  1655. * wcc_data dir_wcc;
  1656. * };
  1657. *
  1658. * struct REMOVE3resfail {
  1659. * wcc_data dir_wcc;
  1660. * };
  1661. *
  1662. * union REMOVE3res switch (nfsstat3 status) {
  1663. * case NFS3_OK:
  1664. * REMOVE3resok resok;
  1665. * default:
  1666. * REMOVE3resfail resfail;
  1667. * };
  1668. */
  1669. static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
  1670. struct xdr_stream *xdr,
  1671. void *data)
  1672. {
  1673. struct nfs_removeres *result = data;
  1674. enum nfs_stat status;
  1675. int error;
  1676. error = decode_nfsstat3(xdr, &status);
  1677. if (unlikely(error))
  1678. goto out;
  1679. error = decode_wcc_data(xdr, result->dir_attr);
  1680. if (unlikely(error))
  1681. goto out;
  1682. if (status != NFS3_OK)
  1683. goto out_status;
  1684. out:
  1685. return error;
  1686. out_status:
  1687. return nfs3_stat_to_errno(status);
  1688. }
  1689. /*
  1690. * 3.3.14 RENAME3res
  1691. *
  1692. * struct RENAME3resok {
  1693. * wcc_data fromdir_wcc;
  1694. * wcc_data todir_wcc;
  1695. * };
  1696. *
  1697. * struct RENAME3resfail {
  1698. * wcc_data fromdir_wcc;
  1699. * wcc_data todir_wcc;
  1700. * };
  1701. *
  1702. * union RENAME3res switch (nfsstat3 status) {
  1703. * case NFS3_OK:
  1704. * RENAME3resok resok;
  1705. * default:
  1706. * RENAME3resfail resfail;
  1707. * };
  1708. */
  1709. static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
  1710. struct xdr_stream *xdr,
  1711. void *data)
  1712. {
  1713. struct nfs_renameres *result = data;
  1714. enum nfs_stat status;
  1715. int error;
  1716. error = decode_nfsstat3(xdr, &status);
  1717. if (unlikely(error))
  1718. goto out;
  1719. error = decode_wcc_data(xdr, result->old_fattr);
  1720. if (unlikely(error))
  1721. goto out;
  1722. error = decode_wcc_data(xdr, result->new_fattr);
  1723. if (unlikely(error))
  1724. goto out;
  1725. if (status != NFS3_OK)
  1726. goto out_status;
  1727. out:
  1728. return error;
  1729. out_status:
  1730. return nfs3_stat_to_errno(status);
  1731. }
  1732. /*
  1733. * 3.3.15 LINK3res
  1734. *
  1735. * struct LINK3resok {
  1736. * post_op_attr file_attributes;
  1737. * wcc_data linkdir_wcc;
  1738. * };
  1739. *
  1740. * struct LINK3resfail {
  1741. * post_op_attr file_attributes;
  1742. * wcc_data linkdir_wcc;
  1743. * };
  1744. *
  1745. * union LINK3res switch (nfsstat3 status) {
  1746. * case NFS3_OK:
  1747. * LINK3resok resok;
  1748. * default:
  1749. * LINK3resfail resfail;
  1750. * };
  1751. */
  1752. static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
  1753. void *data)
  1754. {
  1755. struct nfs3_linkres *result = data;
  1756. enum nfs_stat status;
  1757. int error;
  1758. error = decode_nfsstat3(xdr, &status);
  1759. if (unlikely(error))
  1760. goto out;
  1761. error = decode_post_op_attr(xdr, result->fattr);
  1762. if (unlikely(error))
  1763. goto out;
  1764. error = decode_wcc_data(xdr, result->dir_attr);
  1765. if (unlikely(error))
  1766. goto out;
  1767. if (status != NFS3_OK)
  1768. goto out_status;
  1769. out:
  1770. return error;
  1771. out_status:
  1772. return nfs3_stat_to_errno(status);
  1773. }
  1774. /**
  1775. * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in
  1776. * the local page cache
  1777. * @xdr: XDR stream where entry resides
  1778. * @entry: buffer to fill in with entry data
  1779. * @plus: boolean indicating whether this should be a readdirplus entry
  1780. *
  1781. * Returns zero if successful, otherwise a negative errno value is
  1782. * returned.
  1783. *
  1784. * This function is not invoked during READDIR reply decoding, but
  1785. * rather whenever an application invokes the getdents(2) system call
  1786. * on a directory already in our cache.
  1787. *
  1788. * 3.3.16 entry3
  1789. *
  1790. * struct entry3 {
  1791. * fileid3 fileid;
  1792. * filename3 name;
  1793. * cookie3 cookie;
  1794. * fhandle3 filehandle;
  1795. * post_op_attr3 attributes;
  1796. * entry3 *nextentry;
  1797. * };
  1798. *
  1799. * 3.3.17 entryplus3
  1800. * struct entryplus3 {
  1801. * fileid3 fileid;
  1802. * filename3 name;
  1803. * cookie3 cookie;
  1804. * post_op_attr name_attributes;
  1805. * post_op_fh3 name_handle;
  1806. * entryplus3 *nextentry;
  1807. * };
  1808. */
  1809. int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
  1810. bool plus)
  1811. {
  1812. struct nfs_entry old = *entry;
  1813. __be32 *p;
  1814. int error;
  1815. p = xdr_inline_decode(xdr, 4);
  1816. if (unlikely(p == NULL))
  1817. goto out_overflow;
  1818. if (*p == xdr_zero) {
  1819. p = xdr_inline_decode(xdr, 4);
  1820. if (unlikely(p == NULL))
  1821. goto out_overflow;
  1822. if (*p == xdr_zero)
  1823. return -EAGAIN;
  1824. entry->eof = 1;
  1825. return -EBADCOOKIE;
  1826. }
  1827. error = decode_fileid3(xdr, &entry->ino);
  1828. if (unlikely(error))
  1829. return error;
  1830. error = decode_inline_filename3(xdr, &entry->name, &entry->len);
  1831. if (unlikely(error))
  1832. return error;
  1833. entry->prev_cookie = entry->cookie;
  1834. error = decode_cookie3(xdr, &entry->cookie);
  1835. if (unlikely(error))
  1836. return error;
  1837. entry->d_type = DT_UNKNOWN;
  1838. if (plus) {
  1839. entry->fattr->valid = 0;
  1840. error = decode_post_op_attr(xdr, entry->fattr);
  1841. if (unlikely(error))
  1842. return error;
  1843. if (entry->fattr->valid & NFS_ATTR_FATTR_V3)
  1844. entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
  1845. if (entry->fattr->fileid != entry->ino) {
  1846. entry->fattr->mounted_on_fileid = entry->ino;
  1847. entry->fattr->valid |= NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
  1848. }
  1849. /* In fact, a post_op_fh3: */
  1850. p = xdr_inline_decode(xdr, 4);
  1851. if (unlikely(p == NULL))
  1852. goto out_overflow;
  1853. if (*p != xdr_zero) {
  1854. error = decode_nfs_fh3(xdr, entry->fh);
  1855. if (unlikely(error)) {
  1856. if (error == -E2BIG)
  1857. goto out_truncated;
  1858. return error;
  1859. }
  1860. } else
  1861. zero_nfs_fh3(entry->fh);
  1862. }
  1863. return 0;
  1864. out_overflow:
  1865. print_overflow_msg(__func__, xdr);
  1866. return -EAGAIN;
  1867. out_truncated:
  1868. dprintk("NFS: directory entry contains invalid file handle\n");
  1869. *entry = old;
  1870. return -EAGAIN;
  1871. }
  1872. /*
  1873. * 3.3.16 READDIR3res
  1874. *
  1875. * struct dirlist3 {
  1876. * entry3 *entries;
  1877. * bool eof;
  1878. * };
  1879. *
  1880. * struct READDIR3resok {
  1881. * post_op_attr dir_attributes;
  1882. * cookieverf3 cookieverf;
  1883. * dirlist3 reply;
  1884. * };
  1885. *
  1886. * struct READDIR3resfail {
  1887. * post_op_attr dir_attributes;
  1888. * };
  1889. *
  1890. * union READDIR3res switch (nfsstat3 status) {
  1891. * case NFS3_OK:
  1892. * READDIR3resok resok;
  1893. * default:
  1894. * READDIR3resfail resfail;
  1895. * };
  1896. *
  1897. * Read the directory contents into the page cache, but otherwise
  1898. * don't touch them. The actual decoding is done by nfs3_decode_entry()
  1899. * during subsequent nfs_readdir() calls.
  1900. */
  1901. static int decode_dirlist3(struct xdr_stream *xdr)
  1902. {
  1903. return xdr_read_pages(xdr, xdr->buf->page_len);
  1904. }
  1905. static int decode_readdir3resok(struct xdr_stream *xdr,
  1906. struct nfs3_readdirres *result)
  1907. {
  1908. int error;
  1909. error = decode_post_op_attr(xdr, result->dir_attr);
  1910. if (unlikely(error))
  1911. goto out;
  1912. /* XXX: do we need to check if result->verf != NULL ? */
  1913. error = decode_cookieverf3(xdr, result->verf);
  1914. if (unlikely(error))
  1915. goto out;
  1916. error = decode_dirlist3(xdr);
  1917. out:
  1918. return error;
  1919. }
  1920. static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req,
  1921. struct xdr_stream *xdr,
  1922. void *data)
  1923. {
  1924. struct nfs3_readdirres *result = data;
  1925. enum nfs_stat status;
  1926. int error;
  1927. error = decode_nfsstat3(xdr, &status);
  1928. if (unlikely(error))
  1929. goto out;
  1930. if (status != NFS3_OK)
  1931. goto out_default;
  1932. error = decode_readdir3resok(xdr, result);
  1933. out:
  1934. return error;
  1935. out_default:
  1936. error = decode_post_op_attr(xdr, result->dir_attr);
  1937. if (unlikely(error))
  1938. goto out;
  1939. return nfs3_stat_to_errno(status);
  1940. }
  1941. /*
  1942. * 3.3.18 FSSTAT3res
  1943. *
  1944. * struct FSSTAT3resok {
  1945. * post_op_attr obj_attributes;
  1946. * size3 tbytes;
  1947. * size3 fbytes;
  1948. * size3 abytes;
  1949. * size3 tfiles;
  1950. * size3 ffiles;
  1951. * size3 afiles;
  1952. * uint32 invarsec;
  1953. * };
  1954. *
  1955. * struct FSSTAT3resfail {
  1956. * post_op_attr obj_attributes;
  1957. * };
  1958. *
  1959. * union FSSTAT3res switch (nfsstat3 status) {
  1960. * case NFS3_OK:
  1961. * FSSTAT3resok resok;
  1962. * default:
  1963. * FSSTAT3resfail resfail;
  1964. * };
  1965. */
  1966. static int decode_fsstat3resok(struct xdr_stream *xdr,
  1967. struct nfs_fsstat *result)
  1968. {
  1969. __be32 *p;
  1970. p = xdr_inline_decode(xdr, 8 * 6 + 4);
  1971. if (unlikely(p == NULL))
  1972. goto out_overflow;
  1973. p = xdr_decode_size3(p, &result->tbytes);
  1974. p = xdr_decode_size3(p, &result->fbytes);
  1975. p = xdr_decode_size3(p, &result->abytes);
  1976. p = xdr_decode_size3(p, &result->tfiles);
  1977. p = xdr_decode_size3(p, &result->ffiles);
  1978. xdr_decode_size3(p, &result->afiles);
  1979. /* ignore invarsec */
  1980. return 0;
  1981. out_overflow:
  1982. print_overflow_msg(__func__, xdr);
  1983. return -EIO;
  1984. }
  1985. static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
  1986. struct xdr_stream *xdr,
  1987. void *data)
  1988. {
  1989. struct nfs_fsstat *result = data;
  1990. enum nfs_stat status;
  1991. int error;
  1992. error = decode_nfsstat3(xdr, &status);
  1993. if (unlikely(error))
  1994. goto out;
  1995. error = decode_post_op_attr(xdr, result->fattr);
  1996. if (unlikely(error))
  1997. goto out;
  1998. if (status != NFS3_OK)
  1999. goto out_status;
  2000. error = decode_fsstat3resok(xdr, result);
  2001. out:
  2002. return error;
  2003. out_status:
  2004. return nfs3_stat_to_errno(status);
  2005. }
  2006. /*
  2007. * 3.3.19 FSINFO3res
  2008. *
  2009. * struct FSINFO3resok {
  2010. * post_op_attr obj_attributes;
  2011. * uint32 rtmax;
  2012. * uint32 rtpref;
  2013. * uint32 rtmult;
  2014. * uint32 wtmax;
  2015. * uint32 wtpref;
  2016. * uint32 wtmult;
  2017. * uint32 dtpref;
  2018. * size3 maxfilesize;
  2019. * nfstime3 time_delta;
  2020. * uint32 properties;
  2021. * };
  2022. *
  2023. * struct FSINFO3resfail {
  2024. * post_op_attr obj_attributes;
  2025. * };
  2026. *
  2027. * union FSINFO3res switch (nfsstat3 status) {
  2028. * case NFS3_OK:
  2029. * FSINFO3resok resok;
  2030. * default:
  2031. * FSINFO3resfail resfail;
  2032. * };
  2033. */
  2034. static int decode_fsinfo3resok(struct xdr_stream *xdr,
  2035. struct nfs_fsinfo *result)
  2036. {
  2037. __be32 *p;
  2038. p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4);
  2039. if (unlikely(p == NULL))
  2040. goto out_overflow;
  2041. result->rtmax = be32_to_cpup(p++);
  2042. result->rtpref = be32_to_cpup(p++);
  2043. result->rtmult = be32_to_cpup(p++);
  2044. result->wtmax = be32_to_cpup(p++);
  2045. result->wtpref = be32_to_cpup(p++);
  2046. result->wtmult = be32_to_cpup(p++);
  2047. result->dtpref = be32_to_cpup(p++);
  2048. p = xdr_decode_size3(p, &result->maxfilesize);
  2049. xdr_decode_nfstime3(p, &result->time_delta);
  2050. /* ignore properties */
  2051. result->lease_time = 0;
  2052. return 0;
  2053. out_overflow:
  2054. print_overflow_msg(__func__, xdr);
  2055. return -EIO;
  2056. }
  2057. static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
  2058. struct xdr_stream *xdr,
  2059. void *data)
  2060. {
  2061. struct nfs_fsinfo *result = data;
  2062. enum nfs_stat status;
  2063. int error;
  2064. error = decode_nfsstat3(xdr, &status);
  2065. if (unlikely(error))
  2066. goto out;
  2067. error = decode_post_op_attr(xdr, result->fattr);
  2068. if (unlikely(error))
  2069. goto out;
  2070. if (status != NFS3_OK)
  2071. goto out_status;
  2072. error = decode_fsinfo3resok(xdr, result);
  2073. out:
  2074. return error;
  2075. out_status:
  2076. return nfs3_stat_to_errno(status);
  2077. }
  2078. /*
  2079. * 3.3.20 PATHCONF3res
  2080. *
  2081. * struct PATHCONF3resok {
  2082. * post_op_attr obj_attributes;
  2083. * uint32 linkmax;
  2084. * uint32 name_max;
  2085. * bool no_trunc;
  2086. * bool chown_restricted;
  2087. * bool case_insensitive;
  2088. * bool case_preserving;
  2089. * };
  2090. *
  2091. * struct PATHCONF3resfail {
  2092. * post_op_attr obj_attributes;
  2093. * };
  2094. *
  2095. * union PATHCONF3res switch (nfsstat3 status) {
  2096. * case NFS3_OK:
  2097. * PATHCONF3resok resok;
  2098. * default:
  2099. * PATHCONF3resfail resfail;
  2100. * };
  2101. */
  2102. static int decode_pathconf3resok(struct xdr_stream *xdr,
  2103. struct nfs_pathconf *result)
  2104. {
  2105. __be32 *p;
  2106. p = xdr_inline_decode(xdr, 4 * 6);
  2107. if (unlikely(p == NULL))
  2108. goto out_overflow;
  2109. result->max_link = be32_to_cpup(p++);
  2110. result->max_namelen = be32_to_cpup(p);
  2111. /* ignore remaining fields */
  2112. return 0;
  2113. out_overflow:
  2114. print_overflow_msg(__func__, xdr);
  2115. return -EIO;
  2116. }
  2117. static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
  2118. struct xdr_stream *xdr,
  2119. void *data)
  2120. {
  2121. struct nfs_pathconf *result = data;
  2122. enum nfs_stat status;
  2123. int error;
  2124. error = decode_nfsstat3(xdr, &status);
  2125. if (unlikely(error))
  2126. goto out;
  2127. error = decode_post_op_attr(xdr, result->fattr);
  2128. if (unlikely(error))
  2129. goto out;
  2130. if (status != NFS3_OK)
  2131. goto out_status;
  2132. error = decode_pathconf3resok(xdr, result);
  2133. out:
  2134. return error;
  2135. out_status:
  2136. return nfs3_stat_to_errno(status);
  2137. }
  2138. /*
  2139. * 3.3.21 COMMIT3res
  2140. *
  2141. * struct COMMIT3resok {
  2142. * wcc_data file_wcc;
  2143. * writeverf3 verf;
  2144. * };
  2145. *
  2146. * struct COMMIT3resfail {
  2147. * wcc_data file_wcc;
  2148. * };
  2149. *
  2150. * union COMMIT3res switch (nfsstat3 status) {
  2151. * case NFS3_OK:
  2152. * COMMIT3resok resok;
  2153. * default:
  2154. * COMMIT3resfail resfail;
  2155. * };
  2156. */
  2157. static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
  2158. struct xdr_stream *xdr,
  2159. void *data)
  2160. {
  2161. struct nfs_commitres *result = data;
  2162. enum nfs_stat status;
  2163. int error;
  2164. error = decode_nfsstat3(xdr, &status);
  2165. if (unlikely(error))
  2166. goto out;
  2167. error = decode_wcc_data(xdr, result->fattr);
  2168. if (unlikely(error))
  2169. goto out;
  2170. result->op_status = status;
  2171. if (status != NFS3_OK)
  2172. goto out_status;
  2173. error = decode_writeverf3(xdr, &result->verf->verifier);
  2174. out:
  2175. return error;
  2176. out_status:
  2177. return nfs3_stat_to_errno(status);
  2178. }
  2179. #ifdef CONFIG_NFS_V3_ACL
  2180. static inline int decode_getacl3resok(struct xdr_stream *xdr,
  2181. struct nfs3_getaclres *result)
  2182. {
  2183. struct posix_acl **acl;
  2184. unsigned int *aclcnt;
  2185. size_t hdrlen;
  2186. int error;
  2187. error = decode_post_op_attr(xdr, result->fattr);
  2188. if (unlikely(error))
  2189. goto out;
  2190. error = decode_uint32(xdr, &result->mask);
  2191. if (unlikely(error))
  2192. goto out;
  2193. error = -EINVAL;
  2194. if (result->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
  2195. goto out;
  2196. hdrlen = xdr_stream_pos(xdr);
  2197. acl = NULL;
  2198. if (result->mask & NFS_ACL)
  2199. acl = &result->acl_access;
  2200. aclcnt = NULL;
  2201. if (result->mask & NFS_ACLCNT)
  2202. aclcnt = &result->acl_access_count;
  2203. error = nfsacl_decode(xdr->buf, hdrlen, aclcnt, acl);
  2204. if (unlikely(error <= 0))
  2205. goto out;
  2206. acl = NULL;
  2207. if (result->mask & NFS_DFACL)
  2208. acl = &result->acl_default;
  2209. aclcnt = NULL;
  2210. if (result->mask & NFS_DFACLCNT)
  2211. aclcnt = &result->acl_default_count;
  2212. error = nfsacl_decode(xdr->buf, hdrlen + error, aclcnt, acl);
  2213. if (unlikely(error <= 0))
  2214. return error;
  2215. error = 0;
  2216. out:
  2217. return error;
  2218. }
  2219. static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
  2220. struct xdr_stream *xdr,
  2221. void *result)
  2222. {
  2223. enum nfs_stat status;
  2224. int error;
  2225. error = decode_nfsstat3(xdr, &status);
  2226. if (unlikely(error))
  2227. goto out;
  2228. if (status != NFS3_OK)
  2229. goto out_default;
  2230. error = decode_getacl3resok(xdr, result);
  2231. out:
  2232. return error;
  2233. out_default:
  2234. return nfs3_stat_to_errno(status);
  2235. }
  2236. static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
  2237. struct xdr_stream *xdr,
  2238. void *result)
  2239. {
  2240. enum nfs_stat status;
  2241. int error;
  2242. error = decode_nfsstat3(xdr, &status);
  2243. if (unlikely(error))
  2244. goto out;
  2245. if (status != NFS3_OK)
  2246. goto out_default;
  2247. error = decode_post_op_attr(xdr, result);
  2248. out:
  2249. return error;
  2250. out_default:
  2251. return nfs3_stat_to_errno(status);
  2252. }
  2253. #endif /* CONFIG_NFS_V3_ACL */
  2254. /*
  2255. * We need to translate between nfs status return values and
  2256. * the local errno values which may not be the same.
  2257. */
  2258. static const struct {
  2259. int stat;
  2260. int errno;
  2261. } nfs_errtbl[] = {
  2262. { NFS_OK, 0 },
  2263. { NFSERR_PERM, -EPERM },
  2264. { NFSERR_NOENT, -ENOENT },
  2265. { NFSERR_IO, -errno_NFSERR_IO},
  2266. { NFSERR_NXIO, -ENXIO },
  2267. /* { NFSERR_EAGAIN, -EAGAIN }, */
  2268. { NFSERR_ACCES, -EACCES },
  2269. { NFSERR_EXIST, -EEXIST },
  2270. { NFSERR_XDEV, -EXDEV },
  2271. { NFSERR_NODEV, -ENODEV },
  2272. { NFSERR_NOTDIR, -ENOTDIR },
  2273. { NFSERR_ISDIR, -EISDIR },
  2274. { NFSERR_INVAL, -EINVAL },
  2275. { NFSERR_FBIG, -EFBIG },
  2276. { NFSERR_NOSPC, -ENOSPC },
  2277. { NFSERR_ROFS, -EROFS },
  2278. { NFSERR_MLINK, -EMLINK },
  2279. { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
  2280. { NFSERR_NOTEMPTY, -ENOTEMPTY },
  2281. { NFSERR_DQUOT, -EDQUOT },
  2282. { NFSERR_STALE, -ESTALE },
  2283. { NFSERR_REMOTE, -EREMOTE },
  2284. #ifdef EWFLUSH
  2285. { NFSERR_WFLUSH, -EWFLUSH },
  2286. #endif
  2287. { NFSERR_BADHANDLE, -EBADHANDLE },
  2288. { NFSERR_NOT_SYNC, -ENOTSYNC },
  2289. { NFSERR_BAD_COOKIE, -EBADCOOKIE },
  2290. { NFSERR_NOTSUPP, -ENOTSUPP },
  2291. { NFSERR_TOOSMALL, -ETOOSMALL },
  2292. { NFSERR_SERVERFAULT, -EREMOTEIO },
  2293. { NFSERR_BADTYPE, -EBADTYPE },
  2294. { NFSERR_JUKEBOX, -EJUKEBOX },
  2295. { -1, -EIO }
  2296. };
  2297. /**
  2298. * nfs3_stat_to_errno - convert an NFS status code to a local errno
  2299. * @status: NFS status code to convert
  2300. *
  2301. * Returns a local errno value, or -EIO if the NFS status code is
  2302. * not recognized. This function is used jointly by NFSv2 and NFSv3.
  2303. */
  2304. static int nfs3_stat_to_errno(enum nfs_stat status)
  2305. {
  2306. int i;
  2307. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  2308. if (nfs_errtbl[i].stat == (int)status)
  2309. return nfs_errtbl[i].errno;
  2310. }
  2311. dprintk("NFS: Unrecognized nfs status value: %u\n", status);
  2312. return nfs_errtbl[i].errno;
  2313. }
  2314. #define PROC(proc, argtype, restype, timer) \
  2315. [NFS3PROC_##proc] = { \
  2316. .p_proc = NFS3PROC_##proc, \
  2317. .p_encode = nfs3_xdr_enc_##argtype##3args, \
  2318. .p_decode = nfs3_xdr_dec_##restype##3res, \
  2319. .p_arglen = NFS3_##argtype##args_sz, \
  2320. .p_replen = NFS3_##restype##res_sz, \
  2321. .p_timer = timer, \
  2322. .p_statidx = NFS3PROC_##proc, \
  2323. .p_name = #proc, \
  2324. }
  2325. const struct rpc_procinfo nfs3_procedures[] = {
  2326. PROC(GETATTR, getattr, getattr, 1),
  2327. PROC(SETATTR, setattr, setattr, 0),
  2328. PROC(LOOKUP, lookup, lookup, 2),
  2329. PROC(ACCESS, access, access, 1),
  2330. PROC(READLINK, readlink, readlink, 3),
  2331. PROC(READ, read, read, 3),
  2332. PROC(WRITE, write, write, 4),
  2333. PROC(CREATE, create, create, 0),
  2334. PROC(MKDIR, mkdir, create, 0),
  2335. PROC(SYMLINK, symlink, create, 0),
  2336. PROC(MKNOD, mknod, create, 0),
  2337. PROC(REMOVE, remove, remove, 0),
  2338. PROC(RMDIR, lookup, setattr, 0),
  2339. PROC(RENAME, rename, rename, 0),
  2340. PROC(LINK, link, link, 0),
  2341. PROC(READDIR, readdir, readdir, 3),
  2342. PROC(READDIRPLUS, readdirplus, readdir, 3),
  2343. PROC(FSSTAT, getattr, fsstat, 0),
  2344. PROC(FSINFO, getattr, fsinfo, 0),
  2345. PROC(PATHCONF, getattr, pathconf, 0),
  2346. PROC(COMMIT, commit, commit, 5),
  2347. };
  2348. static unsigned int nfs_version3_counts[ARRAY_SIZE(nfs3_procedures)];
  2349. const struct rpc_version nfs_version3 = {
  2350. .number = 3,
  2351. .nrprocs = ARRAY_SIZE(nfs3_procedures),
  2352. .procs = nfs3_procedures,
  2353. .counts = nfs_version3_counts,
  2354. };
  2355. #ifdef CONFIG_NFS_V3_ACL
  2356. static const struct rpc_procinfo nfs3_acl_procedures[] = {
  2357. [ACLPROC3_GETACL] = {
  2358. .p_proc = ACLPROC3_GETACL,
  2359. .p_encode = nfs3_xdr_enc_getacl3args,
  2360. .p_decode = nfs3_xdr_dec_getacl3res,
  2361. .p_arglen = ACL3_getaclargs_sz,
  2362. .p_replen = ACL3_getaclres_sz,
  2363. .p_timer = 1,
  2364. .p_name = "GETACL",
  2365. },
  2366. [ACLPROC3_SETACL] = {
  2367. .p_proc = ACLPROC3_SETACL,
  2368. .p_encode = nfs3_xdr_enc_setacl3args,
  2369. .p_decode = nfs3_xdr_dec_setacl3res,
  2370. .p_arglen = ACL3_setaclargs_sz,
  2371. .p_replen = ACL3_setaclres_sz,
  2372. .p_timer = 0,
  2373. .p_name = "SETACL",
  2374. },
  2375. };
  2376. static unsigned int nfs3_acl_counts[ARRAY_SIZE(nfs3_acl_procedures)];
  2377. const struct rpc_version nfsacl_version3 = {
  2378. .number = 3,
  2379. .nrprocs = ARRAY_SIZE(nfs3_acl_procedures),
  2380. .procs = nfs3_acl_procedures,
  2381. .counts = nfs3_acl_counts,
  2382. };
  2383. #endif /* CONFIG_NFS_V3_ACL */