nfs3xdr.c 56 KB

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