PageRenderTime 25ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/fs/nfs/nfs3xdr.c

https://bitbucket.org/digetx/picasso-kernel
C | 2546 lines | 1476 code | 217 blank | 853 comment | 198 complexity | f4f6c9ba0973f35e1312ba3031b74e1d MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file