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)
570 * In order to make only a single xdr_reserve_space() call,
571 * pre-compute the total number of bytes to be reserved.
572 * Six boolean values, one for each set_foo field, are always
573 * present in the encoded result, so start there.
576 if (attr->ia_valid & ATTR_MODE)
578 if (attr->ia_valid & ATTR_UID)
580 if (attr->ia_valid & ATTR_GID)
582 if (attr->ia_valid & ATTR_SIZE)
584 if (attr->ia_valid & ATTR_ATIME_SET)
586 if (attr->ia_valid & ATTR_MTIME_SET)
588 p = xdr_reserve_space(xdr, nbytes);
590 if (attr->ia_valid & ATTR_MODE) {
592 *p++ = cpu_to_be32(attr->ia_mode & S_IALLUGO);
596 if (attr->ia_valid & ATTR_UID) {
598 *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
602 if (attr->ia_valid & ATTR_GID) {
604 *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
608 if (attr->ia_valid & ATTR_SIZE) {
610 p = xdr_encode_hyper(p, (u64)attr->ia_size);
614 if (attr->ia_valid & ATTR_ATIME_SET) {
617 ts = timespec64_to_timespec(attr->ia_atime);
618 p = xdr_encode_nfstime3(p, &ts);
619 } else if (attr->ia_valid & ATTR_ATIME) {
624 if (attr->ia_valid & ATTR_MTIME_SET) {
626 ts = timespec64_to_timespec(attr->ia_mtime);
627 xdr_encode_nfstime3(p, &ts);
628 } else if (attr->ia_valid & ATTR_MTIME) {
653 static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr)
658 p = xdr_inline_decode(xdr, NFS3_fattr_sz << 2);
659 if (unlikely(p == NULL))
662 p = xdr_decode_ftype3(p, &fmode);
664 fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode;
665 fattr->nlink = be32_to_cpup(p++);
666 fattr->uid = make_kuid(&init_user_ns, be32_to_cpup(p++));
667 if (!uid_valid(fattr->uid))
669 fattr->gid = make_kgid(&init_user_ns, be32_to_cpup(p++));
670 if (!gid_valid(fattr->gid))
673 p = xdr_decode_size3(p, &fattr->size);
674 p = xdr_decode_size3(p, &fattr->du.nfs3.used);
675 p = xdr_decode_specdata3(p, &fattr->rdev);
677 p = xdr_decode_hyper(p, &fattr->fsid.major);
678 fattr->fsid.minor = 0;
680 p = xdr_decode_fileid3(p, &fattr->fileid);
681 p = xdr_decode_nfstime3(p, &fattr->atime);
682 p = xdr_decode_nfstime3(p, &fattr->mtime);
683 xdr_decode_nfstime3(p, &fattr->ctime);
684 fattr->change_attr = nfs_timespec_to_change_attr(&fattr->ctime);
686 fattr->valid |= NFS_ATTR_FATTR_V3;
689 dprintk("NFS: returned invalid uid\n");
692 dprintk("NFS: returned invalid gid\n");
695 print_overflow_msg(__func__, xdr);
702 * union post_op_attr switch (bool attributes_follow) {
709 static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
713 p = xdr_inline_decode(xdr, 4);
714 if (unlikely(p == NULL))
717 return decode_fattr3(xdr, fattr);
720 print_overflow_msg(__func__, xdr);
732 static int decode_wcc_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
736 p = xdr_inline_decode(xdr, NFS3_wcc_attr_sz << 2);
737 if (unlikely(p == NULL))
740 fattr->valid |= NFS_ATTR_FATTR_PRESIZE
741 | NFS_ATTR_FATTR_PRECHANGE
742 | NFS_ATTR_FATTR_PREMTIME
743 | NFS_ATTR_FATTR_PRECTIME;
745 p = xdr_decode_size3(p, &fattr->pre_size);
746 p = xdr_decode_nfstime3(p, &fattr->pre_mtime);
747 xdr_decode_nfstime3(p, &fattr->pre_ctime);
748 fattr->pre_change_attr = nfs_timespec_to_change_attr(&fattr->pre_ctime);
752 print_overflow_msg(__func__, xdr);
758 * union pre_op_attr switch (bool attributes_follow) {
760 * wcc_attr attributes;
768 * pre_op_attr before;
769 * post_op_attr after;
772 static int decode_pre_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
776 p = xdr_inline_decode(xdr, 4);
777 if (unlikely(p == NULL))
780 return decode_wcc_attr(xdr, fattr);
783 print_overflow_msg(__func__, xdr);
787 static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr)
791 error = decode_pre_op_attr(xdr, fattr);
794 error = decode_post_op_attr(xdr, fattr);
802 * union post_op_fh3 switch (bool handle_follows) {
809 static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
811 __be32 *p = xdr_inline_decode(xdr, 4);
812 if (unlikely(p == NULL))
815 return decode_nfs_fh3(xdr, fh);
819 print_overflow_msg(__func__, xdr);
826 * struct diropargs3 {
831 static void encode_diropargs3(struct xdr_stream *xdr, const struct nfs_fh *fh,
832 const char *name, u32 length)
834 encode_nfs_fh3(xdr, fh);
835 encode_filename3(xdr, name, length);
840 * NFSv3 XDR encode functions
842 * NFSv3 argument types are defined in section 3.3 of RFC 1813:
843 * "NFS Version 3 Protocol Specification".
849 * struct GETATTR3args {
853 static void nfs3_xdr_enc_getattr3args(struct rpc_rqst *req,
854 struct xdr_stream *xdr,
857 const struct nfs_fh *fh = data;
859 encode_nfs_fh3(xdr, fh);
865 * union sattrguard3 switch (bool check) {
867 * nfstime3 obj_ctime;
872 * struct SETATTR3args {
874 * sattr3 new_attributes;
878 static void encode_sattrguard3(struct xdr_stream *xdr,
879 const struct nfs3_sattrargs *args)
884 p = xdr_reserve_space(xdr, 4 + 8);
886 xdr_encode_nfstime3(p, &args->guardtime);
888 p = xdr_reserve_space(xdr, 4);
893 static void nfs3_xdr_enc_setattr3args(struct rpc_rqst *req,
894 struct xdr_stream *xdr,
897 const struct nfs3_sattrargs *args = data;
898 encode_nfs_fh3(xdr, args->fh);
899 encode_sattr3(xdr, args->sattr);
900 encode_sattrguard3(xdr, args);
906 * struct LOOKUP3args {
910 static void nfs3_xdr_enc_lookup3args(struct rpc_rqst *req,
911 struct xdr_stream *xdr,
914 const struct nfs3_diropargs *args = data;
916 encode_diropargs3(xdr, args->fh, args->name, args->len);
922 * struct ACCESS3args {
927 static void encode_access3args(struct xdr_stream *xdr,
928 const struct nfs3_accessargs *args)
930 encode_nfs_fh3(xdr, args->fh);
931 encode_uint32(xdr, args->access);
934 static void nfs3_xdr_enc_access3args(struct rpc_rqst *req,
935 struct xdr_stream *xdr,
938 const struct nfs3_accessargs *args = data;
940 encode_access3args(xdr, args);
944 * 3.3.5 READLINK3args
946 * struct READLINK3args {
950 static void nfs3_xdr_enc_readlink3args(struct rpc_rqst *req,
951 struct xdr_stream *xdr,
954 const struct nfs3_readlinkargs *args = data;
956 encode_nfs_fh3(xdr, args->fh);
957 prepare_reply_buffer(req, args->pages, args->pgbase,
958 args->pglen, NFS3_readlinkres_sz);
970 static void encode_read3args(struct xdr_stream *xdr,
971 const struct nfs_pgio_args *args)
975 encode_nfs_fh3(xdr, args->fh);
977 p = xdr_reserve_space(xdr, 8 + 4);
978 p = xdr_encode_hyper(p, args->offset);
979 *p = cpu_to_be32(args->count);
982 static void nfs3_xdr_enc_read3args(struct rpc_rqst *req,
983 struct xdr_stream *xdr,
986 const struct nfs_pgio_args *args = data;
988 encode_read3args(xdr, args);
989 prepare_reply_buffer(req, args->pages, args->pgbase,
990 args->count, NFS3_readres_sz);
991 req->rq_rcv_buf.flags |= XDRBUF_READ;
1003 * struct WRITE3args {
1007 * stable_how stable;
1011 static void encode_write3args(struct xdr_stream *xdr,
1012 const struct nfs_pgio_args *args)
1016 encode_nfs_fh3(xdr, args->fh);
1018 p = xdr_reserve_space(xdr, 8 + 4 + 4 + 4);
1019 p = xdr_encode_hyper(p, args->offset);
1020 *p++ = cpu_to_be32(args->count);
1021 *p++ = cpu_to_be32(args->stable);
1022 *p = cpu_to_be32(args->count);
1023 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1026 static void nfs3_xdr_enc_write3args(struct rpc_rqst *req,
1027 struct xdr_stream *xdr,
1030 const struct nfs_pgio_args *args = data;
1032 encode_write3args(xdr, args);
1033 xdr->buf->flags |= XDRBUF_WRITE;
1039 * enum createmode3 {
1045 * union createhow3 switch (createmode3 mode) {
1048 * sattr3 obj_attributes;
1053 * struct CREATE3args {
1058 static void encode_createhow3(struct xdr_stream *xdr,
1059 const struct nfs3_createargs *args)
1061 encode_uint32(xdr, args->createmode);
1062 switch (args->createmode) {
1063 case NFS3_CREATE_UNCHECKED:
1064 case NFS3_CREATE_GUARDED:
1065 encode_sattr3(xdr, args->sattr);
1067 case NFS3_CREATE_EXCLUSIVE:
1068 encode_createverf3(xdr, args->verifier);
1075 static void nfs3_xdr_enc_create3args(struct rpc_rqst *req,
1076 struct xdr_stream *xdr,
1079 const struct nfs3_createargs *args = data;
1081 encode_diropargs3(xdr, args->fh, args->name, args->len);
1082 encode_createhow3(xdr, args);
1088 * struct MKDIR3args {
1090 * sattr3 attributes;
1093 static void nfs3_xdr_enc_mkdir3args(struct rpc_rqst *req,
1094 struct xdr_stream *xdr,
1097 const struct nfs3_mkdirargs *args = data;
1099 encode_diropargs3(xdr, args->fh, args->name, args->len);
1100 encode_sattr3(xdr, args->sattr);
1104 * 3.3.10 SYMLINK3args
1106 * struct symlinkdata3 {
1107 * sattr3 symlink_attributes;
1108 * nfspath3 symlink_data;
1111 * struct SYMLINK3args {
1113 * symlinkdata3 symlink;
1116 static void encode_symlinkdata3(struct xdr_stream *xdr,
1119 const struct nfs3_symlinkargs *args = data;
1121 encode_sattr3(xdr, args->sattr);
1122 encode_nfspath3(xdr, args->pages, args->pathlen);
1125 static void nfs3_xdr_enc_symlink3args(struct rpc_rqst *req,
1126 struct xdr_stream *xdr,
1129 const struct nfs3_symlinkargs *args = data;
1131 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
1132 encode_symlinkdata3(xdr, args);
1133 xdr->buf->flags |= XDRBUF_WRITE;
1139 * struct devicedata3 {
1140 * sattr3 dev_attributes;
1144 * union mknoddata3 switch (ftype3 type) {
1147 * devicedata3 device;
1150 * sattr3 pipe_attributes;
1155 * struct MKNOD3args {
1160 static void encode_devicedata3(struct xdr_stream *xdr,
1161 const struct nfs3_mknodargs *args)
1163 encode_sattr3(xdr, args->sattr);
1164 encode_specdata3(xdr, args->rdev);
1167 static void encode_mknoddata3(struct xdr_stream *xdr,
1168 const struct nfs3_mknodargs *args)
1170 encode_ftype3(xdr, args->type);
1171 switch (args->type) {
1174 encode_devicedata3(xdr, args);
1178 encode_sattr3(xdr, args->sattr);
1188 static void nfs3_xdr_enc_mknod3args(struct rpc_rqst *req,
1189 struct xdr_stream *xdr,
1192 const struct nfs3_mknodargs *args = data;
1194 encode_diropargs3(xdr, args->fh, args->name, args->len);
1195 encode_mknoddata3(xdr, args);
1199 * 3.3.12 REMOVE3args
1201 * struct REMOVE3args {
1202 * diropargs3 object;
1205 static void nfs3_xdr_enc_remove3args(struct rpc_rqst *req,
1206 struct xdr_stream *xdr,
1209 const struct nfs_removeargs *args = data;
1211 encode_diropargs3(xdr, args->fh, args->name.name, args->name.len);
1215 * 3.3.14 RENAME3args
1217 * struct RENAME3args {
1222 static void nfs3_xdr_enc_rename3args(struct rpc_rqst *req,
1223 struct xdr_stream *xdr,
1226 const struct nfs_renameargs *args = data;
1227 const struct qstr *old = args->old_name;
1228 const struct qstr *new = args->new_name;
1230 encode_diropargs3(xdr, args->old_dir, old->name, old->len);
1231 encode_diropargs3(xdr, args->new_dir, new->name, new->len);
1237 * struct LINK3args {
1242 static void nfs3_xdr_enc_link3args(struct rpc_rqst *req,
1243 struct xdr_stream *xdr,
1246 const struct nfs3_linkargs *args = data;
1248 encode_nfs_fh3(xdr, args->fromfh);
1249 encode_diropargs3(xdr, args->tofh, args->toname, args->tolen);
1253 * 3.3.16 READDIR3args
1255 * struct READDIR3args {
1258 * cookieverf3 cookieverf;
1262 static void encode_readdir3args(struct xdr_stream *xdr,
1263 const struct nfs3_readdirargs *args)
1267 encode_nfs_fh3(xdr, args->fh);
1269 p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4);
1270 p = xdr_encode_cookie3(p, args->cookie);
1271 p = xdr_encode_cookieverf3(p, args->verf);
1272 *p = cpu_to_be32(args->count);
1275 static void nfs3_xdr_enc_readdir3args(struct rpc_rqst *req,
1276 struct xdr_stream *xdr,
1279 const struct nfs3_readdirargs *args = data;
1281 encode_readdir3args(xdr, args);
1282 prepare_reply_buffer(req, args->pages, 0,
1283 args->count, NFS3_readdirres_sz);
1287 * 3.3.17 READDIRPLUS3args
1289 * struct READDIRPLUS3args {
1292 * cookieverf3 cookieverf;
1297 static void encode_readdirplus3args(struct xdr_stream *xdr,
1298 const struct nfs3_readdirargs *args)
1302 encode_nfs_fh3(xdr, args->fh);
1304 p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4 + 4);
1305 p = xdr_encode_cookie3(p, args->cookie);
1306 p = xdr_encode_cookieverf3(p, args->verf);
1309 * readdirplus: need dircount + buffer size.
1310 * We just make sure we make dircount big enough
1312 *p++ = cpu_to_be32(args->count >> 3);
1314 *p = cpu_to_be32(args->count);
1317 static void nfs3_xdr_enc_readdirplus3args(struct rpc_rqst *req,
1318 struct xdr_stream *xdr,
1321 const struct nfs3_readdirargs *args = data;
1323 encode_readdirplus3args(xdr, args);
1324 prepare_reply_buffer(req, args->pages, 0,
1325 args->count, NFS3_readdirres_sz);
1329 * 3.3.21 COMMIT3args
1331 * struct COMMIT3args {
1337 static void encode_commit3args(struct xdr_stream *xdr,
1338 const struct nfs_commitargs *args)
1342 encode_nfs_fh3(xdr, args->fh);
1344 p = xdr_reserve_space(xdr, 8 + 4);
1345 p = xdr_encode_hyper(p, args->offset);
1346 *p = cpu_to_be32(args->count);
1349 static void nfs3_xdr_enc_commit3args(struct rpc_rqst *req,
1350 struct xdr_stream *xdr,
1353 const struct nfs_commitargs *args = data;
1355 encode_commit3args(xdr, args);
1358 #ifdef CONFIG_NFS_V3_ACL
1360 static void nfs3_xdr_enc_getacl3args(struct rpc_rqst *req,
1361 struct xdr_stream *xdr,
1364 const struct nfs3_getaclargs *args = data;
1366 encode_nfs_fh3(xdr, args->fh);
1367 encode_uint32(xdr, args->mask);
1368 if (args->mask & (NFS_ACL | NFS_DFACL))
1369 prepare_reply_buffer(req, args->pages, 0,
1370 NFSACL_MAXPAGES << PAGE_SHIFT,
1374 static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req,
1375 struct xdr_stream *xdr,
1378 const struct nfs3_setaclargs *args = data;
1382 encode_nfs_fh3(xdr, NFS_FH(args->inode));
1383 encode_uint32(xdr, args->mask);
1385 base = req->rq_slen;
1386 if (args->npages != 0)
1387 xdr_write_pages(xdr, args->pages, 0, args->len);
1389 xdr_reserve_space(xdr, args->len);
1391 error = nfsacl_encode(xdr->buf, base, args->inode,
1392 (args->mask & NFS_ACL) ?
1393 args->acl_access : NULL, 1, 0);
1394 /* FIXME: this is just broken */
1396 error = nfsacl_encode(xdr->buf, base + error, args->inode,
1397 (args->mask & NFS_DFACL) ?
1398 args->acl_default : NULL, 1,
1403 #endif /* CONFIG_NFS_V3_ACL */
1406 * NFSv3 XDR decode functions
1408 * NFSv3 result types are defined in section 3.3 of RFC 1813:
1409 * "NFS Version 3 Protocol Specification".
1415 * struct GETATTR3resok {
1416 * fattr3 obj_attributes;
1419 * union GETATTR3res switch (nfsstat3 status) {
1421 * GETATTR3resok resok;
1426 static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
1427 struct xdr_stream *xdr,
1430 enum nfs_stat status;
1433 error = decode_nfsstat3(xdr, &status);
1434 if (unlikely(error))
1436 if (status != NFS3_OK)
1438 error = decode_fattr3(xdr, result);
1442 return nfs3_stat_to_errno(status);
1448 * struct SETATTR3resok {
1452 * struct SETATTR3resfail {
1456 * union SETATTR3res switch (nfsstat3 status) {
1458 * SETATTR3resok resok;
1460 * SETATTR3resfail resfail;
1463 static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
1464 struct xdr_stream *xdr,
1467 enum nfs_stat status;
1470 error = decode_nfsstat3(xdr, &status);
1471 if (unlikely(error))
1473 error = decode_wcc_data(xdr, result);
1474 if (unlikely(error))
1476 if (status != NFS3_OK)
1481 return nfs3_stat_to_errno(status);
1487 * struct LOOKUP3resok {
1489 * post_op_attr obj_attributes;
1490 * post_op_attr dir_attributes;
1493 * struct LOOKUP3resfail {
1494 * post_op_attr dir_attributes;
1497 * union LOOKUP3res switch (nfsstat3 status) {
1499 * LOOKUP3resok resok;
1501 * LOOKUP3resfail resfail;
1504 static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req,
1505 struct xdr_stream *xdr,
1508 struct nfs3_diropres *result = data;
1509 enum nfs_stat status;
1512 error = decode_nfsstat3(xdr, &status);
1513 if (unlikely(error))
1515 if (status != NFS3_OK)
1517 error = decode_nfs_fh3(xdr, result->fh);
1518 if (unlikely(error))
1520 error = decode_post_op_attr(xdr, result->fattr);
1521 if (unlikely(error))
1523 error = decode_post_op_attr(xdr, result->dir_attr);
1527 error = decode_post_op_attr(xdr, result->dir_attr);
1528 if (unlikely(error))
1530 return nfs3_stat_to_errno(status);
1536 * struct ACCESS3resok {
1537 * post_op_attr obj_attributes;
1541 * struct ACCESS3resfail {
1542 * post_op_attr obj_attributes;
1545 * union ACCESS3res switch (nfsstat3 status) {
1547 * ACCESS3resok resok;
1549 * ACCESS3resfail resfail;
1552 static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
1553 struct xdr_stream *xdr,
1556 struct nfs3_accessres *result = data;
1557 enum nfs_stat status;
1560 error = decode_nfsstat3(xdr, &status);
1561 if (unlikely(error))
1563 error = decode_post_op_attr(xdr, result->fattr);
1564 if (unlikely(error))
1566 if (status != NFS3_OK)
1568 error = decode_uint32(xdr, &result->access);
1572 return nfs3_stat_to_errno(status);
1576 * 3.3.5 READLINK3res
1578 * struct READLINK3resok {
1579 * post_op_attr symlink_attributes;
1583 * struct READLINK3resfail {
1584 * post_op_attr symlink_attributes;
1587 * union READLINK3res switch (nfsstat3 status) {
1589 * READLINK3resok resok;
1591 * READLINK3resfail resfail;
1594 static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
1595 struct xdr_stream *xdr,
1598 enum nfs_stat status;
1601 error = decode_nfsstat3(xdr, &status);
1602 if (unlikely(error))
1604 error = decode_post_op_attr(xdr, result);
1605 if (unlikely(error))
1607 if (status != NFS3_OK)
1609 error = decode_nfspath3(xdr);
1613 return nfs3_stat_to_errno(status);
1619 * struct READ3resok {
1620 * post_op_attr file_attributes;
1626 * struct READ3resfail {
1627 * post_op_attr file_attributes;
1630 * union READ3res switch (nfsstat3 status) {
1634 * READ3resfail resfail;
1637 static int decode_read3resok(struct xdr_stream *xdr,
1638 struct nfs_pgio_res *result)
1640 u32 eof, count, ocount, recvd;
1643 p = xdr_inline_decode(xdr, 4 + 4 + 4);
1644 if (unlikely(p == NULL))
1646 count = be32_to_cpup(p++);
1647 eof = be32_to_cpup(p++);
1648 ocount = be32_to_cpup(p++);
1649 if (unlikely(ocount != count))
1651 recvd = xdr_read_pages(xdr, count);
1652 if (unlikely(count > recvd))
1656 result->count = count;
1659 dprintk("NFS: READ count doesn't match length of opaque: "
1660 "count %u != ocount %u\n", count, ocount);
1663 dprintk("NFS: server cheating in read result: "
1664 "count %u > recvd %u\n", count, recvd);
1669 print_overflow_msg(__func__, xdr);
1673 static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1676 struct nfs_pgio_res *result = data;
1677 enum nfs_stat status;
1680 error = decode_nfsstat3(xdr, &status);
1681 if (unlikely(error))
1683 error = decode_post_op_attr(xdr, result->fattr);
1684 if (unlikely(error))
1686 result->op_status = status;
1687 if (status != NFS3_OK)
1689 error = decode_read3resok(xdr, result);
1693 return nfs3_stat_to_errno(status);
1705 * struct WRITE3resok {
1706 * wcc_data file_wcc;
1708 * stable_how committed;
1712 * struct WRITE3resfail {
1713 * wcc_data file_wcc;
1716 * union WRITE3res switch (nfsstat3 status) {
1718 * WRITE3resok resok;
1720 * WRITE3resfail resfail;
1723 static int decode_write3resok(struct xdr_stream *xdr,
1724 struct nfs_pgio_res *result)
1728 p = xdr_inline_decode(xdr, 4 + 4);
1729 if (unlikely(p == NULL))
1731 result->count = be32_to_cpup(p++);
1732 result->verf->committed = be32_to_cpup(p++);
1733 if (unlikely(result->verf->committed > NFS_FILE_SYNC))
1735 if (decode_writeverf3(xdr, &result->verf->verifier))
1737 return result->count;
1739 dprintk("NFS: bad stable_how value: %u\n", result->verf->committed);
1742 print_overflow_msg(__func__, xdr);
1747 static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1750 struct nfs_pgio_res *result = data;
1751 enum nfs_stat status;
1754 error = decode_nfsstat3(xdr, &status);
1755 if (unlikely(error))
1757 error = decode_wcc_data(xdr, result->fattr);
1758 if (unlikely(error))
1760 result->op_status = status;
1761 if (status != NFS3_OK)
1763 error = decode_write3resok(xdr, result);
1767 return nfs3_stat_to_errno(status);
1773 * struct CREATE3resok {
1775 * post_op_attr obj_attributes;
1779 * struct CREATE3resfail {
1783 * union CREATE3res switch (nfsstat3 status) {
1785 * CREATE3resok resok;
1787 * CREATE3resfail resfail;
1790 static int decode_create3resok(struct xdr_stream *xdr,
1791 struct nfs3_diropres *result)
1795 error = decode_post_op_fh3(xdr, result->fh);
1796 if (unlikely(error))
1798 error = decode_post_op_attr(xdr, result->fattr);
1799 if (unlikely(error))
1801 /* The server isn't required to return a file handle.
1802 * If it didn't, force the client to perform a LOOKUP
1803 * to determine the correct file handle and attribute
1804 * values for the new object. */
1805 if (result->fh->size == 0)
1806 result->fattr->valid = 0;
1807 error = decode_wcc_data(xdr, result->dir_attr);
1812 static int nfs3_xdr_dec_create3res(struct rpc_rqst *req,
1813 struct xdr_stream *xdr,
1816 struct nfs3_diropres *result = data;
1817 enum nfs_stat status;
1820 error = decode_nfsstat3(xdr, &status);
1821 if (unlikely(error))
1823 if (status != NFS3_OK)
1825 error = decode_create3resok(xdr, result);
1829 error = decode_wcc_data(xdr, result->dir_attr);
1830 if (unlikely(error))
1832 return nfs3_stat_to_errno(status);
1838 * struct REMOVE3resok {
1842 * struct REMOVE3resfail {
1846 * union REMOVE3res switch (nfsstat3 status) {
1848 * REMOVE3resok resok;
1850 * REMOVE3resfail resfail;
1853 static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
1854 struct xdr_stream *xdr,
1857 struct nfs_removeres *result = data;
1858 enum nfs_stat status;
1861 error = decode_nfsstat3(xdr, &status);
1862 if (unlikely(error))
1864 error = decode_wcc_data(xdr, result->dir_attr);
1865 if (unlikely(error))
1867 if (status != NFS3_OK)
1872 return nfs3_stat_to_errno(status);
1878 * struct RENAME3resok {
1879 * wcc_data fromdir_wcc;
1880 * wcc_data todir_wcc;
1883 * struct RENAME3resfail {
1884 * wcc_data fromdir_wcc;
1885 * wcc_data todir_wcc;
1888 * union RENAME3res switch (nfsstat3 status) {
1890 * RENAME3resok resok;
1892 * RENAME3resfail resfail;
1895 static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
1896 struct xdr_stream *xdr,
1899 struct nfs_renameres *result = data;
1900 enum nfs_stat status;
1903 error = decode_nfsstat3(xdr, &status);
1904 if (unlikely(error))
1906 error = decode_wcc_data(xdr, result->old_fattr);
1907 if (unlikely(error))
1909 error = decode_wcc_data(xdr, result->new_fattr);
1910 if (unlikely(error))
1912 if (status != NFS3_OK)
1917 return nfs3_stat_to_errno(status);
1923 * struct LINK3resok {
1924 * post_op_attr file_attributes;
1925 * wcc_data linkdir_wcc;
1928 * struct LINK3resfail {
1929 * post_op_attr file_attributes;
1930 * wcc_data linkdir_wcc;
1933 * union LINK3res switch (nfsstat3 status) {
1937 * LINK3resfail resfail;
1940 static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1943 struct nfs3_linkres *result = data;
1944 enum nfs_stat status;
1947 error = decode_nfsstat3(xdr, &status);
1948 if (unlikely(error))
1950 error = decode_post_op_attr(xdr, result->fattr);
1951 if (unlikely(error))
1953 error = decode_wcc_data(xdr, result->dir_attr);
1954 if (unlikely(error))
1956 if (status != NFS3_OK)
1961 return nfs3_stat_to_errno(status);
1965 * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in
1966 * the local page cache
1967 * @xdr: XDR stream where entry resides
1968 * @entry: buffer to fill in with entry data
1969 * @plus: boolean indicating whether this should be a readdirplus entry
1971 * Returns zero if successful, otherwise a negative errno value is
1974 * This function is not invoked during READDIR reply decoding, but
1975 * rather whenever an application invokes the getdents(2) system call
1976 * on a directory already in our cache.
1984 * fhandle3 filehandle;
1985 * post_op_attr3 attributes;
1986 * entry3 *nextentry;
1990 * struct entryplus3 {
1994 * post_op_attr name_attributes;
1995 * post_op_fh3 name_handle;
1996 * entryplus3 *nextentry;
1999 int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
2002 struct nfs_entry old = *entry;
2007 p = xdr_inline_decode(xdr, 4);
2008 if (unlikely(p == NULL))
2010 if (*p == xdr_zero) {
2011 p = xdr_inline_decode(xdr, 4);
2012 if (unlikely(p == NULL))
2020 error = decode_fileid3(xdr, &entry->ino);
2021 if (unlikely(error))
2024 error = decode_inline_filename3(xdr, &entry->name, &entry->len);
2025 if (unlikely(error))
2028 error = decode_cookie3(xdr, &new_cookie);
2029 if (unlikely(error))
2032 entry->d_type = DT_UNKNOWN;
2035 entry->fattr->valid = 0;
2036 error = decode_post_op_attr(xdr, entry->fattr);
2037 if (unlikely(error))
2039 if (entry->fattr->valid & NFS_ATTR_FATTR_V3)
2040 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
2042 if (entry->fattr->fileid != entry->ino) {
2043 entry->fattr->mounted_on_fileid = entry->ino;
2044 entry->fattr->valid |= NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
2047 /* In fact, a post_op_fh3: */
2048 p = xdr_inline_decode(xdr, 4);
2049 if (unlikely(p == NULL))
2051 if (*p != xdr_zero) {
2052 error = decode_nfs_fh3(xdr, entry->fh);
2053 if (unlikely(error)) {
2054 if (error == -E2BIG)
2059 zero_nfs_fh3(entry->fh);
2062 entry->prev_cookie = entry->cookie;
2063 entry->cookie = new_cookie;
2068 print_overflow_msg(__func__, xdr);
2071 dprintk("NFS: directory entry contains invalid file handle\n");
2077 * 3.3.16 READDIR3res
2084 * struct READDIR3resok {
2085 * post_op_attr dir_attributes;
2086 * cookieverf3 cookieverf;
2090 * struct READDIR3resfail {
2091 * post_op_attr dir_attributes;
2094 * union READDIR3res switch (nfsstat3 status) {
2096 * READDIR3resok resok;
2098 * READDIR3resfail resfail;
2101 * Read the directory contents into the page cache, but otherwise
2102 * don't touch them. The actual decoding is done by nfs3_decode_entry()
2103 * during subsequent nfs_readdir() calls.
2105 static int decode_dirlist3(struct xdr_stream *xdr)
2107 return xdr_read_pages(xdr, xdr->buf->page_len);
2110 static int decode_readdir3resok(struct xdr_stream *xdr,
2111 struct nfs3_readdirres *result)
2115 error = decode_post_op_attr(xdr, result->dir_attr);
2116 if (unlikely(error))
2118 /* XXX: do we need to check if result->verf != NULL ? */
2119 error = decode_cookieverf3(xdr, result->verf);
2120 if (unlikely(error))
2122 error = decode_dirlist3(xdr);
2127 static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req,
2128 struct xdr_stream *xdr,
2131 struct nfs3_readdirres *result = data;
2132 enum nfs_stat status;
2135 error = decode_nfsstat3(xdr, &status);
2136 if (unlikely(error))
2138 if (status != NFS3_OK)
2140 error = decode_readdir3resok(xdr, result);
2144 error = decode_post_op_attr(xdr, result->dir_attr);
2145 if (unlikely(error))
2147 return nfs3_stat_to_errno(status);
2153 * struct FSSTAT3resok {
2154 * post_op_attr obj_attributes;
2164 * struct FSSTAT3resfail {
2165 * post_op_attr obj_attributes;
2168 * union FSSTAT3res switch (nfsstat3 status) {
2170 * FSSTAT3resok resok;
2172 * FSSTAT3resfail resfail;
2175 static int decode_fsstat3resok(struct xdr_stream *xdr,
2176 struct nfs_fsstat *result)
2180 p = xdr_inline_decode(xdr, 8 * 6 + 4);
2181 if (unlikely(p == NULL))
2183 p = xdr_decode_size3(p, &result->tbytes);
2184 p = xdr_decode_size3(p, &result->fbytes);
2185 p = xdr_decode_size3(p, &result->abytes);
2186 p = xdr_decode_size3(p, &result->tfiles);
2187 p = xdr_decode_size3(p, &result->ffiles);
2188 xdr_decode_size3(p, &result->afiles);
2189 /* ignore invarsec */
2192 print_overflow_msg(__func__, xdr);
2196 static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
2197 struct xdr_stream *xdr,
2200 struct nfs_fsstat *result = data;
2201 enum nfs_stat status;
2204 error = decode_nfsstat3(xdr, &status);
2205 if (unlikely(error))
2207 error = decode_post_op_attr(xdr, result->fattr);
2208 if (unlikely(error))
2210 if (status != NFS3_OK)
2212 error = decode_fsstat3resok(xdr, result);
2216 return nfs3_stat_to_errno(status);
2222 * struct FSINFO3resok {
2223 * post_op_attr obj_attributes;
2231 * size3 maxfilesize;
2232 * nfstime3 time_delta;
2233 * uint32 properties;
2236 * struct FSINFO3resfail {
2237 * post_op_attr obj_attributes;
2240 * union FSINFO3res switch (nfsstat3 status) {
2242 * FSINFO3resok resok;
2244 * FSINFO3resfail resfail;
2247 static int decode_fsinfo3resok(struct xdr_stream *xdr,
2248 struct nfs_fsinfo *result)
2252 p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4);
2253 if (unlikely(p == NULL))
2255 result->rtmax = be32_to_cpup(p++);
2256 result->rtpref = be32_to_cpup(p++);
2257 result->rtmult = be32_to_cpup(p++);
2258 result->wtmax = be32_to_cpup(p++);
2259 result->wtpref = be32_to_cpup(p++);
2260 result->wtmult = be32_to_cpup(p++);
2261 result->dtpref = be32_to_cpup(p++);
2262 p = xdr_decode_size3(p, &result->maxfilesize);
2263 xdr_decode_nfstime3(p, &result->time_delta);
2265 /* ignore properties */
2266 result->lease_time = 0;
2269 print_overflow_msg(__func__, xdr);
2273 static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
2274 struct xdr_stream *xdr,
2277 struct nfs_fsinfo *result = data;
2278 enum nfs_stat status;
2281 error = decode_nfsstat3(xdr, &status);
2282 if (unlikely(error))
2284 error = decode_post_op_attr(xdr, result->fattr);
2285 if (unlikely(error))
2287 if (status != NFS3_OK)
2289 error = decode_fsinfo3resok(xdr, result);
2293 return nfs3_stat_to_errno(status);
2297 * 3.3.20 PATHCONF3res
2299 * struct PATHCONF3resok {
2300 * post_op_attr obj_attributes;
2304 * bool chown_restricted;
2305 * bool case_insensitive;
2306 * bool case_preserving;
2309 * struct PATHCONF3resfail {
2310 * post_op_attr obj_attributes;
2313 * union PATHCONF3res switch (nfsstat3 status) {
2315 * PATHCONF3resok resok;
2317 * PATHCONF3resfail resfail;
2320 static int decode_pathconf3resok(struct xdr_stream *xdr,
2321 struct nfs_pathconf *result)
2325 p = xdr_inline_decode(xdr, 4 * 6);
2326 if (unlikely(p == NULL))
2328 result->max_link = be32_to_cpup(p++);
2329 result->max_namelen = be32_to_cpup(p);
2330 /* ignore remaining fields */
2333 print_overflow_msg(__func__, xdr);
2337 static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
2338 struct xdr_stream *xdr,
2341 struct nfs_pathconf *result = data;
2342 enum nfs_stat status;
2345 error = decode_nfsstat3(xdr, &status);
2346 if (unlikely(error))
2348 error = decode_post_op_attr(xdr, result->fattr);
2349 if (unlikely(error))
2351 if (status != NFS3_OK)
2353 error = decode_pathconf3resok(xdr, result);
2357 return nfs3_stat_to_errno(status);
2363 * struct COMMIT3resok {
2364 * wcc_data file_wcc;
2368 * struct COMMIT3resfail {
2369 * wcc_data file_wcc;
2372 * union COMMIT3res switch (nfsstat3 status) {
2374 * COMMIT3resok resok;
2376 * COMMIT3resfail resfail;
2379 static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
2380 struct xdr_stream *xdr,
2383 struct nfs_commitres *result = data;
2384 struct nfs_writeverf *verf = result->verf;
2385 enum nfs_stat status;
2388 error = decode_nfsstat3(xdr, &status);
2389 if (unlikely(error))
2391 error = decode_wcc_data(xdr, result->fattr);
2392 if (unlikely(error))
2394 result->op_status = status;
2395 if (status != NFS3_OK)
2397 error = decode_writeverf3(xdr, &verf->verifier);
2399 verf->committed = NFS_FILE_SYNC;
2403 return nfs3_stat_to_errno(status);
2406 #ifdef CONFIG_NFS_V3_ACL
2408 static inline int decode_getacl3resok(struct xdr_stream *xdr,
2409 struct nfs3_getaclres *result)
2411 struct posix_acl **acl;
2412 unsigned int *aclcnt;
2416 error = decode_post_op_attr(xdr, result->fattr);
2417 if (unlikely(error))
2419 error = decode_uint32(xdr, &result->mask);
2420 if (unlikely(error))
2423 if (result->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
2426 hdrlen = xdr_stream_pos(xdr);
2429 if (result->mask & NFS_ACL)
2430 acl = &result->acl_access;
2432 if (result->mask & NFS_ACLCNT)
2433 aclcnt = &result->acl_access_count;
2434 error = nfsacl_decode(xdr->buf, hdrlen, aclcnt, acl);
2435 if (unlikely(error <= 0))
2439 if (result->mask & NFS_DFACL)
2440 acl = &result->acl_default;
2442 if (result->mask & NFS_DFACLCNT)
2443 aclcnt = &result->acl_default_count;
2444 error = nfsacl_decode(xdr->buf, hdrlen + error, aclcnt, acl);
2445 if (unlikely(error <= 0))
2452 static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
2453 struct xdr_stream *xdr,
2456 enum nfs_stat status;
2459 error = decode_nfsstat3(xdr, &status);
2460 if (unlikely(error))
2462 if (status != NFS3_OK)
2464 error = decode_getacl3resok(xdr, result);
2468 return nfs3_stat_to_errno(status);
2471 static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
2472 struct xdr_stream *xdr,
2475 enum nfs_stat status;
2478 error = decode_nfsstat3(xdr, &status);
2479 if (unlikely(error))
2481 if (status != NFS3_OK)
2483 error = decode_post_op_attr(xdr, result);
2487 return nfs3_stat_to_errno(status);
2490 #endif /* CONFIG_NFS_V3_ACL */
2494 * We need to translate between nfs status return values and
2495 * the local errno values which may not be the same.
2497 static const struct {
2502 { NFSERR_PERM, -EPERM },
2503 { NFSERR_NOENT, -ENOENT },
2504 { NFSERR_IO, -errno_NFSERR_IO},
2505 { NFSERR_NXIO, -ENXIO },
2506 /* { NFSERR_EAGAIN, -EAGAIN }, */
2507 { NFSERR_ACCES, -EACCES },
2508 { NFSERR_EXIST, -EEXIST },
2509 { NFSERR_XDEV, -EXDEV },
2510 { NFSERR_NODEV, -ENODEV },
2511 { NFSERR_NOTDIR, -ENOTDIR },
2512 { NFSERR_ISDIR, -EISDIR },
2513 { NFSERR_INVAL, -EINVAL },
2514 { NFSERR_FBIG, -EFBIG },
2515 { NFSERR_NOSPC, -ENOSPC },
2516 { NFSERR_ROFS, -EROFS },
2517 { NFSERR_MLINK, -EMLINK },
2518 { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
2519 { NFSERR_NOTEMPTY, -ENOTEMPTY },
2520 { NFSERR_DQUOT, -EDQUOT },
2521 { NFSERR_STALE, -ESTALE },
2522 { NFSERR_REMOTE, -EREMOTE },
2524 { NFSERR_WFLUSH, -EWFLUSH },
2526 { NFSERR_BADHANDLE, -EBADHANDLE },
2527 { NFSERR_NOT_SYNC, -ENOTSYNC },
2528 { NFSERR_BAD_COOKIE, -EBADCOOKIE },
2529 { NFSERR_NOTSUPP, -ENOTSUPP },
2530 { NFSERR_TOOSMALL, -ETOOSMALL },
2531 { NFSERR_SERVERFAULT, -EREMOTEIO },
2532 { NFSERR_BADTYPE, -EBADTYPE },
2533 { NFSERR_JUKEBOX, -EJUKEBOX },
2538 * nfs3_stat_to_errno - convert an NFS status code to a local errno
2539 * @status: NFS status code to convert
2541 * Returns a local errno value, or -EIO if the NFS status code is
2542 * not recognized. This function is used jointly by NFSv2 and NFSv3.
2544 static int nfs3_stat_to_errno(enum nfs_stat status)
2548 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
2549 if (nfs_errtbl[i].stat == (int)status)
2550 return nfs_errtbl[i].errno;
2552 dprintk("NFS: Unrecognized nfs status value: %u\n", status);
2553 return nfs_errtbl[i].errno;
2557 #define PROC(proc, argtype, restype, timer) \
2558 [NFS3PROC_##proc] = { \
2559 .p_proc = NFS3PROC_##proc, \
2560 .p_encode = nfs3_xdr_enc_##argtype##3args, \
2561 .p_decode = nfs3_xdr_dec_##restype##3res, \
2562 .p_arglen = NFS3_##argtype##args_sz, \
2563 .p_replen = NFS3_##restype##res_sz, \
2565 .p_statidx = NFS3PROC_##proc, \
2569 const struct rpc_procinfo nfs3_procedures[] = {
2570 PROC(GETATTR, getattr, getattr, 1),
2571 PROC(SETATTR, setattr, setattr, 0),
2572 PROC(LOOKUP, lookup, lookup, 2),
2573 PROC(ACCESS, access, access, 1),
2574 PROC(READLINK, readlink, readlink, 3),
2575 PROC(READ, read, read, 3),
2576 PROC(WRITE, write, write, 4),
2577 PROC(CREATE, create, create, 0),
2578 PROC(MKDIR, mkdir, create, 0),
2579 PROC(SYMLINK, symlink, create, 0),
2580 PROC(MKNOD, mknod, create, 0),
2581 PROC(REMOVE, remove, remove, 0),
2582 PROC(RMDIR, lookup, setattr, 0),
2583 PROC(RENAME, rename, rename, 0),
2584 PROC(LINK, link, link, 0),
2585 PROC(READDIR, readdir, readdir, 3),
2586 PROC(READDIRPLUS, readdirplus, readdir, 3),
2587 PROC(FSSTAT, getattr, fsstat, 0),
2588 PROC(FSINFO, getattr, fsinfo, 0),
2589 PROC(PATHCONF, getattr, pathconf, 0),
2590 PROC(COMMIT, commit, commit, 5),
2593 static unsigned int nfs_version3_counts[ARRAY_SIZE(nfs3_procedures)];
2594 const struct rpc_version nfs_version3 = {
2596 .nrprocs = ARRAY_SIZE(nfs3_procedures),
2597 .procs = nfs3_procedures,
2598 .counts = nfs_version3_counts,
2601 #ifdef CONFIG_NFS_V3_ACL
2602 static const struct rpc_procinfo nfs3_acl_procedures[] = {
2603 [ACLPROC3_GETACL] = {
2604 .p_proc = ACLPROC3_GETACL,
2605 .p_encode = nfs3_xdr_enc_getacl3args,
2606 .p_decode = nfs3_xdr_dec_getacl3res,
2607 .p_arglen = ACL3_getaclargs_sz,
2608 .p_replen = ACL3_getaclres_sz,
2612 [ACLPROC3_SETACL] = {
2613 .p_proc = ACLPROC3_SETACL,
2614 .p_encode = nfs3_xdr_enc_setacl3args,
2615 .p_decode = nfs3_xdr_dec_setacl3res,
2616 .p_arglen = ACL3_setaclargs_sz,
2617 .p_replen = ACL3_setaclres_sz,
2623 static unsigned int nfs3_acl_counts[ARRAY_SIZE(nfs3_acl_procedures)];
2624 const struct rpc_version nfsacl_version3 = {
2626 .nrprocs = ARRAY_SIZE(nfs3_acl_procedures),
2627 .procs = nfs3_acl_procedures,
2628 .counts = nfs3_acl_counts,
2630 #endif /* CONFIG_NFS_V3_ACL */