PageRenderTime 58ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/fs/nfs/nfs3xdr.c

https://bitbucket.org/emiliolopez/linux
C | 2619 lines | 1530 code | 235 blank | 854 comment | 202 complexity | a835e2644dce104062f9300ac141c121 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

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

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

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