nfs3xdr.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632
  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. unsigned int replen = args->replen ? args->replen : NFS3_readres_sz;
  883. encode_read3args(xdr, args);
  884. prepare_reply_buffer(req, args->pages, args->pgbase,
  885. args->count, replen);
  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. req->rq_rcv_buf.flags |= XDRBUF_SPARSE_PAGES;
  1224. }
  1225. }
  1226. static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req,
  1227. struct xdr_stream *xdr,
  1228. const void *data)
  1229. {
  1230. const struct nfs3_setaclargs *args = data;
  1231. unsigned int base;
  1232. int error;
  1233. encode_nfs_fh3(xdr, NFS_FH(args->inode));
  1234. encode_uint32(xdr, args->mask);
  1235. base = req->rq_slen;
  1236. if (args->npages != 0)
  1237. xdr_write_pages(xdr, args->pages, 0, args->len);
  1238. else
  1239. xdr_reserve_space(xdr, args->len);
  1240. error = nfsacl_encode(xdr->buf, base, args->inode,
  1241. (args->mask & NFS_ACL) ?
  1242. args->acl_access : NULL, 1, 0);
  1243. /* FIXME: this is just broken */
  1244. BUG_ON(error < 0);
  1245. error = nfsacl_encode(xdr->buf, base + error, args->inode,
  1246. (args->mask & NFS_DFACL) ?
  1247. args->acl_default : NULL, 1,
  1248. NFS_ACL_DEFAULT);
  1249. BUG_ON(error < 0);
  1250. }
  1251. #endif /* CONFIG_NFS_V3_ACL */
  1252. /*
  1253. * NFSv3 XDR decode functions
  1254. *
  1255. * NFSv3 result types are defined in section 3.3 of RFC 1813:
  1256. * "NFS Version 3 Protocol Specification".
  1257. */
  1258. /*
  1259. * 3.3.1 GETATTR3res
  1260. *
  1261. * struct GETATTR3resok {
  1262. * fattr3 obj_attributes;
  1263. * };
  1264. *
  1265. * union GETATTR3res switch (nfsstat3 status) {
  1266. * case NFS3_OK:
  1267. * GETATTR3resok resok;
  1268. * default:
  1269. * void;
  1270. * };
  1271. */
  1272. static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
  1273. struct xdr_stream *xdr,
  1274. void *result)
  1275. {
  1276. enum nfs_stat status;
  1277. int error;
  1278. error = decode_nfsstat3(xdr, &status);
  1279. if (unlikely(error))
  1280. goto out;
  1281. if (status != NFS3_OK)
  1282. goto out_default;
  1283. error = decode_fattr3(xdr, result);
  1284. out:
  1285. return error;
  1286. out_default:
  1287. return nfs3_stat_to_errno(status);
  1288. }
  1289. /*
  1290. * 3.3.2 SETATTR3res
  1291. *
  1292. * struct SETATTR3resok {
  1293. * wcc_data obj_wcc;
  1294. * };
  1295. *
  1296. * struct SETATTR3resfail {
  1297. * wcc_data obj_wcc;
  1298. * };
  1299. *
  1300. * union SETATTR3res switch (nfsstat3 status) {
  1301. * case NFS3_OK:
  1302. * SETATTR3resok resok;
  1303. * default:
  1304. * SETATTR3resfail resfail;
  1305. * };
  1306. */
  1307. static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
  1308. struct xdr_stream *xdr,
  1309. void *result)
  1310. {
  1311. enum nfs_stat status;
  1312. int error;
  1313. error = decode_nfsstat3(xdr, &status);
  1314. if (unlikely(error))
  1315. goto out;
  1316. error = decode_wcc_data(xdr, result);
  1317. if (unlikely(error))
  1318. goto out;
  1319. if (status != NFS3_OK)
  1320. goto out_status;
  1321. out:
  1322. return error;
  1323. out_status:
  1324. return nfs3_stat_to_errno(status);
  1325. }
  1326. /*
  1327. * 3.3.3 LOOKUP3res
  1328. *
  1329. * struct LOOKUP3resok {
  1330. * nfs_fh3 object;
  1331. * post_op_attr obj_attributes;
  1332. * post_op_attr dir_attributes;
  1333. * };
  1334. *
  1335. * struct LOOKUP3resfail {
  1336. * post_op_attr dir_attributes;
  1337. * };
  1338. *
  1339. * union LOOKUP3res switch (nfsstat3 status) {
  1340. * case NFS3_OK:
  1341. * LOOKUP3resok resok;
  1342. * default:
  1343. * LOOKUP3resfail resfail;
  1344. * };
  1345. */
  1346. static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req,
  1347. struct xdr_stream *xdr,
  1348. void *data)
  1349. {
  1350. struct nfs3_diropres *result = data;
  1351. enum nfs_stat status;
  1352. int error;
  1353. error = decode_nfsstat3(xdr, &status);
  1354. if (unlikely(error))
  1355. goto out;
  1356. if (status != NFS3_OK)
  1357. goto out_default;
  1358. error = decode_nfs_fh3(xdr, result->fh);
  1359. if (unlikely(error))
  1360. goto out;
  1361. error = decode_post_op_attr(xdr, result->fattr);
  1362. if (unlikely(error))
  1363. goto out;
  1364. error = decode_post_op_attr(xdr, result->dir_attr);
  1365. out:
  1366. return error;
  1367. out_default:
  1368. error = decode_post_op_attr(xdr, result->dir_attr);
  1369. if (unlikely(error))
  1370. goto out;
  1371. return nfs3_stat_to_errno(status);
  1372. }
  1373. /*
  1374. * 3.3.4 ACCESS3res
  1375. *
  1376. * struct ACCESS3resok {
  1377. * post_op_attr obj_attributes;
  1378. * uint32 access;
  1379. * };
  1380. *
  1381. * struct ACCESS3resfail {
  1382. * post_op_attr obj_attributes;
  1383. * };
  1384. *
  1385. * union ACCESS3res switch (nfsstat3 status) {
  1386. * case NFS3_OK:
  1387. * ACCESS3resok resok;
  1388. * default:
  1389. * ACCESS3resfail resfail;
  1390. * };
  1391. */
  1392. static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
  1393. struct xdr_stream *xdr,
  1394. void *data)
  1395. {
  1396. struct nfs3_accessres *result = data;
  1397. enum nfs_stat status;
  1398. int error;
  1399. error = decode_nfsstat3(xdr, &status);
  1400. if (unlikely(error))
  1401. goto out;
  1402. error = decode_post_op_attr(xdr, result->fattr);
  1403. if (unlikely(error))
  1404. goto out;
  1405. if (status != NFS3_OK)
  1406. goto out_default;
  1407. error = decode_uint32(xdr, &result->access);
  1408. out:
  1409. return error;
  1410. out_default:
  1411. return nfs3_stat_to_errno(status);
  1412. }
  1413. /*
  1414. * 3.3.5 READLINK3res
  1415. *
  1416. * struct READLINK3resok {
  1417. * post_op_attr symlink_attributes;
  1418. * nfspath3 data;
  1419. * };
  1420. *
  1421. * struct READLINK3resfail {
  1422. * post_op_attr symlink_attributes;
  1423. * };
  1424. *
  1425. * union READLINK3res switch (nfsstat3 status) {
  1426. * case NFS3_OK:
  1427. * READLINK3resok resok;
  1428. * default:
  1429. * READLINK3resfail resfail;
  1430. * };
  1431. */
  1432. static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
  1433. struct xdr_stream *xdr,
  1434. void *result)
  1435. {
  1436. enum nfs_stat status;
  1437. int error;
  1438. error = decode_nfsstat3(xdr, &status);
  1439. if (unlikely(error))
  1440. goto out;
  1441. error = decode_post_op_attr(xdr, result);
  1442. if (unlikely(error))
  1443. goto out;
  1444. if (status != NFS3_OK)
  1445. goto out_default;
  1446. error = decode_nfspath3(xdr);
  1447. out:
  1448. return error;
  1449. out_default:
  1450. return nfs3_stat_to_errno(status);
  1451. }
  1452. /*
  1453. * 3.3.6 READ3res
  1454. *
  1455. * struct READ3resok {
  1456. * post_op_attr file_attributes;
  1457. * count3 count;
  1458. * bool eof;
  1459. * opaque data<>;
  1460. * };
  1461. *
  1462. * struct READ3resfail {
  1463. * post_op_attr file_attributes;
  1464. * };
  1465. *
  1466. * union READ3res switch (nfsstat3 status) {
  1467. * case NFS3_OK:
  1468. * READ3resok resok;
  1469. * default:
  1470. * READ3resfail resfail;
  1471. * };
  1472. */
  1473. static int decode_read3resok(struct xdr_stream *xdr,
  1474. struct nfs_pgio_res *result)
  1475. {
  1476. u32 eof, count, ocount, recvd;
  1477. __be32 *p;
  1478. p = xdr_inline_decode(xdr, 4 + 4 + 4);
  1479. if (unlikely(p == NULL))
  1480. goto out_overflow;
  1481. count = be32_to_cpup(p++);
  1482. eof = be32_to_cpup(p++);
  1483. ocount = be32_to_cpup(p++);
  1484. if (unlikely(ocount != count))
  1485. goto out_mismatch;
  1486. recvd = xdr_read_pages(xdr, count);
  1487. if (unlikely(count > recvd))
  1488. goto out_cheating;
  1489. out:
  1490. result->eof = eof;
  1491. result->count = count;
  1492. return count;
  1493. out_mismatch:
  1494. dprintk("NFS: READ count doesn't match length of opaque: "
  1495. "count %u != ocount %u\n", count, ocount);
  1496. return -EIO;
  1497. out_cheating:
  1498. dprintk("NFS: server cheating in read result: "
  1499. "count %u > recvd %u\n", count, recvd);
  1500. count = recvd;
  1501. eof = 0;
  1502. goto out;
  1503. out_overflow:
  1504. print_overflow_msg(__func__, xdr);
  1505. return -EIO;
  1506. }
  1507. static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
  1508. void *data)
  1509. {
  1510. struct nfs_pgio_res *result = data;
  1511. unsigned int pos;
  1512. enum nfs_stat status;
  1513. int error;
  1514. pos = xdr_stream_pos(xdr);
  1515. error = decode_nfsstat3(xdr, &status);
  1516. if (unlikely(error))
  1517. goto out;
  1518. error = decode_post_op_attr(xdr, result->fattr);
  1519. if (unlikely(error))
  1520. goto out;
  1521. result->op_status = status;
  1522. if (status != NFS3_OK)
  1523. goto out_status;
  1524. result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
  1525. error = decode_read3resok(xdr, result);
  1526. out:
  1527. return error;
  1528. out_status:
  1529. return nfs3_stat_to_errno(status);
  1530. }
  1531. /*
  1532. * 3.3.7 WRITE3res
  1533. *
  1534. * enum stable_how {
  1535. * UNSTABLE = 0,
  1536. * DATA_SYNC = 1,
  1537. * FILE_SYNC = 2
  1538. * };
  1539. *
  1540. * struct WRITE3resok {
  1541. * wcc_data file_wcc;
  1542. * count3 count;
  1543. * stable_how committed;
  1544. * writeverf3 verf;
  1545. * };
  1546. *
  1547. * struct WRITE3resfail {
  1548. * wcc_data file_wcc;
  1549. * };
  1550. *
  1551. * union WRITE3res switch (nfsstat3 status) {
  1552. * case NFS3_OK:
  1553. * WRITE3resok resok;
  1554. * default:
  1555. * WRITE3resfail resfail;
  1556. * };
  1557. */
  1558. static int decode_write3resok(struct xdr_stream *xdr,
  1559. struct nfs_pgio_res *result)
  1560. {
  1561. __be32 *p;
  1562. p = xdr_inline_decode(xdr, 4 + 4);
  1563. if (unlikely(p == NULL))
  1564. goto out_overflow;
  1565. result->count = be32_to_cpup(p++);
  1566. result->verf->committed = be32_to_cpup(p++);
  1567. if (unlikely(result->verf->committed > NFS_FILE_SYNC))
  1568. goto out_badvalue;
  1569. if (decode_writeverf3(xdr, &result->verf->verifier))
  1570. goto out_eio;
  1571. return result->count;
  1572. out_badvalue:
  1573. dprintk("NFS: bad stable_how value: %u\n", result->verf->committed);
  1574. return -EIO;
  1575. out_overflow:
  1576. print_overflow_msg(__func__, xdr);
  1577. out_eio:
  1578. return -EIO;
  1579. }
  1580. static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
  1581. void *data)
  1582. {
  1583. struct nfs_pgio_res *result = data;
  1584. enum nfs_stat status;
  1585. int error;
  1586. error = decode_nfsstat3(xdr, &status);
  1587. if (unlikely(error))
  1588. goto out;
  1589. error = decode_wcc_data(xdr, result->fattr);
  1590. if (unlikely(error))
  1591. goto out;
  1592. result->op_status = status;
  1593. if (status != NFS3_OK)
  1594. goto out_status;
  1595. error = decode_write3resok(xdr, result);
  1596. out:
  1597. return error;
  1598. out_status:
  1599. return nfs3_stat_to_errno(status);
  1600. }
  1601. /*
  1602. * 3.3.8 CREATE3res
  1603. *
  1604. * struct CREATE3resok {
  1605. * post_op_fh3 obj;
  1606. * post_op_attr obj_attributes;
  1607. * wcc_data dir_wcc;
  1608. * };
  1609. *
  1610. * struct CREATE3resfail {
  1611. * wcc_data dir_wcc;
  1612. * };
  1613. *
  1614. * union CREATE3res switch (nfsstat3 status) {
  1615. * case NFS3_OK:
  1616. * CREATE3resok resok;
  1617. * default:
  1618. * CREATE3resfail resfail;
  1619. * };
  1620. */
  1621. static int decode_create3resok(struct xdr_stream *xdr,
  1622. struct nfs3_diropres *result)
  1623. {
  1624. int error;
  1625. error = decode_post_op_fh3(xdr, result->fh);
  1626. if (unlikely(error))
  1627. goto out;
  1628. error = decode_post_op_attr(xdr, result->fattr);
  1629. if (unlikely(error))
  1630. goto out;
  1631. /* The server isn't required to return a file handle.
  1632. * If it didn't, force the client to perform a LOOKUP
  1633. * to determine the correct file handle and attribute
  1634. * values for the new object. */
  1635. if (result->fh->size == 0)
  1636. result->fattr->valid = 0;
  1637. error = decode_wcc_data(xdr, result->dir_attr);
  1638. out:
  1639. return error;
  1640. }
  1641. static int nfs3_xdr_dec_create3res(struct rpc_rqst *req,
  1642. struct xdr_stream *xdr,
  1643. void *data)
  1644. {
  1645. struct nfs3_diropres *result = data;
  1646. enum nfs_stat status;
  1647. int error;
  1648. error = decode_nfsstat3(xdr, &status);
  1649. if (unlikely(error))
  1650. goto out;
  1651. if (status != NFS3_OK)
  1652. goto out_default;
  1653. error = decode_create3resok(xdr, result);
  1654. out:
  1655. return error;
  1656. out_default:
  1657. error = decode_wcc_data(xdr, result->dir_attr);
  1658. if (unlikely(error))
  1659. goto out;
  1660. return nfs3_stat_to_errno(status);
  1661. }
  1662. /*
  1663. * 3.3.12 REMOVE3res
  1664. *
  1665. * struct REMOVE3resok {
  1666. * wcc_data dir_wcc;
  1667. * };
  1668. *
  1669. * struct REMOVE3resfail {
  1670. * wcc_data dir_wcc;
  1671. * };
  1672. *
  1673. * union REMOVE3res switch (nfsstat3 status) {
  1674. * case NFS3_OK:
  1675. * REMOVE3resok resok;
  1676. * default:
  1677. * REMOVE3resfail resfail;
  1678. * };
  1679. */
  1680. static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
  1681. struct xdr_stream *xdr,
  1682. void *data)
  1683. {
  1684. struct nfs_removeres *result = data;
  1685. enum nfs_stat status;
  1686. int error;
  1687. error = decode_nfsstat3(xdr, &status);
  1688. if (unlikely(error))
  1689. goto out;
  1690. error = decode_wcc_data(xdr, result->dir_attr);
  1691. if (unlikely(error))
  1692. goto out;
  1693. if (status != NFS3_OK)
  1694. goto out_status;
  1695. out:
  1696. return error;
  1697. out_status:
  1698. return nfs3_stat_to_errno(status);
  1699. }
  1700. /*
  1701. * 3.3.14 RENAME3res
  1702. *
  1703. * struct RENAME3resok {
  1704. * wcc_data fromdir_wcc;
  1705. * wcc_data todir_wcc;
  1706. * };
  1707. *
  1708. * struct RENAME3resfail {
  1709. * wcc_data fromdir_wcc;
  1710. * wcc_data todir_wcc;
  1711. * };
  1712. *
  1713. * union RENAME3res switch (nfsstat3 status) {
  1714. * case NFS3_OK:
  1715. * RENAME3resok resok;
  1716. * default:
  1717. * RENAME3resfail resfail;
  1718. * };
  1719. */
  1720. static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
  1721. struct xdr_stream *xdr,
  1722. void *data)
  1723. {
  1724. struct nfs_renameres *result = data;
  1725. enum nfs_stat status;
  1726. int error;
  1727. error = decode_nfsstat3(xdr, &status);
  1728. if (unlikely(error))
  1729. goto out;
  1730. error = decode_wcc_data(xdr, result->old_fattr);
  1731. if (unlikely(error))
  1732. goto out;
  1733. error = decode_wcc_data(xdr, result->new_fattr);
  1734. if (unlikely(error))
  1735. goto out;
  1736. if (status != NFS3_OK)
  1737. goto out_status;
  1738. out:
  1739. return error;
  1740. out_status:
  1741. return nfs3_stat_to_errno(status);
  1742. }
  1743. /*
  1744. * 3.3.15 LINK3res
  1745. *
  1746. * struct LINK3resok {
  1747. * post_op_attr file_attributes;
  1748. * wcc_data linkdir_wcc;
  1749. * };
  1750. *
  1751. * struct LINK3resfail {
  1752. * post_op_attr file_attributes;
  1753. * wcc_data linkdir_wcc;
  1754. * };
  1755. *
  1756. * union LINK3res switch (nfsstat3 status) {
  1757. * case NFS3_OK:
  1758. * LINK3resok resok;
  1759. * default:
  1760. * LINK3resfail resfail;
  1761. * };
  1762. */
  1763. static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
  1764. void *data)
  1765. {
  1766. struct nfs3_linkres *result = data;
  1767. enum nfs_stat status;
  1768. int error;
  1769. error = decode_nfsstat3(xdr, &status);
  1770. if (unlikely(error))
  1771. goto out;
  1772. error = decode_post_op_attr(xdr, result->fattr);
  1773. if (unlikely(error))
  1774. goto out;
  1775. error = decode_wcc_data(xdr, result->dir_attr);
  1776. if (unlikely(error))
  1777. goto out;
  1778. if (status != NFS3_OK)
  1779. goto out_status;
  1780. out:
  1781. return error;
  1782. out_status:
  1783. return nfs3_stat_to_errno(status);
  1784. }
  1785. /**
  1786. * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in
  1787. * the local page cache
  1788. * @xdr: XDR stream where entry resides
  1789. * @entry: buffer to fill in with entry data
  1790. * @plus: boolean indicating whether this should be a readdirplus entry
  1791. *
  1792. * Returns zero if successful, otherwise a negative errno value is
  1793. * returned.
  1794. *
  1795. * This function is not invoked during READDIR reply decoding, but
  1796. * rather whenever an application invokes the getdents(2) system call
  1797. * on a directory already in our cache.
  1798. *
  1799. * 3.3.16 entry3
  1800. *
  1801. * struct entry3 {
  1802. * fileid3 fileid;
  1803. * filename3 name;
  1804. * cookie3 cookie;
  1805. * fhandle3 filehandle;
  1806. * post_op_attr3 attributes;
  1807. * entry3 *nextentry;
  1808. * };
  1809. *
  1810. * 3.3.17 entryplus3
  1811. * struct entryplus3 {
  1812. * fileid3 fileid;
  1813. * filename3 name;
  1814. * cookie3 cookie;
  1815. * post_op_attr name_attributes;
  1816. * post_op_fh3 name_handle;
  1817. * entryplus3 *nextentry;
  1818. * };
  1819. */
  1820. int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
  1821. bool plus)
  1822. {
  1823. struct nfs_entry old = *entry;
  1824. __be32 *p;
  1825. int error;
  1826. u64 new_cookie;
  1827. p = xdr_inline_decode(xdr, 4);
  1828. if (unlikely(p == NULL))
  1829. goto out_overflow;
  1830. if (*p == xdr_zero) {
  1831. p = xdr_inline_decode(xdr, 4);
  1832. if (unlikely(p == NULL))
  1833. goto out_overflow;
  1834. if (*p == xdr_zero)
  1835. return -EAGAIN;
  1836. entry->eof = 1;
  1837. return -EBADCOOKIE;
  1838. }
  1839. error = decode_fileid3(xdr, &entry->ino);
  1840. if (unlikely(error))
  1841. return error;
  1842. error = decode_inline_filename3(xdr, &entry->name, &entry->len);
  1843. if (unlikely(error))
  1844. return error;
  1845. error = decode_cookie3(xdr, &new_cookie);
  1846. if (unlikely(error))
  1847. return error;
  1848. entry->d_type = DT_UNKNOWN;
  1849. if (plus) {
  1850. entry->fattr->valid = 0;
  1851. error = decode_post_op_attr(xdr, entry->fattr);
  1852. if (unlikely(error))
  1853. return error;
  1854. if (entry->fattr->valid & NFS_ATTR_FATTR_V3)
  1855. entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
  1856. if (entry->fattr->fileid != entry->ino) {
  1857. entry->fattr->mounted_on_fileid = entry->ino;
  1858. entry->fattr->valid |= NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
  1859. }
  1860. /* In fact, a post_op_fh3: */
  1861. p = xdr_inline_decode(xdr, 4);
  1862. if (unlikely(p == NULL))
  1863. goto out_overflow;
  1864. if (*p != xdr_zero) {
  1865. error = decode_nfs_fh3(xdr, entry->fh);
  1866. if (unlikely(error)) {
  1867. if (error == -E2BIG)
  1868. goto out_truncated;
  1869. return error;
  1870. }
  1871. } else
  1872. zero_nfs_fh3(entry->fh);
  1873. }
  1874. entry->prev_cookie = entry->cookie;
  1875. entry->cookie = new_cookie;
  1876. return 0;
  1877. out_overflow:
  1878. print_overflow_msg(__func__, xdr);
  1879. return -EAGAIN;
  1880. out_truncated:
  1881. dprintk("NFS: directory entry contains invalid file handle\n");
  1882. *entry = old;
  1883. return -EAGAIN;
  1884. }
  1885. /*
  1886. * 3.3.16 READDIR3res
  1887. *
  1888. * struct dirlist3 {
  1889. * entry3 *entries;
  1890. * bool eof;
  1891. * };
  1892. *
  1893. * struct READDIR3resok {
  1894. * post_op_attr dir_attributes;
  1895. * cookieverf3 cookieverf;
  1896. * dirlist3 reply;
  1897. * };
  1898. *
  1899. * struct READDIR3resfail {
  1900. * post_op_attr dir_attributes;
  1901. * };
  1902. *
  1903. * union READDIR3res switch (nfsstat3 status) {
  1904. * case NFS3_OK:
  1905. * READDIR3resok resok;
  1906. * default:
  1907. * READDIR3resfail resfail;
  1908. * };
  1909. *
  1910. * Read the directory contents into the page cache, but otherwise
  1911. * don't touch them. The actual decoding is done by nfs3_decode_entry()
  1912. * during subsequent nfs_readdir() calls.
  1913. */
  1914. static int decode_dirlist3(struct xdr_stream *xdr)
  1915. {
  1916. return xdr_read_pages(xdr, xdr->buf->page_len);
  1917. }
  1918. static int decode_readdir3resok(struct xdr_stream *xdr,
  1919. struct nfs3_readdirres *result)
  1920. {
  1921. int error;
  1922. error = decode_post_op_attr(xdr, result->dir_attr);
  1923. if (unlikely(error))
  1924. goto out;
  1925. /* XXX: do we need to check if result->verf != NULL ? */
  1926. error = decode_cookieverf3(xdr, result->verf);
  1927. if (unlikely(error))
  1928. goto out;
  1929. error = decode_dirlist3(xdr);
  1930. out:
  1931. return error;
  1932. }
  1933. static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req,
  1934. struct xdr_stream *xdr,
  1935. void *data)
  1936. {
  1937. struct nfs3_readdirres *result = data;
  1938. enum nfs_stat status;
  1939. int error;
  1940. error = decode_nfsstat3(xdr, &status);
  1941. if (unlikely(error))
  1942. goto out;
  1943. if (status != NFS3_OK)
  1944. goto out_default;
  1945. error = decode_readdir3resok(xdr, result);
  1946. out:
  1947. return error;
  1948. out_default:
  1949. error = decode_post_op_attr(xdr, result->dir_attr);
  1950. if (unlikely(error))
  1951. goto out;
  1952. return nfs3_stat_to_errno(status);
  1953. }
  1954. /*
  1955. * 3.3.18 FSSTAT3res
  1956. *
  1957. * struct FSSTAT3resok {
  1958. * post_op_attr obj_attributes;
  1959. * size3 tbytes;
  1960. * size3 fbytes;
  1961. * size3 abytes;
  1962. * size3 tfiles;
  1963. * size3 ffiles;
  1964. * size3 afiles;
  1965. * uint32 invarsec;
  1966. * };
  1967. *
  1968. * struct FSSTAT3resfail {
  1969. * post_op_attr obj_attributes;
  1970. * };
  1971. *
  1972. * union FSSTAT3res switch (nfsstat3 status) {
  1973. * case NFS3_OK:
  1974. * FSSTAT3resok resok;
  1975. * default:
  1976. * FSSTAT3resfail resfail;
  1977. * };
  1978. */
  1979. static int decode_fsstat3resok(struct xdr_stream *xdr,
  1980. struct nfs_fsstat *result)
  1981. {
  1982. __be32 *p;
  1983. p = xdr_inline_decode(xdr, 8 * 6 + 4);
  1984. if (unlikely(p == NULL))
  1985. goto out_overflow;
  1986. p = xdr_decode_size3(p, &result->tbytes);
  1987. p = xdr_decode_size3(p, &result->fbytes);
  1988. p = xdr_decode_size3(p, &result->abytes);
  1989. p = xdr_decode_size3(p, &result->tfiles);
  1990. p = xdr_decode_size3(p, &result->ffiles);
  1991. xdr_decode_size3(p, &result->afiles);
  1992. /* ignore invarsec */
  1993. return 0;
  1994. out_overflow:
  1995. print_overflow_msg(__func__, xdr);
  1996. return -EIO;
  1997. }
  1998. static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
  1999. struct xdr_stream *xdr,
  2000. void *data)
  2001. {
  2002. struct nfs_fsstat *result = data;
  2003. enum nfs_stat status;
  2004. int error;
  2005. error = decode_nfsstat3(xdr, &status);
  2006. if (unlikely(error))
  2007. goto out;
  2008. error = decode_post_op_attr(xdr, result->fattr);
  2009. if (unlikely(error))
  2010. goto out;
  2011. if (status != NFS3_OK)
  2012. goto out_status;
  2013. error = decode_fsstat3resok(xdr, result);
  2014. out:
  2015. return error;
  2016. out_status:
  2017. return nfs3_stat_to_errno(status);
  2018. }
  2019. /*
  2020. * 3.3.19 FSINFO3res
  2021. *
  2022. * struct FSINFO3resok {
  2023. * post_op_attr obj_attributes;
  2024. * uint32 rtmax;
  2025. * uint32 rtpref;
  2026. * uint32 rtmult;
  2027. * uint32 wtmax;
  2028. * uint32 wtpref;
  2029. * uint32 wtmult;
  2030. * uint32 dtpref;
  2031. * size3 maxfilesize;
  2032. * nfstime3 time_delta;
  2033. * uint32 properties;
  2034. * };
  2035. *
  2036. * struct FSINFO3resfail {
  2037. * post_op_attr obj_attributes;
  2038. * };
  2039. *
  2040. * union FSINFO3res switch (nfsstat3 status) {
  2041. * case NFS3_OK:
  2042. * FSINFO3resok resok;
  2043. * default:
  2044. * FSINFO3resfail resfail;
  2045. * };
  2046. */
  2047. static int decode_fsinfo3resok(struct xdr_stream *xdr,
  2048. struct nfs_fsinfo *result)
  2049. {
  2050. __be32 *p;
  2051. p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4);
  2052. if (unlikely(p == NULL))
  2053. goto out_overflow;
  2054. result->rtmax = be32_to_cpup(p++);
  2055. result->rtpref = be32_to_cpup(p++);
  2056. result->rtmult = be32_to_cpup(p++);
  2057. result->wtmax = be32_to_cpup(p++);
  2058. result->wtpref = be32_to_cpup(p++);
  2059. result->wtmult = be32_to_cpup(p++);
  2060. result->dtpref = be32_to_cpup(p++);
  2061. p = xdr_decode_size3(p, &result->maxfilesize);
  2062. xdr_decode_nfstime3(p, &result->time_delta);
  2063. /* ignore properties */
  2064. result->lease_time = 0;
  2065. return 0;
  2066. out_overflow:
  2067. print_overflow_msg(__func__, xdr);
  2068. return -EIO;
  2069. }
  2070. static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
  2071. struct xdr_stream *xdr,
  2072. void *data)
  2073. {
  2074. struct nfs_fsinfo *result = data;
  2075. enum nfs_stat status;
  2076. int error;
  2077. error = decode_nfsstat3(xdr, &status);
  2078. if (unlikely(error))
  2079. goto out;
  2080. error = decode_post_op_attr(xdr, result->fattr);
  2081. if (unlikely(error))
  2082. goto out;
  2083. if (status != NFS3_OK)
  2084. goto out_status;
  2085. error = decode_fsinfo3resok(xdr, result);
  2086. out:
  2087. return error;
  2088. out_status:
  2089. return nfs3_stat_to_errno(status);
  2090. }
  2091. /*
  2092. * 3.3.20 PATHCONF3res
  2093. *
  2094. * struct PATHCONF3resok {
  2095. * post_op_attr obj_attributes;
  2096. * uint32 linkmax;
  2097. * uint32 name_max;
  2098. * bool no_trunc;
  2099. * bool chown_restricted;
  2100. * bool case_insensitive;
  2101. * bool case_preserving;
  2102. * };
  2103. *
  2104. * struct PATHCONF3resfail {
  2105. * post_op_attr obj_attributes;
  2106. * };
  2107. *
  2108. * union PATHCONF3res switch (nfsstat3 status) {
  2109. * case NFS3_OK:
  2110. * PATHCONF3resok resok;
  2111. * default:
  2112. * PATHCONF3resfail resfail;
  2113. * };
  2114. */
  2115. static int decode_pathconf3resok(struct xdr_stream *xdr,
  2116. struct nfs_pathconf *result)
  2117. {
  2118. __be32 *p;
  2119. p = xdr_inline_decode(xdr, 4 * 6);
  2120. if (unlikely(p == NULL))
  2121. goto out_overflow;
  2122. result->max_link = be32_to_cpup(p++);
  2123. result->max_namelen = be32_to_cpup(p);
  2124. /* ignore remaining fields */
  2125. return 0;
  2126. out_overflow:
  2127. print_overflow_msg(__func__, xdr);
  2128. return -EIO;
  2129. }
  2130. static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
  2131. struct xdr_stream *xdr,
  2132. void *data)
  2133. {
  2134. struct nfs_pathconf *result = data;
  2135. enum nfs_stat status;
  2136. int error;
  2137. error = decode_nfsstat3(xdr, &status);
  2138. if (unlikely(error))
  2139. goto out;
  2140. error = decode_post_op_attr(xdr, result->fattr);
  2141. if (unlikely(error))
  2142. goto out;
  2143. if (status != NFS3_OK)
  2144. goto out_status;
  2145. error = decode_pathconf3resok(xdr, result);
  2146. out:
  2147. return error;
  2148. out_status:
  2149. return nfs3_stat_to_errno(status);
  2150. }
  2151. /*
  2152. * 3.3.21 COMMIT3res
  2153. *
  2154. * struct COMMIT3resok {
  2155. * wcc_data file_wcc;
  2156. * writeverf3 verf;
  2157. * };
  2158. *
  2159. * struct COMMIT3resfail {
  2160. * wcc_data file_wcc;
  2161. * };
  2162. *
  2163. * union COMMIT3res switch (nfsstat3 status) {
  2164. * case NFS3_OK:
  2165. * COMMIT3resok resok;
  2166. * default:
  2167. * COMMIT3resfail resfail;
  2168. * };
  2169. */
  2170. static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
  2171. struct xdr_stream *xdr,
  2172. void *data)
  2173. {
  2174. struct nfs_commitres *result = data;
  2175. enum nfs_stat status;
  2176. int error;
  2177. error = decode_nfsstat3(xdr, &status);
  2178. if (unlikely(error))
  2179. goto out;
  2180. error = decode_wcc_data(xdr, result->fattr);
  2181. if (unlikely(error))
  2182. goto out;
  2183. result->op_status = status;
  2184. if (status != NFS3_OK)
  2185. goto out_status;
  2186. error = decode_writeverf3(xdr, &result->verf->verifier);
  2187. out:
  2188. return error;
  2189. out_status:
  2190. return nfs3_stat_to_errno(status);
  2191. }
  2192. #ifdef CONFIG_NFS_V3_ACL
  2193. static inline int decode_getacl3resok(struct xdr_stream *xdr,
  2194. struct nfs3_getaclres *result)
  2195. {
  2196. struct posix_acl **acl;
  2197. unsigned int *aclcnt;
  2198. size_t hdrlen;
  2199. int error;
  2200. error = decode_post_op_attr(xdr, result->fattr);
  2201. if (unlikely(error))
  2202. goto out;
  2203. error = decode_uint32(xdr, &result->mask);
  2204. if (unlikely(error))
  2205. goto out;
  2206. error = -EINVAL;
  2207. if (result->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
  2208. goto out;
  2209. hdrlen = xdr_stream_pos(xdr);
  2210. acl = NULL;
  2211. if (result->mask & NFS_ACL)
  2212. acl = &result->acl_access;
  2213. aclcnt = NULL;
  2214. if (result->mask & NFS_ACLCNT)
  2215. aclcnt = &result->acl_access_count;
  2216. error = nfsacl_decode(xdr->buf, hdrlen, aclcnt, acl);
  2217. if (unlikely(error <= 0))
  2218. goto out;
  2219. acl = NULL;
  2220. if (result->mask & NFS_DFACL)
  2221. acl = &result->acl_default;
  2222. aclcnt = NULL;
  2223. if (result->mask & NFS_DFACLCNT)
  2224. aclcnt = &result->acl_default_count;
  2225. error = nfsacl_decode(xdr->buf, hdrlen + error, aclcnt, acl);
  2226. if (unlikely(error <= 0))
  2227. return error;
  2228. error = 0;
  2229. out:
  2230. return error;
  2231. }
  2232. static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
  2233. struct xdr_stream *xdr,
  2234. void *result)
  2235. {
  2236. enum nfs_stat status;
  2237. int error;
  2238. error = decode_nfsstat3(xdr, &status);
  2239. if (unlikely(error))
  2240. goto out;
  2241. if (status != NFS3_OK)
  2242. goto out_default;
  2243. error = decode_getacl3resok(xdr, result);
  2244. out:
  2245. return error;
  2246. out_default:
  2247. return nfs3_stat_to_errno(status);
  2248. }
  2249. static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
  2250. struct xdr_stream *xdr,
  2251. void *result)
  2252. {
  2253. enum nfs_stat status;
  2254. int error;
  2255. error = decode_nfsstat3(xdr, &status);
  2256. if (unlikely(error))
  2257. goto out;
  2258. if (status != NFS3_OK)
  2259. goto out_default;
  2260. error = decode_post_op_attr(xdr, result);
  2261. out:
  2262. return error;
  2263. out_default:
  2264. return nfs3_stat_to_errno(status);
  2265. }
  2266. #endif /* CONFIG_NFS_V3_ACL */
  2267. /*
  2268. * We need to translate between nfs status return values and
  2269. * the local errno values which may not be the same.
  2270. */
  2271. static const struct {
  2272. int stat;
  2273. int errno;
  2274. } nfs_errtbl[] = {
  2275. { NFS_OK, 0 },
  2276. { NFSERR_PERM, -EPERM },
  2277. { NFSERR_NOENT, -ENOENT },
  2278. { NFSERR_IO, -errno_NFSERR_IO},
  2279. { NFSERR_NXIO, -ENXIO },
  2280. /* { NFSERR_EAGAIN, -EAGAIN }, */
  2281. { NFSERR_ACCES, -EACCES },
  2282. { NFSERR_EXIST, -EEXIST },
  2283. { NFSERR_XDEV, -EXDEV },
  2284. { NFSERR_NODEV, -ENODEV },
  2285. { NFSERR_NOTDIR, -ENOTDIR },
  2286. { NFSERR_ISDIR, -EISDIR },
  2287. { NFSERR_INVAL, -EINVAL },
  2288. { NFSERR_FBIG, -EFBIG },
  2289. { NFSERR_NOSPC, -ENOSPC },
  2290. { NFSERR_ROFS, -EROFS },
  2291. { NFSERR_MLINK, -EMLINK },
  2292. { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
  2293. { NFSERR_NOTEMPTY, -ENOTEMPTY },
  2294. { NFSERR_DQUOT, -EDQUOT },
  2295. { NFSERR_STALE, -ESTALE },
  2296. { NFSERR_REMOTE, -EREMOTE },
  2297. #ifdef EWFLUSH
  2298. { NFSERR_WFLUSH, -EWFLUSH },
  2299. #endif
  2300. { NFSERR_BADHANDLE, -EBADHANDLE },
  2301. { NFSERR_NOT_SYNC, -ENOTSYNC },
  2302. { NFSERR_BAD_COOKIE, -EBADCOOKIE },
  2303. { NFSERR_NOTSUPP, -ENOTSUPP },
  2304. { NFSERR_TOOSMALL, -ETOOSMALL },
  2305. { NFSERR_SERVERFAULT, -EREMOTEIO },
  2306. { NFSERR_BADTYPE, -EBADTYPE },
  2307. { NFSERR_JUKEBOX, -EJUKEBOX },
  2308. { -1, -EIO }
  2309. };
  2310. /**
  2311. * nfs3_stat_to_errno - convert an NFS status code to a local errno
  2312. * @status: NFS status code to convert
  2313. *
  2314. * Returns a local errno value, or -EIO if the NFS status code is
  2315. * not recognized. This function is used jointly by NFSv2 and NFSv3.
  2316. */
  2317. static int nfs3_stat_to_errno(enum nfs_stat status)
  2318. {
  2319. int i;
  2320. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  2321. if (nfs_errtbl[i].stat == (int)status)
  2322. return nfs_errtbl[i].errno;
  2323. }
  2324. dprintk("NFS: Unrecognized nfs status value: %u\n", status);
  2325. return nfs_errtbl[i].errno;
  2326. }
  2327. #define PROC(proc, argtype, restype, timer) \
  2328. [NFS3PROC_##proc] = { \
  2329. .p_proc = NFS3PROC_##proc, \
  2330. .p_encode = nfs3_xdr_enc_##argtype##3args, \
  2331. .p_decode = nfs3_xdr_dec_##restype##3res, \
  2332. .p_arglen = NFS3_##argtype##args_sz, \
  2333. .p_replen = NFS3_##restype##res_sz, \
  2334. .p_timer = timer, \
  2335. .p_statidx = NFS3PROC_##proc, \
  2336. .p_name = #proc, \
  2337. }
  2338. const struct rpc_procinfo nfs3_procedures[] = {
  2339. PROC(GETATTR, getattr, getattr, 1),
  2340. PROC(SETATTR, setattr, setattr, 0),
  2341. PROC(LOOKUP, lookup, lookup, 2),
  2342. PROC(ACCESS, access, access, 1),
  2343. PROC(READLINK, readlink, readlink, 3),
  2344. PROC(READ, read, read, 3),
  2345. PROC(WRITE, write, write, 4),
  2346. PROC(CREATE, create, create, 0),
  2347. PROC(MKDIR, mkdir, create, 0),
  2348. PROC(SYMLINK, symlink, create, 0),
  2349. PROC(MKNOD, mknod, create, 0),
  2350. PROC(REMOVE, remove, remove, 0),
  2351. PROC(RMDIR, lookup, setattr, 0),
  2352. PROC(RENAME, rename, rename, 0),
  2353. PROC(LINK, link, link, 0),
  2354. PROC(READDIR, readdir, readdir, 3),
  2355. PROC(READDIRPLUS, readdirplus, readdir, 3),
  2356. PROC(FSSTAT, getattr, fsstat, 0),
  2357. PROC(FSINFO, getattr, fsinfo, 0),
  2358. PROC(PATHCONF, getattr, pathconf, 0),
  2359. PROC(COMMIT, commit, commit, 5),
  2360. };
  2361. static unsigned int nfs_version3_counts[ARRAY_SIZE(nfs3_procedures)];
  2362. const struct rpc_version nfs_version3 = {
  2363. .number = 3,
  2364. .nrprocs = ARRAY_SIZE(nfs3_procedures),
  2365. .procs = nfs3_procedures,
  2366. .counts = nfs_version3_counts,
  2367. };
  2368. #ifdef CONFIG_NFS_V3_ACL
  2369. static const struct rpc_procinfo nfs3_acl_procedures[] = {
  2370. [ACLPROC3_GETACL] = {
  2371. .p_proc = ACLPROC3_GETACL,
  2372. .p_encode = nfs3_xdr_enc_getacl3args,
  2373. .p_decode = nfs3_xdr_dec_getacl3res,
  2374. .p_arglen = ACL3_getaclargs_sz,
  2375. .p_replen = ACL3_getaclres_sz,
  2376. .p_timer = 1,
  2377. .p_name = "GETACL",
  2378. },
  2379. [ACLPROC3_SETACL] = {
  2380. .p_proc = ACLPROC3_SETACL,
  2381. .p_encode = nfs3_xdr_enc_setacl3args,
  2382. .p_decode = nfs3_xdr_dec_setacl3res,
  2383. .p_arglen = ACL3_setaclargs_sz,
  2384. .p_replen = ACL3_setaclres_sz,
  2385. .p_timer = 0,
  2386. .p_name = "SETACL",
  2387. },
  2388. };
  2389. static unsigned int nfs3_acl_counts[ARRAY_SIZE(nfs3_acl_procedures)];
  2390. const struct rpc_version nfsacl_version3 = {
  2391. .number = 3,
  2392. .nrprocs = ARRAY_SIZE(nfs3_acl_procedures),
  2393. .procs = nfs3_acl_procedures,
  2394. .counts = nfs3_acl_counts,
  2395. };
  2396. #endif /* CONFIG_NFS_V3_ACL */