1 // SPDX-License-Identifier: GPL-2.0
3 * linux/fs/nfs/nfs3xdr.c
5 * XDR functions to encode/decode NFSv3 RPC arguments and results.
7 * Copyright (C) 1996, 1997 Olaf Kirch
10 #include <linux/param.h>
11 #include <linux/time.h>
13 #include <linux/errno.h>
14 #include <linux/string.h>
16 #include <linux/pagemap.h>
17 #include <linux/proc_fs.h>
18 #include <linux/kdev_t.h>
19 #include <linux/sunrpc/clnt.h>
20 #include <linux/nfs.h>
21 #include <linux/nfs3.h>
22 #include <linux/nfs_fs.h>
23 #include <linux/nfsacl.h>
26 #define NFSDBG_FACILITY NFSDBG_XDR
28 /* Mapping from NFS error code to "errno" error code. */
29 #define errno_NFSERR_IO EIO
32 * Declare the space requirements for NFS arguments and replies as
33 * number of 32bit-words
35 #define NFS3_fhandle_sz (1+16)
36 #define NFS3_fh_sz (NFS3_fhandle_sz) /* shorthand */
37 #define NFS3_post_op_fh_sz (1+NFS3_fh_sz)
38 #define NFS3_sattr_sz (15)
39 #define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2))
40 #define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2))
41 #define NFS3_fattr_sz (21)
42 #define NFS3_cookieverf_sz (NFS3_COOKIEVERFSIZE>>2)
43 #define NFS3_wcc_attr_sz (6)
44 #define NFS3_pre_op_attr_sz (1+NFS3_wcc_attr_sz)
45 #define NFS3_post_op_attr_sz (1+NFS3_fattr_sz)
46 #define NFS3_wcc_data_sz (NFS3_pre_op_attr_sz+NFS3_post_op_attr_sz)
47 #define NFS3_diropargs_sz (NFS3_fh_sz+NFS3_filename_sz)
49 #define NFS3_getattrargs_sz (NFS3_fh_sz)
50 #define NFS3_setattrargs_sz (NFS3_fh_sz+NFS3_sattr_sz+3)
51 #define NFS3_lookupargs_sz (NFS3_fh_sz+NFS3_filename_sz)
52 #define NFS3_accessargs_sz (NFS3_fh_sz+1)
53 #define NFS3_readlinkargs_sz (NFS3_fh_sz)
54 #define NFS3_readargs_sz (NFS3_fh_sz+3)
55 #define NFS3_writeargs_sz (NFS3_fh_sz+5)
56 #define NFS3_createargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
57 #define NFS3_mkdirargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
58 #define NFS3_symlinkargs_sz (NFS3_diropargs_sz+1+NFS3_sattr_sz)
59 #define NFS3_mknodargs_sz (NFS3_diropargs_sz+2+NFS3_sattr_sz)
60 #define NFS3_removeargs_sz (NFS3_fh_sz+NFS3_filename_sz)
61 #define NFS3_renameargs_sz (NFS3_diropargs_sz+NFS3_diropargs_sz)
62 #define NFS3_linkargs_sz (NFS3_fh_sz+NFS3_diropargs_sz)
63 #define NFS3_readdirargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+3)
64 #define NFS3_readdirplusargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+4)
65 #define NFS3_commitargs_sz (NFS3_fh_sz+3)
67 #define NFS3_getattrres_sz (1+NFS3_fattr_sz)
68 #define NFS3_setattrres_sz (1+NFS3_wcc_data_sz)
69 #define NFS3_removeres_sz (NFS3_setattrres_sz)
70 #define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
71 #define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1)
72 #define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1)
73 #define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3)
74 #define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4)
75 #define NFS3_createres_sz (1+NFS3_post_op_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
76 #define NFS3_renameres_sz (1+(2 * NFS3_wcc_data_sz))
77 #define NFS3_linkres_sz (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
78 #define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2)
79 #define NFS3_fsstatres_sz (1+NFS3_post_op_attr_sz+13)
80 #define NFS3_fsinfores_sz (1+NFS3_post_op_attr_sz+12)
81 #define NFS3_pathconfres_sz (1+NFS3_post_op_attr_sz+6)
82 #define NFS3_commitres_sz (1+NFS3_wcc_data_sz+2)
84 #define ACL3_getaclargs_sz (NFS3_fh_sz+1)
85 #define ACL3_setaclargs_sz (NFS3_fh_sz+1+ \
86 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
87 #define ACL3_getaclres_sz (1+NFS3_post_op_attr_sz+1+ \
88 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
89 #define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
91 static int nfs3_stat_to_errno(enum nfs_stat);
94 * Map file type to S_IFMT bits
96 static const umode_t nfs_type2fmt[] = {
103 [NF3SOCK] = S_IFSOCK,
108 * While encoding arguments, set up the reply buffer in advance to
109 * receive reply data directly into the page cache.
111 static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages,
112 unsigned int base, unsigned int len,
113 unsigned int bufsize)
115 struct rpc_auth *auth = req->rq_cred->cr_auth;
118 replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize;
119 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len);
123 * Handle decode buffer overflows out-of-line.
125 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
127 dprintk("NFS: %s prematurely hit the end of our receive buffer. "
128 "Remaining buffer length is %tu words.\n",
129 func, xdr->end - xdr->p);
134 * Encode/decode NFSv3 basic data types
136 * Basic NFSv3 data types are defined in section 2.5 of RFC 1813:
137 * "NFS Version 3 Protocol Specification".
139 * Not all basic data types have their own encoding and decoding
140 * functions. For run-time efficiency, some data types are encoded
144 static void encode_uint32(struct xdr_stream *xdr, u32 value)
146 __be32 *p = xdr_reserve_space(xdr, 4);
147 *p = cpu_to_be32(value);
150 static int decode_uint32(struct xdr_stream *xdr, u32 *value)
154 p = xdr_inline_decode(xdr, 4);
155 if (unlikely(p == NULL))
157 *value = be32_to_cpup(p);
160 print_overflow_msg(__func__, xdr);
164 static int decode_uint64(struct xdr_stream *xdr, u64 *value)
168 p = xdr_inline_decode(xdr, 8);
169 if (unlikely(p == NULL))
171 xdr_decode_hyper(p, value);
174 print_overflow_msg(__func__, xdr);
181 * typedef uint64 fileid3;
183 static __be32 *xdr_decode_fileid3(__be32 *p, u64 *fileid)
185 return xdr_decode_hyper(p, fileid);
188 static int decode_fileid3(struct xdr_stream *xdr, u64 *fileid)
190 return decode_uint64(xdr, fileid);
196 * typedef string filename3<>;
198 static void encode_filename3(struct xdr_stream *xdr,
199 const char *name, u32 length)
203 WARN_ON_ONCE(length > NFS3_MAXNAMLEN);
204 p = xdr_reserve_space(xdr, 4 + length);
205 xdr_encode_opaque(p, name, length);
208 static int decode_inline_filename3(struct xdr_stream *xdr,
209 const char **name, u32 *length)
214 p = xdr_inline_decode(xdr, 4);
215 if (unlikely(p == NULL))
217 count = be32_to_cpup(p);
218 if (count > NFS3_MAXNAMLEN)
219 goto out_nametoolong;
220 p = xdr_inline_decode(xdr, count);
221 if (unlikely(p == NULL))
223 *name = (const char *)p;
228 dprintk("NFS: returned filename too long: %u\n", count);
229 return -ENAMETOOLONG;
231 print_overflow_msg(__func__, xdr);
238 * typedef string nfspath3<>;
240 static void encode_nfspath3(struct xdr_stream *xdr, struct page **pages,
243 encode_uint32(xdr, length);
244 xdr_write_pages(xdr, pages, 0, length);
247 static int decode_nfspath3(struct xdr_stream *xdr)
252 p = xdr_inline_decode(xdr, 4);
253 if (unlikely(p == NULL))
255 count = be32_to_cpup(p);
256 if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN))
257 goto out_nametoolong;
258 recvd = xdr_read_pages(xdr, count);
259 if (unlikely(count > recvd))
261 xdr_terminate_string(xdr->buf, count);
265 dprintk("NFS: returned pathname too long: %u\n", count);
266 return -ENAMETOOLONG;
268 dprintk("NFS: server cheating in pathname result: "
269 "count %u > recvd %u\n", count, recvd);
272 print_overflow_msg(__func__, xdr);
279 * typedef uint64 cookie3
281 static __be32 *xdr_encode_cookie3(__be32 *p, u64 cookie)
283 return xdr_encode_hyper(p, cookie);
286 static int decode_cookie3(struct xdr_stream *xdr, u64 *cookie)
288 return decode_uint64(xdr, cookie);
294 * typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
296 static __be32 *xdr_encode_cookieverf3(__be32 *p, const __be32 *verifier)
298 memcpy(p, verifier, NFS3_COOKIEVERFSIZE);
299 return p + XDR_QUADLEN(NFS3_COOKIEVERFSIZE);
302 static int decode_cookieverf3(struct xdr_stream *xdr, __be32 *verifier)
306 p = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE);
307 if (unlikely(p == NULL))
309 memcpy(verifier, p, NFS3_COOKIEVERFSIZE);
312 print_overflow_msg(__func__, xdr);
319 * typedef opaque createverf3[NFS3_CREATEVERFSIZE];
321 static void encode_createverf3(struct xdr_stream *xdr, const __be32 *verifier)
325 p = xdr_reserve_space(xdr, NFS3_CREATEVERFSIZE);
326 memcpy(p, verifier, NFS3_CREATEVERFSIZE);
329 static int decode_writeverf3(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
333 p = xdr_inline_decode(xdr, NFS3_WRITEVERFSIZE);
334 if (unlikely(p == NULL))
336 memcpy(verifier->data, p, NFS3_WRITEVERFSIZE);
339 print_overflow_msg(__func__, xdr);
346 * typedef uint64 size3;
348 static __be32 *xdr_decode_size3(__be32 *p, u64 *size)
350 return xdr_decode_hyper(p, size);
361 #define NFS3_OK NFS_OK
363 static int decode_nfsstat3(struct xdr_stream *xdr, enum nfs_stat *status)
367 p = xdr_inline_decode(xdr, 4);
368 if (unlikely(p == NULL))
370 *status = be32_to_cpup(p);
373 print_overflow_msg(__func__, xdr);
390 static void encode_ftype3(struct xdr_stream *xdr, const u32 type)
392 encode_uint32(xdr, type);
395 static __be32 *xdr_decode_ftype3(__be32 *p, umode_t *mode)
399 type = be32_to_cpup(p++);
402 *mode = nfs_type2fmt[type];
414 static void encode_specdata3(struct xdr_stream *xdr, const dev_t rdev)
418 p = xdr_reserve_space(xdr, 8);
419 *p++ = cpu_to_be32(MAJOR(rdev));
420 *p = cpu_to_be32(MINOR(rdev));
423 static __be32 *xdr_decode_specdata3(__be32 *p, dev_t *rdev)
425 unsigned int major, minor;
427 major = be32_to_cpup(p++);
428 minor = be32_to_cpup(p++);
429 *rdev = MKDEV(major, minor);
430 if (MAJOR(*rdev) != major || MINOR(*rdev) != minor)
439 * opaque data<NFS3_FHSIZE>;
442 static void encode_nfs_fh3(struct xdr_stream *xdr, const struct nfs_fh *fh)
446 WARN_ON_ONCE(fh->size > NFS3_FHSIZE);
447 p = xdr_reserve_space(xdr, 4 + fh->size);
448 xdr_encode_opaque(p, fh->data, fh->size);
451 static int decode_nfs_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
456 p = xdr_inline_decode(xdr, 4);
457 if (unlikely(p == NULL))
459 length = be32_to_cpup(p++);
460 if (unlikely(length > NFS3_FHSIZE))
462 p = xdr_inline_decode(xdr, length);
463 if (unlikely(p == NULL))
466 memcpy(fh->data, p, length);
469 dprintk("NFS: file handle size (%u) too big\n", length);
472 print_overflow_msg(__func__, xdr);
476 static void zero_nfs_fh3(struct nfs_fh *fh)
478 memset(fh, 0, sizeof(*fh));
489 static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec *timep)
491 *p++ = cpu_to_be32(timep->tv_sec);
492 *p++ = cpu_to_be32(timep->tv_nsec);
496 static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec *timep)
498 timep->tv_sec = be32_to_cpup(p++);
499 timep->tv_nsec = be32_to_cpup(p++);
508 * SET_TO_SERVER_TIME = 1,
509 * SET_TO_CLIENT_TIME = 2
512 * union set_mode3 switch (bool set_it) {
519 * union set_uid3 switch (bool set_it) {
526 * union set_gid3 switch (bool set_it) {
533 * union set_size3 switch (bool set_it) {
540 * union set_atime switch (time_how set_it) {
541 * case SET_TO_CLIENT_TIME:
547 * union set_mtime switch (time_how set_it) {
548 * case SET_TO_CLIENT_TIME:
563 static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
569 * In order to make only a single xdr_reserve_space() call,
570 * pre-compute the total number of bytes to be reserved.
571 * Six boolean values, one for each set_foo field, are always
572 * present in the encoded result, so start there.
575 if (attr->ia_valid & ATTR_MODE)
577 if (attr->ia_valid & ATTR_UID)
579 if (attr->ia_valid & ATTR_GID)
581 if (attr->ia_valid & ATTR_SIZE)
583 if (attr->ia_valid & ATTR_ATIME_SET)
585 if (attr->ia_valid & ATTR_MTIME_SET)
587 p = xdr_reserve_space(xdr, nbytes);
589 if (attr->ia_valid & ATTR_MODE) {
591 *p++ = cpu_to_be32(attr->ia_mode & S_IALLUGO);
595 if (attr->ia_valid & ATTR_UID) {
597 *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
601 if (attr->ia_valid & ATTR_GID) {
603 *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
607 if (attr->ia_valid & ATTR_SIZE) {
609 p = xdr_encode_hyper(p, (u64)attr->ia_size);
613 if (attr->ia_valid & ATTR_ATIME_SET) {
615 p = xdr_encode_nfstime3(p, &attr->ia_atime);
616 } else if (attr->ia_valid & ATTR_ATIME) {
621 if (attr->ia_valid & ATTR_MTIME_SET) {
623 xdr_encode_nfstime3(p, &attr->ia_mtime);
624 } else if (attr->ia_valid & ATTR_MTIME) {
649 static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr)
654 p = xdr_inline_decode(xdr, NFS3_fattr_sz << 2);
655 if (unlikely(p == NULL))
658 p = xdr_decode_ftype3(p, &fmode);
660 fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode;
661 fattr->nlink = be32_to_cpup(p++);
662 fattr->uid = make_kuid(&init_user_ns, be32_to_cpup(p++));
663 if (!uid_valid(fattr->uid))
665 fattr->gid = make_kgid(&init_user_ns, be32_to_cpup(p++));
666 if (!gid_valid(fattr->gid))
669 p = xdr_decode_size3(p, &fattr->size);
670 p = xdr_decode_size3(p, &fattr->du.nfs3.used);
671 p = xdr_decode_specdata3(p, &fattr->rdev);
673 p = xdr_decode_hyper(p, &fattr->fsid.major);
674 fattr->fsid.minor = 0;
676 p = xdr_decode_fileid3(p, &fattr->fileid);
677 p = xdr_decode_nfstime3(p, &fattr->atime);
678 p = xdr_decode_nfstime3(p, &fattr->mtime);
679 xdr_decode_nfstime3(p, &fattr->ctime);
680 fattr->change_attr = nfs_timespec_to_change_attr(&fattr->ctime);
682 fattr->valid |= NFS_ATTR_FATTR_V3;
685 dprintk("NFS: returned invalid uid\n");
688 dprintk("NFS: returned invalid gid\n");
691 print_overflow_msg(__func__, xdr);
698 * union post_op_attr switch (bool attributes_follow) {
705 static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
709 p = xdr_inline_decode(xdr, 4);
710 if (unlikely(p == NULL))
713 return decode_fattr3(xdr, fattr);
716 print_overflow_msg(__func__, xdr);
728 static int decode_wcc_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
732 p = xdr_inline_decode(xdr, NFS3_wcc_attr_sz << 2);
733 if (unlikely(p == NULL))
736 fattr->valid |= NFS_ATTR_FATTR_PRESIZE
737 | NFS_ATTR_FATTR_PRECHANGE
738 | NFS_ATTR_FATTR_PREMTIME
739 | NFS_ATTR_FATTR_PRECTIME;
741 p = xdr_decode_size3(p, &fattr->pre_size);
742 p = xdr_decode_nfstime3(p, &fattr->pre_mtime);
743 xdr_decode_nfstime3(p, &fattr->pre_ctime);
744 fattr->pre_change_attr = nfs_timespec_to_change_attr(&fattr->pre_ctime);
748 print_overflow_msg(__func__, xdr);
754 * union pre_op_attr switch (bool attributes_follow) {
756 * wcc_attr attributes;
764 * pre_op_attr before;
765 * post_op_attr after;
768 static int decode_pre_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
772 p = xdr_inline_decode(xdr, 4);
773 if (unlikely(p == NULL))
776 return decode_wcc_attr(xdr, fattr);
779 print_overflow_msg(__func__, xdr);
783 static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr)
787 error = decode_pre_op_attr(xdr, fattr);
790 error = decode_post_op_attr(xdr, fattr);
798 * union post_op_fh3 switch (bool handle_follows) {
805 static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
807 __be32 *p = xdr_inline_decode(xdr, 4);
808 if (unlikely(p == NULL))
811 return decode_nfs_fh3(xdr, fh);
815 print_overflow_msg(__func__, xdr);
822 * struct diropargs3 {
827 static void encode_diropargs3(struct xdr_stream *xdr, const struct nfs_fh *fh,
828 const char *name, u32 length)
830 encode_nfs_fh3(xdr, fh);
831 encode_filename3(xdr, name, length);
836 * NFSv3 XDR encode functions
838 * NFSv3 argument types are defined in section 3.3 of RFC 1813:
839 * "NFS Version 3 Protocol Specification".
845 * struct GETATTR3args {
849 static void nfs3_xdr_enc_getattr3args(struct rpc_rqst *req,
850 struct xdr_stream *xdr,
853 const struct nfs_fh *fh = data;
855 encode_nfs_fh3(xdr, fh);
861 * union sattrguard3 switch (bool check) {
863 * nfstime3 obj_ctime;
868 * struct SETATTR3args {
870 * sattr3 new_attributes;
874 static void encode_sattrguard3(struct xdr_stream *xdr,
875 const struct nfs3_sattrargs *args)
880 p = xdr_reserve_space(xdr, 4 + 8);
882 xdr_encode_nfstime3(p, &args->guardtime);
884 p = xdr_reserve_space(xdr, 4);
889 static void nfs3_xdr_enc_setattr3args(struct rpc_rqst *req,
890 struct xdr_stream *xdr,
893 const struct nfs3_sattrargs *args = data;
894 encode_nfs_fh3(xdr, args->fh);
895 encode_sattr3(xdr, args->sattr);
896 encode_sattrguard3(xdr, args);
902 * struct LOOKUP3args {
906 static void nfs3_xdr_enc_lookup3args(struct rpc_rqst *req,
907 struct xdr_stream *xdr,
910 const struct nfs3_diropargs *args = data;
912 encode_diropargs3(xdr, args->fh, args->name, args->len);
918 * struct ACCESS3args {
923 static void encode_access3args(struct xdr_stream *xdr,
924 const struct nfs3_accessargs *args)
926 encode_nfs_fh3(xdr, args->fh);
927 encode_uint32(xdr, args->access);
930 static void nfs3_xdr_enc_access3args(struct rpc_rqst *req,
931 struct xdr_stream *xdr,
934 const struct nfs3_accessargs *args = data;
936 encode_access3args(xdr, args);
940 * 3.3.5 READLINK3args
942 * struct READLINK3args {
946 static void nfs3_xdr_enc_readlink3args(struct rpc_rqst *req,
947 struct xdr_stream *xdr,
950 const struct nfs3_readlinkargs *args = data;
952 encode_nfs_fh3(xdr, args->fh);
953 prepare_reply_buffer(req, args->pages, args->pgbase,
954 args->pglen, NFS3_readlinkres_sz);
966 static void encode_read3args(struct xdr_stream *xdr,
967 const struct nfs_pgio_args *args)
971 encode_nfs_fh3(xdr, args->fh);
973 p = xdr_reserve_space(xdr, 8 + 4);
974 p = xdr_encode_hyper(p, args->offset);
975 *p = cpu_to_be32(args->count);
978 static void nfs3_xdr_enc_read3args(struct rpc_rqst *req,
979 struct xdr_stream *xdr,
982 const struct nfs_pgio_args *args = data;
984 encode_read3args(xdr, args);
985 prepare_reply_buffer(req, args->pages, args->pgbase,
986 args->count, NFS3_readres_sz);
987 req->rq_rcv_buf.flags |= XDRBUF_READ;
999 * struct WRITE3args {
1003 * stable_how stable;
1007 static void encode_write3args(struct xdr_stream *xdr,
1008 const struct nfs_pgio_args *args)
1012 encode_nfs_fh3(xdr, args->fh);
1014 p = xdr_reserve_space(xdr, 8 + 4 + 4 + 4);
1015 p = xdr_encode_hyper(p, args->offset);
1016 *p++ = cpu_to_be32(args->count);
1017 *p++ = cpu_to_be32(args->stable);
1018 *p = cpu_to_be32(args->count);
1019 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1022 static void nfs3_xdr_enc_write3args(struct rpc_rqst *req,
1023 struct xdr_stream *xdr,
1026 const struct nfs_pgio_args *args = data;
1028 encode_write3args(xdr, args);
1029 xdr->buf->flags |= XDRBUF_WRITE;
1035 * enum createmode3 {
1041 * union createhow3 switch (createmode3 mode) {
1044 * sattr3 obj_attributes;
1049 * struct CREATE3args {
1054 static void encode_createhow3(struct xdr_stream *xdr,
1055 const struct nfs3_createargs *args)
1057 encode_uint32(xdr, args->createmode);
1058 switch (args->createmode) {
1059 case NFS3_CREATE_UNCHECKED:
1060 case NFS3_CREATE_GUARDED:
1061 encode_sattr3(xdr, args->sattr);
1063 case NFS3_CREATE_EXCLUSIVE:
1064 encode_createverf3(xdr, args->verifier);
1071 static void nfs3_xdr_enc_create3args(struct rpc_rqst *req,
1072 struct xdr_stream *xdr,
1075 const struct nfs3_createargs *args = data;
1077 encode_diropargs3(xdr, args->fh, args->name, args->len);
1078 encode_createhow3(xdr, args);
1084 * struct MKDIR3args {
1086 * sattr3 attributes;
1089 static void nfs3_xdr_enc_mkdir3args(struct rpc_rqst *req,
1090 struct xdr_stream *xdr,
1093 const struct nfs3_mkdirargs *args = data;
1095 encode_diropargs3(xdr, args->fh, args->name, args->len);
1096 encode_sattr3(xdr, args->sattr);
1100 * 3.3.10 SYMLINK3args
1102 * struct symlinkdata3 {
1103 * sattr3 symlink_attributes;
1104 * nfspath3 symlink_data;
1107 * struct SYMLINK3args {
1109 * symlinkdata3 symlink;
1112 static void encode_symlinkdata3(struct xdr_stream *xdr,
1115 const struct nfs3_symlinkargs *args = data;
1117 encode_sattr3(xdr, args->sattr);
1118 encode_nfspath3(xdr, args->pages, args->pathlen);
1121 static void nfs3_xdr_enc_symlink3args(struct rpc_rqst *req,
1122 struct xdr_stream *xdr,
1125 const struct nfs3_symlinkargs *args = data;
1127 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
1128 encode_symlinkdata3(xdr, args);
1129 xdr->buf->flags |= XDRBUF_WRITE;
1135 * struct devicedata3 {
1136 * sattr3 dev_attributes;
1140 * union mknoddata3 switch (ftype3 type) {
1143 * devicedata3 device;
1146 * sattr3 pipe_attributes;
1151 * struct MKNOD3args {
1156 static void encode_devicedata3(struct xdr_stream *xdr,
1157 const struct nfs3_mknodargs *args)
1159 encode_sattr3(xdr, args->sattr);
1160 encode_specdata3(xdr, args->rdev);
1163 static void encode_mknoddata3(struct xdr_stream *xdr,
1164 const struct nfs3_mknodargs *args)
1166 encode_ftype3(xdr, args->type);
1167 switch (args->type) {
1170 encode_devicedata3(xdr, args);
1174 encode_sattr3(xdr, args->sattr);
1184 static void nfs3_xdr_enc_mknod3args(struct rpc_rqst *req,
1185 struct xdr_stream *xdr,
1188 const struct nfs3_mknodargs *args = data;
1190 encode_diropargs3(xdr, args->fh, args->name, args->len);
1191 encode_mknoddata3(xdr, args);
1195 * 3.3.12 REMOVE3args
1197 * struct REMOVE3args {
1198 * diropargs3 object;
1201 static void nfs3_xdr_enc_remove3args(struct rpc_rqst *req,
1202 struct xdr_stream *xdr,
1205 const struct nfs_removeargs *args = data;
1207 encode_diropargs3(xdr, args->fh, args->name.name, args->name.len);
1211 * 3.3.14 RENAME3args
1213 * struct RENAME3args {
1218 static void nfs3_xdr_enc_rename3args(struct rpc_rqst *req,
1219 struct xdr_stream *xdr,
1222 const struct nfs_renameargs *args = data;
1223 const struct qstr *old = args->old_name;
1224 const struct qstr *new = args->new_name;
1226 encode_diropargs3(xdr, args->old_dir, old->name, old->len);
1227 encode_diropargs3(xdr, args->new_dir, new->name, new->len);
1233 * struct LINK3args {
1238 static void nfs3_xdr_enc_link3args(struct rpc_rqst *req,
1239 struct xdr_stream *xdr,
1242 const struct nfs3_linkargs *args = data;
1244 encode_nfs_fh3(xdr, args->fromfh);
1245 encode_diropargs3(xdr, args->tofh, args->toname, args->tolen);
1249 * 3.3.16 READDIR3args
1251 * struct READDIR3args {
1254 * cookieverf3 cookieverf;
1258 static void encode_readdir3args(struct xdr_stream *xdr,
1259 const struct nfs3_readdirargs *args)
1263 encode_nfs_fh3(xdr, args->fh);
1265 p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4);
1266 p = xdr_encode_cookie3(p, args->cookie);
1267 p = xdr_encode_cookieverf3(p, args->verf);
1268 *p = cpu_to_be32(args->count);
1271 static void nfs3_xdr_enc_readdir3args(struct rpc_rqst *req,
1272 struct xdr_stream *xdr,
1275 const struct nfs3_readdirargs *args = data;
1277 encode_readdir3args(xdr, args);
1278 prepare_reply_buffer(req, args->pages, 0,
1279 args->count, NFS3_readdirres_sz);
1283 * 3.3.17 READDIRPLUS3args
1285 * struct READDIRPLUS3args {
1288 * cookieverf3 cookieverf;
1293 static void encode_readdirplus3args(struct xdr_stream *xdr,
1294 const struct nfs3_readdirargs *args)
1298 encode_nfs_fh3(xdr, args->fh);
1300 p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4 + 4);
1301 p = xdr_encode_cookie3(p, args->cookie);
1302 p = xdr_encode_cookieverf3(p, args->verf);
1305 * readdirplus: need dircount + buffer size.
1306 * We just make sure we make dircount big enough
1308 *p++ = cpu_to_be32(args->count >> 3);
1310 *p = cpu_to_be32(args->count);
1313 static void nfs3_xdr_enc_readdirplus3args(struct rpc_rqst *req,
1314 struct xdr_stream *xdr,
1317 const struct nfs3_readdirargs *args = data;
1319 encode_readdirplus3args(xdr, args);
1320 prepare_reply_buffer(req, args->pages, 0,
1321 args->count, NFS3_readdirres_sz);
1325 * 3.3.21 COMMIT3args
1327 * struct COMMIT3args {
1333 static void encode_commit3args(struct xdr_stream *xdr,
1334 const struct nfs_commitargs *args)
1338 encode_nfs_fh3(xdr, args->fh);
1340 p = xdr_reserve_space(xdr, 8 + 4);
1341 p = xdr_encode_hyper(p, args->offset);
1342 *p = cpu_to_be32(args->count);
1345 static void nfs3_xdr_enc_commit3args(struct rpc_rqst *req,
1346 struct xdr_stream *xdr,
1349 const struct nfs_commitargs *args = data;
1351 encode_commit3args(xdr, args);
1354 #ifdef CONFIG_NFS_V3_ACL
1356 static void nfs3_xdr_enc_getacl3args(struct rpc_rqst *req,
1357 struct xdr_stream *xdr,
1360 const struct nfs3_getaclargs *args = data;
1362 encode_nfs_fh3(xdr, args->fh);
1363 encode_uint32(xdr, args->mask);
1364 if (args->mask & (NFS_ACL | NFS_DFACL))
1365 prepare_reply_buffer(req, args->pages, 0,
1366 NFSACL_MAXPAGES << PAGE_SHIFT,
1370 static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req,
1371 struct xdr_stream *xdr,
1374 const struct nfs3_setaclargs *args = data;
1378 encode_nfs_fh3(xdr, NFS_FH(args->inode));
1379 encode_uint32(xdr, args->mask);
1381 base = req->rq_slen;
1382 if (args->npages != 0)
1383 xdr_write_pages(xdr, args->pages, 0, args->len);
1385 xdr_reserve_space(xdr, args->len);
1387 error = nfsacl_encode(xdr->buf, base, args->inode,
1388 (args->mask & NFS_ACL) ?
1389 args->acl_access : NULL, 1, 0);
1390 /* FIXME: this is just broken */
1392 error = nfsacl_encode(xdr->buf, base + error, args->inode,
1393 (args->mask & NFS_DFACL) ?
1394 args->acl_default : NULL, 1,
1399 #endif /* CONFIG_NFS_V3_ACL */
1402 * NFSv3 XDR decode functions
1404 * NFSv3 result types are defined in section 3.3 of RFC 1813:
1405 * "NFS Version 3 Protocol Specification".
1411 * struct GETATTR3resok {
1412 * fattr3 obj_attributes;
1415 * union GETATTR3res switch (nfsstat3 status) {
1417 * GETATTR3resok resok;
1422 static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
1423 struct xdr_stream *xdr,
1426 enum nfs_stat status;
1429 error = decode_nfsstat3(xdr, &status);
1430 if (unlikely(error))
1432 if (status != NFS3_OK)
1434 error = decode_fattr3(xdr, result);
1438 return nfs3_stat_to_errno(status);
1444 * struct SETATTR3resok {
1448 * struct SETATTR3resfail {
1452 * union SETATTR3res switch (nfsstat3 status) {
1454 * SETATTR3resok resok;
1456 * SETATTR3resfail resfail;
1459 static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
1460 struct xdr_stream *xdr,
1463 enum nfs_stat status;
1466 error = decode_nfsstat3(xdr, &status);
1467 if (unlikely(error))
1469 error = decode_wcc_data(xdr, result);
1470 if (unlikely(error))
1472 if (status != NFS3_OK)
1477 return nfs3_stat_to_errno(status);
1483 * struct LOOKUP3resok {
1485 * post_op_attr obj_attributes;
1486 * post_op_attr dir_attributes;
1489 * struct LOOKUP3resfail {
1490 * post_op_attr dir_attributes;
1493 * union LOOKUP3res switch (nfsstat3 status) {
1495 * LOOKUP3resok resok;
1497 * LOOKUP3resfail resfail;
1500 static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req,
1501 struct xdr_stream *xdr,
1504 struct nfs3_diropres *result = data;
1505 enum nfs_stat status;
1508 error = decode_nfsstat3(xdr, &status);
1509 if (unlikely(error))
1511 if (status != NFS3_OK)
1513 error = decode_nfs_fh3(xdr, result->fh);
1514 if (unlikely(error))
1516 error = decode_post_op_attr(xdr, result->fattr);
1517 if (unlikely(error))
1519 error = decode_post_op_attr(xdr, result->dir_attr);
1523 error = decode_post_op_attr(xdr, result->dir_attr);
1524 if (unlikely(error))
1526 return nfs3_stat_to_errno(status);
1532 * struct ACCESS3resok {
1533 * post_op_attr obj_attributes;
1537 * struct ACCESS3resfail {
1538 * post_op_attr obj_attributes;
1541 * union ACCESS3res switch (nfsstat3 status) {
1543 * ACCESS3resok resok;
1545 * ACCESS3resfail resfail;
1548 static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
1549 struct xdr_stream *xdr,
1552 struct nfs3_accessres *result = data;
1553 enum nfs_stat status;
1556 error = decode_nfsstat3(xdr, &status);
1557 if (unlikely(error))
1559 error = decode_post_op_attr(xdr, result->fattr);
1560 if (unlikely(error))
1562 if (status != NFS3_OK)
1564 error = decode_uint32(xdr, &result->access);
1568 return nfs3_stat_to_errno(status);
1572 * 3.3.5 READLINK3res
1574 * struct READLINK3resok {
1575 * post_op_attr symlink_attributes;
1579 * struct READLINK3resfail {
1580 * post_op_attr symlink_attributes;
1583 * union READLINK3res switch (nfsstat3 status) {
1585 * READLINK3resok resok;
1587 * READLINK3resfail resfail;
1590 static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
1591 struct xdr_stream *xdr,
1594 enum nfs_stat status;
1597 error = decode_nfsstat3(xdr, &status);
1598 if (unlikely(error))
1600 error = decode_post_op_attr(xdr, result);
1601 if (unlikely(error))
1603 if (status != NFS3_OK)
1605 error = decode_nfspath3(xdr);
1609 return nfs3_stat_to_errno(status);
1615 * struct READ3resok {
1616 * post_op_attr file_attributes;
1622 * struct READ3resfail {
1623 * post_op_attr file_attributes;
1626 * union READ3res switch (nfsstat3 status) {
1630 * READ3resfail resfail;
1633 static int decode_read3resok(struct xdr_stream *xdr,
1634 struct nfs_pgio_res *result)
1636 u32 eof, count, ocount, recvd;
1639 p = xdr_inline_decode(xdr, 4 + 4 + 4);
1640 if (unlikely(p == NULL))
1642 count = be32_to_cpup(p++);
1643 eof = be32_to_cpup(p++);
1644 ocount = be32_to_cpup(p++);
1645 if (unlikely(ocount != count))
1647 recvd = xdr_read_pages(xdr, count);
1648 if (unlikely(count > recvd))
1652 result->count = count;
1655 dprintk("NFS: READ count doesn't match length of opaque: "
1656 "count %u != ocount %u\n", count, ocount);
1659 dprintk("NFS: server cheating in read result: "
1660 "count %u > recvd %u\n", count, recvd);
1665 print_overflow_msg(__func__, xdr);
1669 static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1672 struct nfs_pgio_res *result = data;
1673 enum nfs_stat status;
1676 error = decode_nfsstat3(xdr, &status);
1677 if (unlikely(error))
1679 error = decode_post_op_attr(xdr, result->fattr);
1680 if (unlikely(error))
1682 result->op_status = status;
1683 if (status != NFS3_OK)
1685 error = decode_read3resok(xdr, result);
1689 return nfs3_stat_to_errno(status);
1701 * struct WRITE3resok {
1702 * wcc_data file_wcc;
1704 * stable_how committed;
1708 * struct WRITE3resfail {
1709 * wcc_data file_wcc;
1712 * union WRITE3res switch (nfsstat3 status) {
1714 * WRITE3resok resok;
1716 * WRITE3resfail resfail;
1719 static int decode_write3resok(struct xdr_stream *xdr,
1720 struct nfs_pgio_res *result)
1724 p = xdr_inline_decode(xdr, 4 + 4);
1725 if (unlikely(p == NULL))
1727 result->count = be32_to_cpup(p++);
1728 result->verf->committed = be32_to_cpup(p++);
1729 if (unlikely(result->verf->committed > NFS_FILE_SYNC))
1731 if (decode_writeverf3(xdr, &result->verf->verifier))
1733 return result->count;
1735 dprintk("NFS: bad stable_how value: %u\n", result->verf->committed);
1738 print_overflow_msg(__func__, xdr);
1743 static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1746 struct nfs_pgio_res *result = data;
1747 enum nfs_stat status;
1750 error = decode_nfsstat3(xdr, &status);
1751 if (unlikely(error))
1753 error = decode_wcc_data(xdr, result->fattr);
1754 if (unlikely(error))
1756 result->op_status = status;
1757 if (status != NFS3_OK)
1759 error = decode_write3resok(xdr, result);
1763 return nfs3_stat_to_errno(status);
1769 * struct CREATE3resok {
1771 * post_op_attr obj_attributes;
1775 * struct CREATE3resfail {
1779 * union CREATE3res switch (nfsstat3 status) {
1781 * CREATE3resok resok;
1783 * CREATE3resfail resfail;
1786 static int decode_create3resok(struct xdr_stream *xdr,
1787 struct nfs3_diropres *result)
1791 error = decode_post_op_fh3(xdr, result->fh);
1792 if (unlikely(error))
1794 error = decode_post_op_attr(xdr, result->fattr);
1795 if (unlikely(error))
1797 /* The server isn't required to return a file handle.
1798 * If it didn't, force the client to perform a LOOKUP
1799 * to determine the correct file handle and attribute
1800 * values for the new object. */
1801 if (result->fh->size == 0)
1802 result->fattr->valid = 0;
1803 error = decode_wcc_data(xdr, result->dir_attr);
1808 static int nfs3_xdr_dec_create3res(struct rpc_rqst *req,
1809 struct xdr_stream *xdr,
1812 struct nfs3_diropres *result = data;
1813 enum nfs_stat status;
1816 error = decode_nfsstat3(xdr, &status);
1817 if (unlikely(error))
1819 if (status != NFS3_OK)
1821 error = decode_create3resok(xdr, result);
1825 error = decode_wcc_data(xdr, result->dir_attr);
1826 if (unlikely(error))
1828 return nfs3_stat_to_errno(status);
1834 * struct REMOVE3resok {
1838 * struct REMOVE3resfail {
1842 * union REMOVE3res switch (nfsstat3 status) {
1844 * REMOVE3resok resok;
1846 * REMOVE3resfail resfail;
1849 static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
1850 struct xdr_stream *xdr,
1853 struct nfs_removeres *result = data;
1854 enum nfs_stat status;
1857 error = decode_nfsstat3(xdr, &status);
1858 if (unlikely(error))
1860 error = decode_wcc_data(xdr, result->dir_attr);
1861 if (unlikely(error))
1863 if (status != NFS3_OK)
1868 return nfs3_stat_to_errno(status);
1874 * struct RENAME3resok {
1875 * wcc_data fromdir_wcc;
1876 * wcc_data todir_wcc;
1879 * struct RENAME3resfail {
1880 * wcc_data fromdir_wcc;
1881 * wcc_data todir_wcc;
1884 * union RENAME3res switch (nfsstat3 status) {
1886 * RENAME3resok resok;
1888 * RENAME3resfail resfail;
1891 static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
1892 struct xdr_stream *xdr,
1895 struct nfs_renameres *result = data;
1896 enum nfs_stat status;
1899 error = decode_nfsstat3(xdr, &status);
1900 if (unlikely(error))
1902 error = decode_wcc_data(xdr, result->old_fattr);
1903 if (unlikely(error))
1905 error = decode_wcc_data(xdr, result->new_fattr);
1906 if (unlikely(error))
1908 if (status != NFS3_OK)
1913 return nfs3_stat_to_errno(status);
1919 * struct LINK3resok {
1920 * post_op_attr file_attributes;
1921 * wcc_data linkdir_wcc;
1924 * struct LINK3resfail {
1925 * post_op_attr file_attributes;
1926 * wcc_data linkdir_wcc;
1929 * union LINK3res switch (nfsstat3 status) {
1933 * LINK3resfail resfail;
1936 static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1939 struct nfs3_linkres *result = data;
1940 enum nfs_stat status;
1943 error = decode_nfsstat3(xdr, &status);
1944 if (unlikely(error))
1946 error = decode_post_op_attr(xdr, result->fattr);
1947 if (unlikely(error))
1949 error = decode_wcc_data(xdr, result->dir_attr);
1950 if (unlikely(error))
1952 if (status != NFS3_OK)
1957 return nfs3_stat_to_errno(status);
1961 * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in
1962 * the local page cache
1963 * @xdr: XDR stream where entry resides
1964 * @entry: buffer to fill in with entry data
1965 * @plus: boolean indicating whether this should be a readdirplus entry
1967 * Returns zero if successful, otherwise a negative errno value is
1970 * This function is not invoked during READDIR reply decoding, but
1971 * rather whenever an application invokes the getdents(2) system call
1972 * on a directory already in our cache.
1980 * fhandle3 filehandle;
1981 * post_op_attr3 attributes;
1982 * entry3 *nextentry;
1986 * struct entryplus3 {
1990 * post_op_attr name_attributes;
1991 * post_op_fh3 name_handle;
1992 * entryplus3 *nextentry;
1995 int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
1998 struct nfs_entry old = *entry;
2002 p = xdr_inline_decode(xdr, 4);
2003 if (unlikely(p == NULL))
2005 if (*p == xdr_zero) {
2006 p = xdr_inline_decode(xdr, 4);
2007 if (unlikely(p == NULL))
2015 error = decode_fileid3(xdr, &entry->ino);
2016 if (unlikely(error))
2019 error = decode_inline_filename3(xdr, &entry->name, &entry->len);
2020 if (unlikely(error))
2023 entry->prev_cookie = entry->cookie;
2024 error = decode_cookie3(xdr, &entry->cookie);
2025 if (unlikely(error))
2028 entry->d_type = DT_UNKNOWN;
2031 entry->fattr->valid = 0;
2032 error = decode_post_op_attr(xdr, entry->fattr);
2033 if (unlikely(error))
2035 if (entry->fattr->valid & NFS_ATTR_FATTR_V3)
2036 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
2038 if (entry->fattr->fileid != entry->ino) {
2039 entry->fattr->mounted_on_fileid = entry->ino;
2040 entry->fattr->valid |= NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
2043 /* In fact, a post_op_fh3: */
2044 p = xdr_inline_decode(xdr, 4);
2045 if (unlikely(p == NULL))
2047 if (*p != xdr_zero) {
2048 error = decode_nfs_fh3(xdr, entry->fh);
2049 if (unlikely(error)) {
2050 if (error == -E2BIG)
2055 zero_nfs_fh3(entry->fh);
2061 print_overflow_msg(__func__, xdr);
2064 dprintk("NFS: directory entry contains invalid file handle\n");
2070 * 3.3.16 READDIR3res
2077 * struct READDIR3resok {
2078 * post_op_attr dir_attributes;
2079 * cookieverf3 cookieverf;
2083 * struct READDIR3resfail {
2084 * post_op_attr dir_attributes;
2087 * union READDIR3res switch (nfsstat3 status) {
2089 * READDIR3resok resok;
2091 * READDIR3resfail resfail;
2094 * Read the directory contents into the page cache, but otherwise
2095 * don't touch them. The actual decoding is done by nfs3_decode_entry()
2096 * during subsequent nfs_readdir() calls.
2098 static int decode_dirlist3(struct xdr_stream *xdr)
2100 return xdr_read_pages(xdr, xdr->buf->page_len);
2103 static int decode_readdir3resok(struct xdr_stream *xdr,
2104 struct nfs3_readdirres *result)
2108 error = decode_post_op_attr(xdr, result->dir_attr);
2109 if (unlikely(error))
2111 /* XXX: do we need to check if result->verf != NULL ? */
2112 error = decode_cookieverf3(xdr, result->verf);
2113 if (unlikely(error))
2115 error = decode_dirlist3(xdr);
2120 static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req,
2121 struct xdr_stream *xdr,
2124 struct nfs3_readdirres *result = data;
2125 enum nfs_stat status;
2128 error = decode_nfsstat3(xdr, &status);
2129 if (unlikely(error))
2131 if (status != NFS3_OK)
2133 error = decode_readdir3resok(xdr, result);
2137 error = decode_post_op_attr(xdr, result->dir_attr);
2138 if (unlikely(error))
2140 return nfs3_stat_to_errno(status);
2146 * struct FSSTAT3resok {
2147 * post_op_attr obj_attributes;
2157 * struct FSSTAT3resfail {
2158 * post_op_attr obj_attributes;
2161 * union FSSTAT3res switch (nfsstat3 status) {
2163 * FSSTAT3resok resok;
2165 * FSSTAT3resfail resfail;
2168 static int decode_fsstat3resok(struct xdr_stream *xdr,
2169 struct nfs_fsstat *result)
2173 p = xdr_inline_decode(xdr, 8 * 6 + 4);
2174 if (unlikely(p == NULL))
2176 p = xdr_decode_size3(p, &result->tbytes);
2177 p = xdr_decode_size3(p, &result->fbytes);
2178 p = xdr_decode_size3(p, &result->abytes);
2179 p = xdr_decode_size3(p, &result->tfiles);
2180 p = xdr_decode_size3(p, &result->ffiles);
2181 xdr_decode_size3(p, &result->afiles);
2182 /* ignore invarsec */
2185 print_overflow_msg(__func__, xdr);
2189 static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
2190 struct xdr_stream *xdr,
2193 struct nfs_fsstat *result = data;
2194 enum nfs_stat status;
2197 error = decode_nfsstat3(xdr, &status);
2198 if (unlikely(error))
2200 error = decode_post_op_attr(xdr, result->fattr);
2201 if (unlikely(error))
2203 if (status != NFS3_OK)
2205 error = decode_fsstat3resok(xdr, result);
2209 return nfs3_stat_to_errno(status);
2215 * struct FSINFO3resok {
2216 * post_op_attr obj_attributes;
2224 * size3 maxfilesize;
2225 * nfstime3 time_delta;
2226 * uint32 properties;
2229 * struct FSINFO3resfail {
2230 * post_op_attr obj_attributes;
2233 * union FSINFO3res switch (nfsstat3 status) {
2235 * FSINFO3resok resok;
2237 * FSINFO3resfail resfail;
2240 static int decode_fsinfo3resok(struct xdr_stream *xdr,
2241 struct nfs_fsinfo *result)
2245 p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4);
2246 if (unlikely(p == NULL))
2248 result->rtmax = be32_to_cpup(p++);
2249 result->rtpref = be32_to_cpup(p++);
2250 result->rtmult = be32_to_cpup(p++);
2251 result->wtmax = be32_to_cpup(p++);
2252 result->wtpref = be32_to_cpup(p++);
2253 result->wtmult = be32_to_cpup(p++);
2254 result->dtpref = be32_to_cpup(p++);
2255 p = xdr_decode_size3(p, &result->maxfilesize);
2256 xdr_decode_nfstime3(p, &result->time_delta);
2258 /* ignore properties */
2259 result->lease_time = 0;
2262 print_overflow_msg(__func__, xdr);
2266 static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
2267 struct xdr_stream *xdr,
2270 struct nfs_fsinfo *result = data;
2271 enum nfs_stat status;
2274 error = decode_nfsstat3(xdr, &status);
2275 if (unlikely(error))
2277 error = decode_post_op_attr(xdr, result->fattr);
2278 if (unlikely(error))
2280 if (status != NFS3_OK)
2282 error = decode_fsinfo3resok(xdr, result);
2286 return nfs3_stat_to_errno(status);
2290 * 3.3.20 PATHCONF3res
2292 * struct PATHCONF3resok {
2293 * post_op_attr obj_attributes;
2297 * bool chown_restricted;
2298 * bool case_insensitive;
2299 * bool case_preserving;
2302 * struct PATHCONF3resfail {
2303 * post_op_attr obj_attributes;
2306 * union PATHCONF3res switch (nfsstat3 status) {
2308 * PATHCONF3resok resok;
2310 * PATHCONF3resfail resfail;
2313 static int decode_pathconf3resok(struct xdr_stream *xdr,
2314 struct nfs_pathconf *result)
2318 p = xdr_inline_decode(xdr, 4 * 6);
2319 if (unlikely(p == NULL))
2321 result->max_link = be32_to_cpup(p++);
2322 result->max_namelen = be32_to_cpup(p);
2323 /* ignore remaining fields */
2326 print_overflow_msg(__func__, xdr);
2330 static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
2331 struct xdr_stream *xdr,
2334 struct nfs_pathconf *result = data;
2335 enum nfs_stat status;
2338 error = decode_nfsstat3(xdr, &status);
2339 if (unlikely(error))
2341 error = decode_post_op_attr(xdr, result->fattr);
2342 if (unlikely(error))
2344 if (status != NFS3_OK)
2346 error = decode_pathconf3resok(xdr, result);
2350 return nfs3_stat_to_errno(status);
2356 * struct COMMIT3resok {
2357 * wcc_data file_wcc;
2361 * struct COMMIT3resfail {
2362 * wcc_data file_wcc;
2365 * union COMMIT3res switch (nfsstat3 status) {
2367 * COMMIT3resok resok;
2369 * COMMIT3resfail resfail;
2372 static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
2373 struct xdr_stream *xdr,
2376 struct nfs_commitres *result = data;
2377 struct nfs_writeverf *verf = result->verf;
2378 enum nfs_stat status;
2381 error = decode_nfsstat3(xdr, &status);
2382 if (unlikely(error))
2384 error = decode_wcc_data(xdr, result->fattr);
2385 if (unlikely(error))
2387 result->op_status = status;
2388 if (status != NFS3_OK)
2390 error = decode_writeverf3(xdr, &verf->verifier);
2392 verf->committed = NFS_FILE_SYNC;
2396 return nfs3_stat_to_errno(status);
2399 #ifdef CONFIG_NFS_V3_ACL
2401 static inline int decode_getacl3resok(struct xdr_stream *xdr,
2402 struct nfs3_getaclres *result)
2404 struct posix_acl **acl;
2405 unsigned int *aclcnt;
2409 error = decode_post_op_attr(xdr, result->fattr);
2410 if (unlikely(error))
2412 error = decode_uint32(xdr, &result->mask);
2413 if (unlikely(error))
2416 if (result->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
2419 hdrlen = xdr_stream_pos(xdr);
2422 if (result->mask & NFS_ACL)
2423 acl = &result->acl_access;
2425 if (result->mask & NFS_ACLCNT)
2426 aclcnt = &result->acl_access_count;
2427 error = nfsacl_decode(xdr->buf, hdrlen, aclcnt, acl);
2428 if (unlikely(error <= 0))
2432 if (result->mask & NFS_DFACL)
2433 acl = &result->acl_default;
2435 if (result->mask & NFS_DFACLCNT)
2436 aclcnt = &result->acl_default_count;
2437 error = nfsacl_decode(xdr->buf, hdrlen + error, aclcnt, acl);
2438 if (unlikely(error <= 0))
2445 static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
2446 struct xdr_stream *xdr,
2449 enum nfs_stat status;
2452 error = decode_nfsstat3(xdr, &status);
2453 if (unlikely(error))
2455 if (status != NFS3_OK)
2457 error = decode_getacl3resok(xdr, result);
2461 return nfs3_stat_to_errno(status);
2464 static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
2465 struct xdr_stream *xdr,
2468 enum nfs_stat status;
2471 error = decode_nfsstat3(xdr, &status);
2472 if (unlikely(error))
2474 if (status != NFS3_OK)
2476 error = decode_post_op_attr(xdr, result);
2480 return nfs3_stat_to_errno(status);
2483 #endif /* CONFIG_NFS_V3_ACL */
2487 * We need to translate between nfs status return values and
2488 * the local errno values which may not be the same.
2490 static const struct {
2495 { NFSERR_PERM, -EPERM },
2496 { NFSERR_NOENT, -ENOENT },
2497 { NFSERR_IO, -errno_NFSERR_IO},
2498 { NFSERR_NXIO, -ENXIO },
2499 /* { NFSERR_EAGAIN, -EAGAIN }, */
2500 { NFSERR_ACCES, -EACCES },
2501 { NFSERR_EXIST, -EEXIST },
2502 { NFSERR_XDEV, -EXDEV },
2503 { NFSERR_NODEV, -ENODEV },
2504 { NFSERR_NOTDIR, -ENOTDIR },
2505 { NFSERR_ISDIR, -EISDIR },
2506 { NFSERR_INVAL, -EINVAL },
2507 { NFSERR_FBIG, -EFBIG },
2508 { NFSERR_NOSPC, -ENOSPC },
2509 { NFSERR_ROFS, -EROFS },
2510 { NFSERR_MLINK, -EMLINK },
2511 { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
2512 { NFSERR_NOTEMPTY, -ENOTEMPTY },
2513 { NFSERR_DQUOT, -EDQUOT },
2514 { NFSERR_STALE, -ESTALE },
2515 { NFSERR_REMOTE, -EREMOTE },
2517 { NFSERR_WFLUSH, -EWFLUSH },
2519 { NFSERR_BADHANDLE, -EBADHANDLE },
2520 { NFSERR_NOT_SYNC, -ENOTSYNC },
2521 { NFSERR_BAD_COOKIE, -EBADCOOKIE },
2522 { NFSERR_NOTSUPP, -ENOTSUPP },
2523 { NFSERR_TOOSMALL, -ETOOSMALL },
2524 { NFSERR_SERVERFAULT, -EREMOTEIO },
2525 { NFSERR_BADTYPE, -EBADTYPE },
2526 { NFSERR_JUKEBOX, -EJUKEBOX },
2531 * nfs3_stat_to_errno - convert an NFS status code to a local errno
2532 * @status: NFS status code to convert
2534 * Returns a local errno value, or -EIO if the NFS status code is
2535 * not recognized. This function is used jointly by NFSv2 and NFSv3.
2537 static int nfs3_stat_to_errno(enum nfs_stat status)
2541 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
2542 if (nfs_errtbl[i].stat == (int)status)
2543 return nfs_errtbl[i].errno;
2545 dprintk("NFS: Unrecognized nfs status value: %u\n", status);
2546 return nfs_errtbl[i].errno;
2550 #define PROC(proc, argtype, restype, timer) \
2551 [NFS3PROC_##proc] = { \
2552 .p_proc = NFS3PROC_##proc, \
2553 .p_encode = nfs3_xdr_enc_##argtype##3args, \
2554 .p_decode = nfs3_xdr_dec_##restype##3res, \
2555 .p_arglen = NFS3_##argtype##args_sz, \
2556 .p_replen = NFS3_##restype##res_sz, \
2558 .p_statidx = NFS3PROC_##proc, \
2562 const struct rpc_procinfo nfs3_procedures[] = {
2563 PROC(GETATTR, getattr, getattr, 1),
2564 PROC(SETATTR, setattr, setattr, 0),
2565 PROC(LOOKUP, lookup, lookup, 2),
2566 PROC(ACCESS, access, access, 1),
2567 PROC(READLINK, readlink, readlink, 3),
2568 PROC(READ, read, read, 3),
2569 PROC(WRITE, write, write, 4),
2570 PROC(CREATE, create, create, 0),
2571 PROC(MKDIR, mkdir, create, 0),
2572 PROC(SYMLINK, symlink, create, 0),
2573 PROC(MKNOD, mknod, create, 0),
2574 PROC(REMOVE, remove, remove, 0),
2575 PROC(RMDIR, lookup, setattr, 0),
2576 PROC(RENAME, rename, rename, 0),
2577 PROC(LINK, link, link, 0),
2578 PROC(READDIR, readdir, readdir, 3),
2579 PROC(READDIRPLUS, readdirplus, readdir, 3),
2580 PROC(FSSTAT, getattr, fsstat, 0),
2581 PROC(FSINFO, getattr, fsinfo, 0),
2582 PROC(PATHCONF, getattr, pathconf, 0),
2583 PROC(COMMIT, commit, commit, 5),
2586 static unsigned int nfs_version3_counts[ARRAY_SIZE(nfs3_procedures)];
2587 const struct rpc_version nfs_version3 = {
2589 .nrprocs = ARRAY_SIZE(nfs3_procedures),
2590 .procs = nfs3_procedures,
2591 .counts = nfs_version3_counts,
2594 #ifdef CONFIG_NFS_V3_ACL
2595 static const struct rpc_procinfo nfs3_acl_procedures[] = {
2596 [ACLPROC3_GETACL] = {
2597 .p_proc = ACLPROC3_GETACL,
2598 .p_encode = nfs3_xdr_enc_getacl3args,
2599 .p_decode = nfs3_xdr_dec_getacl3res,
2600 .p_arglen = ACL3_getaclargs_sz,
2601 .p_replen = ACL3_getaclres_sz,
2605 [ACLPROC3_SETACL] = {
2606 .p_proc = ACLPROC3_SETACL,
2607 .p_encode = nfs3_xdr_enc_setacl3args,
2608 .p_decode = nfs3_xdr_dec_setacl3res,
2609 .p_arglen = ACL3_setaclargs_sz,
2610 .p_replen = ACL3_setaclres_sz,
2616 static unsigned int nfs3_acl_counts[ARRAY_SIZE(nfs3_acl_procedures)];
2617 const struct rpc_version nfsacl_version3 = {
2619 .nrprocs = ARRAY_SIZE(nfs3_acl_procedures),
2620 .procs = nfs3_acl_procedures,
2621 .counts = nfs3_acl_counts,
2623 #endif /* CONFIG_NFS_V3_ACL */