PageRenderTime 51ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/fs/nfs/nfs3xdr.c

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