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