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>
27 #define NFSDBG_FACILITY NFSDBG_XDR
29 /* Mapping from NFS error code to "errno" error code. */
30 #define errno_NFSERR_IO EIO
33 * Declare the space requirements for NFS arguments and replies as
34 * number of 32bit-words
36 #define NFS3_pagepad_sz (1) /* Page padding */
37 #define NFS3_fhandle_sz (1+16)
38 #define NFS3_fh_sz (NFS3_fhandle_sz) /* shorthand */
39 #define NFS3_sattr_sz (15)
40 #define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2))
41 #define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2))
42 #define NFS3_fattr_sz (21)
43 #define NFS3_cookieverf_sz (NFS3_COOKIEVERFSIZE>>2)
44 #define NFS3_wcc_attr_sz (6)
45 #define NFS3_pre_op_attr_sz (1+NFS3_wcc_attr_sz)
46 #define NFS3_post_op_attr_sz (1+NFS3_fattr_sz)
47 #define NFS3_wcc_data_sz (NFS3_pre_op_attr_sz+NFS3_post_op_attr_sz)
48 #define NFS3_diropargs_sz (NFS3_fh_sz+NFS3_filename_sz)
50 #define NFS3_getattrargs_sz (NFS3_fh_sz)
51 #define NFS3_setattrargs_sz (NFS3_fh_sz+NFS3_sattr_sz+3)
52 #define NFS3_lookupargs_sz (NFS3_fh_sz+NFS3_filename_sz)
53 #define NFS3_accessargs_sz (NFS3_fh_sz+1)
54 #define NFS3_readlinkargs_sz (NFS3_fh_sz)
55 #define NFS3_readargs_sz (NFS3_fh_sz+3)
56 #define NFS3_writeargs_sz (NFS3_fh_sz+5)
57 #define NFS3_createargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
58 #define NFS3_mkdirargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
59 #define NFS3_symlinkargs_sz (NFS3_diropargs_sz+1+NFS3_sattr_sz)
60 #define NFS3_mknodargs_sz (NFS3_diropargs_sz+2+NFS3_sattr_sz)
61 #define NFS3_removeargs_sz (NFS3_fh_sz+NFS3_filename_sz)
62 #define NFS3_renameargs_sz (NFS3_diropargs_sz+NFS3_diropargs_sz)
63 #define NFS3_linkargs_sz (NFS3_fh_sz+NFS3_diropargs_sz)
64 #define NFS3_readdirargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+3)
65 #define NFS3_readdirplusargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+4)
66 #define NFS3_commitargs_sz (NFS3_fh_sz+3)
68 #define NFS3_getattrres_sz (1+NFS3_fattr_sz)
69 #define NFS3_setattrres_sz (1+NFS3_wcc_data_sz)
70 #define NFS3_removeres_sz (NFS3_setattrres_sz)
71 #define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
72 #define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1)
73 #define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1+NFS3_pagepad_sz)
74 #define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3+NFS3_pagepad_sz)
75 #define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4)
76 #define NFS3_createres_sz (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
77 #define NFS3_renameres_sz (1+(2 * NFS3_wcc_data_sz))
78 #define NFS3_linkres_sz (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
79 #define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2+NFS3_pagepad_sz)
80 #define NFS3_fsstatres_sz (1+NFS3_post_op_attr_sz+13)
81 #define NFS3_fsinfores_sz (1+NFS3_post_op_attr_sz+12)
82 #define NFS3_pathconfres_sz (1+NFS3_post_op_attr_sz+6)
83 #define NFS3_commitres_sz (1+NFS3_wcc_data_sz+2)
85 #define ACL3_getaclargs_sz (NFS3_fh_sz+1)
86 #define ACL3_setaclargs_sz (NFS3_fh_sz+1+ \
87 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
88 #define ACL3_getaclres_sz (1+NFS3_post_op_attr_sz+1+ \
89 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+\
91 #define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
93 static int nfs3_stat_to_errno(enum nfs_stat);
96 * Map file type to S_IFMT bits
98 static const umode_t nfs_type2fmt[] = {
105 [NF3SOCK] = S_IFSOCK,
109 static struct user_namespace *rpc_userns(const struct rpc_clnt *clnt)
111 if (clnt && clnt->cl_cred)
112 return clnt->cl_cred->user_ns;
113 return &init_user_ns;
116 static struct user_namespace *rpc_rqst_userns(const struct rpc_rqst *rqstp)
119 return rpc_userns(rqstp->rq_task->tk_client);
120 return &init_user_ns;
124 * Encode/decode NFSv3 basic data types
126 * Basic NFSv3 data types are defined in section 2.5 of RFC 1813:
127 * "NFS Version 3 Protocol Specification".
129 * Not all basic data types have their own encoding and decoding
130 * functions. For run-time efficiency, some data types are encoded
134 static void encode_uint32(struct xdr_stream *xdr, u32 value)
136 __be32 *p = xdr_reserve_space(xdr, 4);
137 *p = cpu_to_be32(value);
140 static int decode_uint32(struct xdr_stream *xdr, u32 *value)
144 p = xdr_inline_decode(xdr, 4);
147 *value = be32_to_cpup(p);
151 static int decode_uint64(struct xdr_stream *xdr, u64 *value)
155 p = xdr_inline_decode(xdr, 8);
158 xdr_decode_hyper(p, value);
165 * typedef uint64 fileid3;
167 static __be32 *xdr_decode_fileid3(__be32 *p, u64 *fileid)
169 return xdr_decode_hyper(p, fileid);
172 static int decode_fileid3(struct xdr_stream *xdr, u64 *fileid)
174 return decode_uint64(xdr, fileid);
180 * typedef string filename3<>;
182 static void encode_filename3(struct xdr_stream *xdr,
183 const char *name, u32 length)
187 WARN_ON_ONCE(length > NFS3_MAXNAMLEN);
188 p = xdr_reserve_space(xdr, 4 + length);
189 xdr_encode_opaque(p, name, length);
192 static int decode_inline_filename3(struct xdr_stream *xdr,
193 const char **name, u32 *length)
198 p = xdr_inline_decode(xdr, 4);
201 count = be32_to_cpup(p);
202 if (count > NFS3_MAXNAMLEN)
203 goto out_nametoolong;
204 p = xdr_inline_decode(xdr, count);
207 *name = (const char *)p;
212 dprintk("NFS: returned filename too long: %u\n", count);
213 return -ENAMETOOLONG;
219 * typedef string nfspath3<>;
221 static void encode_nfspath3(struct xdr_stream *xdr, struct page **pages,
224 encode_uint32(xdr, length);
225 xdr_write_pages(xdr, pages, 0, length);
228 static int decode_nfspath3(struct xdr_stream *xdr)
233 p = xdr_inline_decode(xdr, 4);
236 count = be32_to_cpup(p);
237 if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN))
238 goto out_nametoolong;
239 recvd = xdr_read_pages(xdr, count);
240 if (unlikely(count > recvd))
242 xdr_terminate_string(xdr->buf, count);
246 dprintk("NFS: returned pathname too long: %u\n", count);
247 return -ENAMETOOLONG;
249 dprintk("NFS: server cheating in pathname result: "
250 "count %u > recvd %u\n", count, recvd);
257 * typedef uint64 cookie3
259 static __be32 *xdr_encode_cookie3(__be32 *p, u64 cookie)
261 return xdr_encode_hyper(p, cookie);
264 static int decode_cookie3(struct xdr_stream *xdr, u64 *cookie)
266 return decode_uint64(xdr, cookie);
272 * typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
274 static __be32 *xdr_encode_cookieverf3(__be32 *p, const __be32 *verifier)
276 memcpy(p, verifier, NFS3_COOKIEVERFSIZE);
277 return p + XDR_QUADLEN(NFS3_COOKIEVERFSIZE);
280 static int decode_cookieverf3(struct xdr_stream *xdr, __be32 *verifier)
284 p = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE);
287 memcpy(verifier, p, NFS3_COOKIEVERFSIZE);
294 * typedef opaque createverf3[NFS3_CREATEVERFSIZE];
296 static void encode_createverf3(struct xdr_stream *xdr, const __be32 *verifier)
300 p = xdr_reserve_space(xdr, NFS3_CREATEVERFSIZE);
301 memcpy(p, verifier, NFS3_CREATEVERFSIZE);
304 static int decode_writeverf3(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
308 p = xdr_inline_decode(xdr, NFS3_WRITEVERFSIZE);
311 memcpy(verifier->data, p, NFS3_WRITEVERFSIZE);
318 * typedef uint64 size3;
320 static __be32 *xdr_decode_size3(__be32 *p, u64 *size)
322 return xdr_decode_hyper(p, size);
333 #define NFS3_OK NFS_OK
335 static int decode_nfsstat3(struct xdr_stream *xdr, enum nfs_stat *status)
339 p = xdr_inline_decode(xdr, 4);
342 if (unlikely(*p != cpu_to_be32(NFS3_OK)))
347 *status = be32_to_cpup(p);
348 trace_nfs_xdr_status(xdr, (int)*status);
365 static void encode_ftype3(struct xdr_stream *xdr, const u32 type)
367 encode_uint32(xdr, type);
370 static __be32 *xdr_decode_ftype3(__be32 *p, umode_t *mode)
374 type = be32_to_cpup(p++);
377 *mode = nfs_type2fmt[type];
389 static void encode_specdata3(struct xdr_stream *xdr, const dev_t rdev)
393 p = xdr_reserve_space(xdr, 8);
394 *p++ = cpu_to_be32(MAJOR(rdev));
395 *p = cpu_to_be32(MINOR(rdev));
398 static __be32 *xdr_decode_specdata3(__be32 *p, dev_t *rdev)
400 unsigned int major, minor;
402 major = be32_to_cpup(p++);
403 minor = be32_to_cpup(p++);
404 *rdev = MKDEV(major, minor);
405 if (MAJOR(*rdev) != major || MINOR(*rdev) != minor)
414 * opaque data<NFS3_FHSIZE>;
417 static void encode_nfs_fh3(struct xdr_stream *xdr, const struct nfs_fh *fh)
421 WARN_ON_ONCE(fh->size > NFS3_FHSIZE);
422 p = xdr_reserve_space(xdr, 4 + fh->size);
423 xdr_encode_opaque(p, fh->data, fh->size);
426 static int decode_nfs_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
431 p = xdr_inline_decode(xdr, 4);
434 length = be32_to_cpup(p++);
435 if (unlikely(length > NFS3_FHSIZE))
437 p = xdr_inline_decode(xdr, length);
441 memcpy(fh->data, p, length);
444 dprintk("NFS: file handle size (%u) too big\n", length);
448 static void zero_nfs_fh3(struct nfs_fh *fh)
450 memset(fh, 0, sizeof(*fh));
461 static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec64 *timep)
463 *p++ = cpu_to_be32((u32)timep->tv_sec);
464 *p++ = cpu_to_be32(timep->tv_nsec);
468 static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec64 *timep)
470 timep->tv_sec = be32_to_cpup(p++);
471 timep->tv_nsec = be32_to_cpup(p++);
480 * SET_TO_SERVER_TIME = 1,
481 * SET_TO_CLIENT_TIME = 2
484 * union set_mode3 switch (bool set_it) {
491 * union set_uid3 switch (bool set_it) {
498 * union set_gid3 switch (bool set_it) {
505 * union set_size3 switch (bool set_it) {
512 * union set_atime switch (time_how set_it) {
513 * case SET_TO_CLIENT_TIME:
519 * union set_mtime switch (time_how set_it) {
520 * case SET_TO_CLIENT_TIME:
535 static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr,
536 struct user_namespace *userns)
542 * In order to make only a single xdr_reserve_space() call,
543 * pre-compute the total number of bytes to be reserved.
544 * Six boolean values, one for each set_foo field, are always
545 * present in the encoded result, so start there.
548 if (attr->ia_valid & ATTR_MODE)
550 if (attr->ia_valid & ATTR_UID)
552 if (attr->ia_valid & ATTR_GID)
554 if (attr->ia_valid & ATTR_SIZE)
556 if (attr->ia_valid & ATTR_ATIME_SET)
558 if (attr->ia_valid & ATTR_MTIME_SET)
560 p = xdr_reserve_space(xdr, nbytes);
562 if (attr->ia_valid & ATTR_MODE) {
564 *p++ = cpu_to_be32(attr->ia_mode & S_IALLUGO);
568 if (attr->ia_valid & ATTR_UID) {
570 *p++ = cpu_to_be32(from_kuid_munged(userns, attr->ia_uid));
574 if (attr->ia_valid & ATTR_GID) {
576 *p++ = cpu_to_be32(from_kgid_munged(userns, attr->ia_gid));
580 if (attr->ia_valid & ATTR_SIZE) {
582 p = xdr_encode_hyper(p, (u64)attr->ia_size);
586 if (attr->ia_valid & ATTR_ATIME_SET) {
588 p = xdr_encode_nfstime3(p, &attr->ia_atime);
589 } else if (attr->ia_valid & ATTR_ATIME) {
594 if (attr->ia_valid & ATTR_MTIME_SET) {
596 xdr_encode_nfstime3(p, &attr->ia_mtime);
597 } else if (attr->ia_valid & ATTR_MTIME) {
622 static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr,
623 struct user_namespace *userns)
628 p = xdr_inline_decode(xdr, NFS3_fattr_sz << 2);
632 p = xdr_decode_ftype3(p, &fmode);
634 fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode;
635 fattr->nlink = be32_to_cpup(p++);
636 fattr->uid = make_kuid(userns, be32_to_cpup(p++));
637 if (!uid_valid(fattr->uid))
639 fattr->gid = make_kgid(userns, be32_to_cpup(p++));
640 if (!gid_valid(fattr->gid))
643 p = xdr_decode_size3(p, &fattr->size);
644 p = xdr_decode_size3(p, &fattr->du.nfs3.used);
645 p = xdr_decode_specdata3(p, &fattr->rdev);
647 p = xdr_decode_hyper(p, &fattr->fsid.major);
648 fattr->fsid.minor = 0;
650 p = xdr_decode_fileid3(p, &fattr->fileid);
651 p = xdr_decode_nfstime3(p, &fattr->atime);
652 p = xdr_decode_nfstime3(p, &fattr->mtime);
653 xdr_decode_nfstime3(p, &fattr->ctime);
654 fattr->change_attr = nfs_timespec_to_change_attr(&fattr->ctime);
656 fattr->valid |= NFS_ATTR_FATTR_V3;
659 dprintk("NFS: returned invalid uid\n");
662 dprintk("NFS: returned invalid gid\n");
669 * union post_op_attr switch (bool attributes_follow) {
676 static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
677 struct user_namespace *userns)
681 p = xdr_inline_decode(xdr, 4);
685 return decode_fattr3(xdr, fattr, userns);
697 static int decode_wcc_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
701 p = xdr_inline_decode(xdr, NFS3_wcc_attr_sz << 2);
705 fattr->valid |= NFS_ATTR_FATTR_PRESIZE
706 | NFS_ATTR_FATTR_PRECHANGE
707 | NFS_ATTR_FATTR_PREMTIME
708 | NFS_ATTR_FATTR_PRECTIME;
710 p = xdr_decode_size3(p, &fattr->pre_size);
711 p = xdr_decode_nfstime3(p, &fattr->pre_mtime);
712 xdr_decode_nfstime3(p, &fattr->pre_ctime);
713 fattr->pre_change_attr = nfs_timespec_to_change_attr(&fattr->pre_ctime);
720 * union pre_op_attr switch (bool attributes_follow) {
722 * wcc_attr attributes;
730 * pre_op_attr before;
731 * post_op_attr after;
734 static int decode_pre_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
738 p = xdr_inline_decode(xdr, 4);
742 return decode_wcc_attr(xdr, fattr);
746 static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr,
747 struct user_namespace *userns)
751 error = decode_pre_op_attr(xdr, fattr);
754 error = decode_post_op_attr(xdr, fattr, userns);
762 * union post_op_fh3 switch (bool handle_follows) {
769 static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
771 __be32 *p = xdr_inline_decode(xdr, 4);
775 return decode_nfs_fh3(xdr, fh);
783 * struct diropargs3 {
788 static void encode_diropargs3(struct xdr_stream *xdr, const struct nfs_fh *fh,
789 const char *name, u32 length)
791 encode_nfs_fh3(xdr, fh);
792 encode_filename3(xdr, name, length);
797 * NFSv3 XDR encode functions
799 * NFSv3 argument types are defined in section 3.3 of RFC 1813:
800 * "NFS Version 3 Protocol Specification".
806 * struct GETATTR3args {
810 static void nfs3_xdr_enc_getattr3args(struct rpc_rqst *req,
811 struct xdr_stream *xdr,
814 const struct nfs_fh *fh = data;
816 encode_nfs_fh3(xdr, fh);
822 * union sattrguard3 switch (bool check) {
824 * nfstime3 obj_ctime;
829 * struct SETATTR3args {
831 * sattr3 new_attributes;
835 static void encode_sattrguard3(struct xdr_stream *xdr,
836 const struct nfs3_sattrargs *args)
841 p = xdr_reserve_space(xdr, 4 + 8);
843 xdr_encode_nfstime3(p, &args->guardtime);
845 p = xdr_reserve_space(xdr, 4);
850 static void nfs3_xdr_enc_setattr3args(struct rpc_rqst *req,
851 struct xdr_stream *xdr,
854 const struct nfs3_sattrargs *args = data;
855 encode_nfs_fh3(xdr, args->fh);
856 encode_sattr3(xdr, args->sattr, rpc_rqst_userns(req));
857 encode_sattrguard3(xdr, args);
863 * struct LOOKUP3args {
867 static void nfs3_xdr_enc_lookup3args(struct rpc_rqst *req,
868 struct xdr_stream *xdr,
871 const struct nfs3_diropargs *args = data;
873 encode_diropargs3(xdr, args->fh, args->name, args->len);
879 * struct ACCESS3args {
884 static void encode_access3args(struct xdr_stream *xdr,
885 const struct nfs3_accessargs *args)
887 encode_nfs_fh3(xdr, args->fh);
888 encode_uint32(xdr, args->access);
891 static void nfs3_xdr_enc_access3args(struct rpc_rqst *req,
892 struct xdr_stream *xdr,
895 const struct nfs3_accessargs *args = data;
897 encode_access3args(xdr, args);
901 * 3.3.5 READLINK3args
903 * struct READLINK3args {
907 static void nfs3_xdr_enc_readlink3args(struct rpc_rqst *req,
908 struct xdr_stream *xdr,
911 const struct nfs3_readlinkargs *args = data;
913 encode_nfs_fh3(xdr, args->fh);
914 rpc_prepare_reply_pages(req, args->pages, args->pgbase, args->pglen,
915 NFS3_readlinkres_sz - NFS3_pagepad_sz);
927 static void encode_read3args(struct xdr_stream *xdr,
928 const struct nfs_pgio_args *args)
932 encode_nfs_fh3(xdr, args->fh);
934 p = xdr_reserve_space(xdr, 8 + 4);
935 p = xdr_encode_hyper(p, args->offset);
936 *p = cpu_to_be32(args->count);
939 static void nfs3_xdr_enc_read3args(struct rpc_rqst *req,
940 struct xdr_stream *xdr,
943 const struct nfs_pgio_args *args = data;
944 unsigned int replen = args->replen ? args->replen :
945 NFS3_readres_sz - NFS3_pagepad_sz;
947 encode_read3args(xdr, args);
948 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
949 args->count, replen);
950 req->rq_rcv_buf.flags |= XDRBUF_READ;
962 * struct WRITE3args {
970 static void encode_write3args(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 + 4 + 4);
978 p = xdr_encode_hyper(p, args->offset);
979 *p++ = cpu_to_be32(args->count);
980 *p++ = cpu_to_be32(args->stable);
981 *p = cpu_to_be32(args->count);
982 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
985 static void nfs3_xdr_enc_write3args(struct rpc_rqst *req,
986 struct xdr_stream *xdr,
989 const struct nfs_pgio_args *args = data;
991 encode_write3args(xdr, args);
992 xdr->buf->flags |= XDRBUF_WRITE;
1004 * union createhow3 switch (createmode3 mode) {
1007 * sattr3 obj_attributes;
1012 * struct CREATE3args {
1017 static void encode_createhow3(struct xdr_stream *xdr,
1018 const struct nfs3_createargs *args,
1019 struct user_namespace *userns)
1021 encode_uint32(xdr, args->createmode);
1022 switch (args->createmode) {
1023 case NFS3_CREATE_UNCHECKED:
1024 case NFS3_CREATE_GUARDED:
1025 encode_sattr3(xdr, args->sattr, userns);
1027 case NFS3_CREATE_EXCLUSIVE:
1028 encode_createverf3(xdr, args->verifier);
1035 static void nfs3_xdr_enc_create3args(struct rpc_rqst *req,
1036 struct xdr_stream *xdr,
1039 const struct nfs3_createargs *args = data;
1041 encode_diropargs3(xdr, args->fh, args->name, args->len);
1042 encode_createhow3(xdr, args, rpc_rqst_userns(req));
1048 * struct MKDIR3args {
1050 * sattr3 attributes;
1053 static void nfs3_xdr_enc_mkdir3args(struct rpc_rqst *req,
1054 struct xdr_stream *xdr,
1057 const struct nfs3_mkdirargs *args = data;
1059 encode_diropargs3(xdr, args->fh, args->name, args->len);
1060 encode_sattr3(xdr, args->sattr, rpc_rqst_userns(req));
1064 * 3.3.10 SYMLINK3args
1066 * struct symlinkdata3 {
1067 * sattr3 symlink_attributes;
1068 * nfspath3 symlink_data;
1071 * struct SYMLINK3args {
1073 * symlinkdata3 symlink;
1076 static void encode_symlinkdata3(struct xdr_stream *xdr,
1078 struct user_namespace *userns)
1080 const struct nfs3_symlinkargs *args = data;
1082 encode_sattr3(xdr, args->sattr, userns);
1083 encode_nfspath3(xdr, args->pages, args->pathlen);
1086 static void nfs3_xdr_enc_symlink3args(struct rpc_rqst *req,
1087 struct xdr_stream *xdr,
1090 const struct nfs3_symlinkargs *args = data;
1092 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
1093 encode_symlinkdata3(xdr, args, rpc_rqst_userns(req));
1094 xdr->buf->flags |= XDRBUF_WRITE;
1100 * struct devicedata3 {
1101 * sattr3 dev_attributes;
1105 * union mknoddata3 switch (ftype3 type) {
1108 * devicedata3 device;
1111 * sattr3 pipe_attributes;
1116 * struct MKNOD3args {
1121 static void encode_devicedata3(struct xdr_stream *xdr,
1122 const struct nfs3_mknodargs *args,
1123 struct user_namespace *userns)
1125 encode_sattr3(xdr, args->sattr, userns);
1126 encode_specdata3(xdr, args->rdev);
1129 static void encode_mknoddata3(struct xdr_stream *xdr,
1130 const struct nfs3_mknodargs *args,
1131 struct user_namespace *userns)
1133 encode_ftype3(xdr, args->type);
1134 switch (args->type) {
1137 encode_devicedata3(xdr, args, userns);
1141 encode_sattr3(xdr, args->sattr, userns);
1151 static void nfs3_xdr_enc_mknod3args(struct rpc_rqst *req,
1152 struct xdr_stream *xdr,
1155 const struct nfs3_mknodargs *args = data;
1157 encode_diropargs3(xdr, args->fh, args->name, args->len);
1158 encode_mknoddata3(xdr, args, rpc_rqst_userns(req));
1162 * 3.3.12 REMOVE3args
1164 * struct REMOVE3args {
1165 * diropargs3 object;
1168 static void nfs3_xdr_enc_remove3args(struct rpc_rqst *req,
1169 struct xdr_stream *xdr,
1172 const struct nfs_removeargs *args = data;
1174 encode_diropargs3(xdr, args->fh, args->name.name, args->name.len);
1178 * 3.3.14 RENAME3args
1180 * struct RENAME3args {
1185 static void nfs3_xdr_enc_rename3args(struct rpc_rqst *req,
1186 struct xdr_stream *xdr,
1189 const struct nfs_renameargs *args = data;
1190 const struct qstr *old = args->old_name;
1191 const struct qstr *new = args->new_name;
1193 encode_diropargs3(xdr, args->old_dir, old->name, old->len);
1194 encode_diropargs3(xdr, args->new_dir, new->name, new->len);
1200 * struct LINK3args {
1205 static void nfs3_xdr_enc_link3args(struct rpc_rqst *req,
1206 struct xdr_stream *xdr,
1209 const struct nfs3_linkargs *args = data;
1211 encode_nfs_fh3(xdr, args->fromfh);
1212 encode_diropargs3(xdr, args->tofh, args->toname, args->tolen);
1216 * 3.3.16 READDIR3args
1218 * struct READDIR3args {
1221 * cookieverf3 cookieverf;
1225 static void encode_readdir3args(struct xdr_stream *xdr,
1226 const struct nfs3_readdirargs *args)
1230 encode_nfs_fh3(xdr, args->fh);
1232 p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4);
1233 p = xdr_encode_cookie3(p, args->cookie);
1234 p = xdr_encode_cookieverf3(p, args->verf);
1235 *p = cpu_to_be32(args->count);
1238 static void nfs3_xdr_enc_readdir3args(struct rpc_rqst *req,
1239 struct xdr_stream *xdr,
1242 const struct nfs3_readdirargs *args = data;
1244 encode_readdir3args(xdr, args);
1245 rpc_prepare_reply_pages(req, args->pages, 0, args->count,
1246 NFS3_readdirres_sz - NFS3_pagepad_sz);
1250 * 3.3.17 READDIRPLUS3args
1252 * struct READDIRPLUS3args {
1255 * cookieverf3 cookieverf;
1260 static void encode_readdirplus3args(struct xdr_stream *xdr,
1261 const struct nfs3_readdirargs *args)
1265 encode_nfs_fh3(xdr, args->fh);
1267 p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4 + 4);
1268 p = xdr_encode_cookie3(p, args->cookie);
1269 p = xdr_encode_cookieverf3(p, args->verf);
1272 * readdirplus: need dircount + buffer size.
1273 * We just make sure we make dircount big enough
1275 *p++ = cpu_to_be32(args->count >> 3);
1277 *p = cpu_to_be32(args->count);
1280 static void nfs3_xdr_enc_readdirplus3args(struct rpc_rqst *req,
1281 struct xdr_stream *xdr,
1284 const struct nfs3_readdirargs *args = data;
1286 encode_readdirplus3args(xdr, args);
1287 rpc_prepare_reply_pages(req, args->pages, 0, args->count,
1288 NFS3_readdirres_sz - NFS3_pagepad_sz);
1292 * 3.3.21 COMMIT3args
1294 * struct COMMIT3args {
1300 static void encode_commit3args(struct xdr_stream *xdr,
1301 const struct nfs_commitargs *args)
1305 encode_nfs_fh3(xdr, args->fh);
1307 p = xdr_reserve_space(xdr, 8 + 4);
1308 p = xdr_encode_hyper(p, args->offset);
1309 *p = cpu_to_be32(args->count);
1312 static void nfs3_xdr_enc_commit3args(struct rpc_rqst *req,
1313 struct xdr_stream *xdr,
1316 const struct nfs_commitargs *args = data;
1318 encode_commit3args(xdr, args);
1321 #ifdef CONFIG_NFS_V3_ACL
1323 static void nfs3_xdr_enc_getacl3args(struct rpc_rqst *req,
1324 struct xdr_stream *xdr,
1327 const struct nfs3_getaclargs *args = data;
1329 encode_nfs_fh3(xdr, args->fh);
1330 encode_uint32(xdr, args->mask);
1331 if (args->mask & (NFS_ACL | NFS_DFACL)) {
1332 rpc_prepare_reply_pages(req, args->pages, 0,
1333 NFSACL_MAXPAGES << PAGE_SHIFT,
1334 ACL3_getaclres_sz - NFS3_pagepad_sz);
1335 req->rq_rcv_buf.flags |= XDRBUF_SPARSE_PAGES;
1339 static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req,
1340 struct xdr_stream *xdr,
1343 const struct nfs3_setaclargs *args = data;
1347 encode_nfs_fh3(xdr, NFS_FH(args->inode));
1348 encode_uint32(xdr, args->mask);
1350 base = req->rq_slen;
1351 if (args->npages != 0)
1352 xdr_write_pages(xdr, args->pages, 0, args->len);
1354 xdr_reserve_space(xdr, args->len);
1356 error = nfsacl_encode(xdr->buf, base, args->inode,
1357 (args->mask & NFS_ACL) ?
1358 args->acl_access : NULL, 1, 0);
1359 /* FIXME: this is just broken */
1361 error = nfsacl_encode(xdr->buf, base + error, args->inode,
1362 (args->mask & NFS_DFACL) ?
1363 args->acl_default : NULL, 1,
1368 #endif /* CONFIG_NFS_V3_ACL */
1371 * NFSv3 XDR decode functions
1373 * NFSv3 result types are defined in section 3.3 of RFC 1813:
1374 * "NFS Version 3 Protocol Specification".
1380 * struct GETATTR3resok {
1381 * fattr3 obj_attributes;
1384 * union GETATTR3res switch (nfsstat3 status) {
1386 * GETATTR3resok resok;
1391 static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
1392 struct xdr_stream *xdr,
1395 enum nfs_stat status;
1398 error = decode_nfsstat3(xdr, &status);
1399 if (unlikely(error))
1401 if (status != NFS3_OK)
1403 error = decode_fattr3(xdr, result, rpc_rqst_userns(req));
1407 return nfs3_stat_to_errno(status);
1413 * struct SETATTR3resok {
1417 * struct SETATTR3resfail {
1421 * union SETATTR3res switch (nfsstat3 status) {
1423 * SETATTR3resok resok;
1425 * SETATTR3resfail resfail;
1428 static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
1429 struct xdr_stream *xdr,
1432 enum nfs_stat status;
1435 error = decode_nfsstat3(xdr, &status);
1436 if (unlikely(error))
1438 error = decode_wcc_data(xdr, result, rpc_rqst_userns(req));
1439 if (unlikely(error))
1441 if (status != NFS3_OK)
1446 return nfs3_stat_to_errno(status);
1452 * struct LOOKUP3resok {
1454 * post_op_attr obj_attributes;
1455 * post_op_attr dir_attributes;
1458 * struct LOOKUP3resfail {
1459 * post_op_attr dir_attributes;
1462 * union LOOKUP3res switch (nfsstat3 status) {
1464 * LOOKUP3resok resok;
1466 * LOOKUP3resfail resfail;
1469 static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req,
1470 struct xdr_stream *xdr,
1473 struct user_namespace *userns = rpc_rqst_userns(req);
1474 struct nfs3_diropres *result = data;
1475 enum nfs_stat status;
1478 error = decode_nfsstat3(xdr, &status);
1479 if (unlikely(error))
1481 if (status != NFS3_OK)
1483 error = decode_nfs_fh3(xdr, result->fh);
1484 if (unlikely(error))
1486 error = decode_post_op_attr(xdr, result->fattr, userns);
1487 if (unlikely(error))
1489 error = decode_post_op_attr(xdr, result->dir_attr, userns);
1493 error = decode_post_op_attr(xdr, result->dir_attr, userns);
1494 if (unlikely(error))
1496 return nfs3_stat_to_errno(status);
1502 * struct ACCESS3resok {
1503 * post_op_attr obj_attributes;
1507 * struct ACCESS3resfail {
1508 * post_op_attr obj_attributes;
1511 * union ACCESS3res switch (nfsstat3 status) {
1513 * ACCESS3resok resok;
1515 * ACCESS3resfail resfail;
1518 static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
1519 struct xdr_stream *xdr,
1522 struct nfs3_accessres *result = data;
1523 enum nfs_stat status;
1526 error = decode_nfsstat3(xdr, &status);
1527 if (unlikely(error))
1529 error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
1530 if (unlikely(error))
1532 if (status != NFS3_OK)
1534 error = decode_uint32(xdr, &result->access);
1538 return nfs3_stat_to_errno(status);
1542 * 3.3.5 READLINK3res
1544 * struct READLINK3resok {
1545 * post_op_attr symlink_attributes;
1549 * struct READLINK3resfail {
1550 * post_op_attr symlink_attributes;
1553 * union READLINK3res switch (nfsstat3 status) {
1555 * READLINK3resok resok;
1557 * READLINK3resfail resfail;
1560 static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
1561 struct xdr_stream *xdr,
1564 enum nfs_stat status;
1567 error = decode_nfsstat3(xdr, &status);
1568 if (unlikely(error))
1570 error = decode_post_op_attr(xdr, result, rpc_rqst_userns(req));
1571 if (unlikely(error))
1573 if (status != NFS3_OK)
1575 error = decode_nfspath3(xdr);
1579 return nfs3_stat_to_errno(status);
1585 * struct READ3resok {
1586 * post_op_attr file_attributes;
1592 * struct READ3resfail {
1593 * post_op_attr file_attributes;
1596 * union READ3res switch (nfsstat3 status) {
1600 * READ3resfail resfail;
1603 static int decode_read3resok(struct xdr_stream *xdr,
1604 struct nfs_pgio_res *result)
1606 u32 eof, count, ocount, recvd;
1609 p = xdr_inline_decode(xdr, 4 + 4 + 4);
1612 count = be32_to_cpup(p++);
1613 eof = be32_to_cpup(p++);
1614 ocount = be32_to_cpup(p++);
1615 if (unlikely(ocount != count))
1617 recvd = xdr_read_pages(xdr, count);
1618 if (unlikely(count > recvd))
1622 result->count = count;
1625 dprintk("NFS: READ count doesn't match length of opaque: "
1626 "count %u != ocount %u\n", count, ocount);
1629 dprintk("NFS: server cheating in read result: "
1630 "count %u > recvd %u\n", count, recvd);
1636 static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1639 struct nfs_pgio_res *result = data;
1641 enum nfs_stat status;
1644 pos = xdr_stream_pos(xdr);
1645 error = decode_nfsstat3(xdr, &status);
1646 if (unlikely(error))
1648 error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
1649 if (unlikely(error))
1651 result->op_status = status;
1652 if (status != NFS3_OK)
1654 result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
1655 error = decode_read3resok(xdr, result);
1659 return nfs3_stat_to_errno(status);
1671 * struct WRITE3resok {
1672 * wcc_data file_wcc;
1674 * stable_how committed;
1678 * struct WRITE3resfail {
1679 * wcc_data file_wcc;
1682 * union WRITE3res switch (nfsstat3 status) {
1684 * WRITE3resok resok;
1686 * WRITE3resfail resfail;
1689 static int decode_write3resok(struct xdr_stream *xdr,
1690 struct nfs_pgio_res *result)
1694 p = xdr_inline_decode(xdr, 4 + 4);
1697 result->count = be32_to_cpup(p++);
1698 result->verf->committed = be32_to_cpup(p++);
1699 if (unlikely(result->verf->committed > NFS_FILE_SYNC))
1701 if (decode_writeverf3(xdr, &result->verf->verifier))
1703 return result->count;
1705 dprintk("NFS: bad stable_how value: %u\n", result->verf->committed);
1709 static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1712 struct nfs_pgio_res *result = data;
1713 enum nfs_stat status;
1716 error = decode_nfsstat3(xdr, &status);
1717 if (unlikely(error))
1719 error = decode_wcc_data(xdr, result->fattr, rpc_rqst_userns(req));
1720 if (unlikely(error))
1722 result->op_status = status;
1723 if (status != NFS3_OK)
1725 error = decode_write3resok(xdr, result);
1729 return nfs3_stat_to_errno(status);
1735 * struct CREATE3resok {
1737 * post_op_attr obj_attributes;
1741 * struct CREATE3resfail {
1745 * union CREATE3res switch (nfsstat3 status) {
1747 * CREATE3resok resok;
1749 * CREATE3resfail resfail;
1752 static int decode_create3resok(struct xdr_stream *xdr,
1753 struct nfs3_diropres *result,
1754 struct user_namespace *userns)
1758 error = decode_post_op_fh3(xdr, result->fh);
1759 if (unlikely(error))
1761 error = decode_post_op_attr(xdr, result->fattr, userns);
1762 if (unlikely(error))
1764 /* The server isn't required to return a file handle.
1765 * If it didn't, force the client to perform a LOOKUP
1766 * to determine the correct file handle and attribute
1767 * values for the new object. */
1768 if (result->fh->size == 0)
1769 result->fattr->valid = 0;
1770 error = decode_wcc_data(xdr, result->dir_attr, userns);
1775 static int nfs3_xdr_dec_create3res(struct rpc_rqst *req,
1776 struct xdr_stream *xdr,
1779 struct user_namespace *userns = rpc_rqst_userns(req);
1780 struct nfs3_diropres *result = data;
1781 enum nfs_stat status;
1784 error = decode_nfsstat3(xdr, &status);
1785 if (unlikely(error))
1787 if (status != NFS3_OK)
1789 error = decode_create3resok(xdr, result, userns);
1793 error = decode_wcc_data(xdr, result->dir_attr, userns);
1794 if (unlikely(error))
1796 return nfs3_stat_to_errno(status);
1802 * struct REMOVE3resok {
1806 * struct REMOVE3resfail {
1810 * union REMOVE3res switch (nfsstat3 status) {
1812 * REMOVE3resok resok;
1814 * REMOVE3resfail resfail;
1817 static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
1818 struct xdr_stream *xdr,
1821 struct nfs_removeres *result = data;
1822 enum nfs_stat status;
1825 error = decode_nfsstat3(xdr, &status);
1826 if (unlikely(error))
1828 error = decode_wcc_data(xdr, result->dir_attr, rpc_rqst_userns(req));
1829 if (unlikely(error))
1831 if (status != NFS3_OK)
1836 return nfs3_stat_to_errno(status);
1842 * struct RENAME3resok {
1843 * wcc_data fromdir_wcc;
1844 * wcc_data todir_wcc;
1847 * struct RENAME3resfail {
1848 * wcc_data fromdir_wcc;
1849 * wcc_data todir_wcc;
1852 * union RENAME3res switch (nfsstat3 status) {
1854 * RENAME3resok resok;
1856 * RENAME3resfail resfail;
1859 static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
1860 struct xdr_stream *xdr,
1863 struct user_namespace *userns = rpc_rqst_userns(req);
1864 struct nfs_renameres *result = data;
1865 enum nfs_stat status;
1868 error = decode_nfsstat3(xdr, &status);
1869 if (unlikely(error))
1871 error = decode_wcc_data(xdr, result->old_fattr, userns);
1872 if (unlikely(error))
1874 error = decode_wcc_data(xdr, result->new_fattr, userns);
1875 if (unlikely(error))
1877 if (status != NFS3_OK)
1882 return nfs3_stat_to_errno(status);
1888 * struct LINK3resok {
1889 * post_op_attr file_attributes;
1890 * wcc_data linkdir_wcc;
1893 * struct LINK3resfail {
1894 * post_op_attr file_attributes;
1895 * wcc_data linkdir_wcc;
1898 * union LINK3res switch (nfsstat3 status) {
1902 * LINK3resfail resfail;
1905 static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1908 struct user_namespace *userns = rpc_rqst_userns(req);
1909 struct nfs3_linkres *result = data;
1910 enum nfs_stat status;
1913 error = decode_nfsstat3(xdr, &status);
1914 if (unlikely(error))
1916 error = decode_post_op_attr(xdr, result->fattr, userns);
1917 if (unlikely(error))
1919 error = decode_wcc_data(xdr, result->dir_attr, userns);
1920 if (unlikely(error))
1922 if (status != NFS3_OK)
1927 return nfs3_stat_to_errno(status);
1931 * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in
1932 * the local page cache
1933 * @xdr: XDR stream where entry resides
1934 * @entry: buffer to fill in with entry data
1935 * @plus: boolean indicating whether this should be a readdirplus entry
1937 * Returns zero if successful, otherwise a negative errno value is
1940 * This function is not invoked during READDIR reply decoding, but
1941 * rather whenever an application invokes the getdents(2) system call
1942 * on a directory already in our cache.
1950 * fhandle3 filehandle;
1951 * post_op_attr3 attributes;
1952 * entry3 *nextentry;
1956 * struct entryplus3 {
1960 * post_op_attr name_attributes;
1961 * post_op_fh3 name_handle;
1962 * entryplus3 *nextentry;
1965 int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
1968 struct user_namespace *userns = rpc_userns(entry->server->client);
1969 struct nfs_entry old = *entry;
1974 p = xdr_inline_decode(xdr, 4);
1977 if (*p == xdr_zero) {
1978 p = xdr_inline_decode(xdr, 4);
1987 error = decode_fileid3(xdr, &entry->ino);
1988 if (unlikely(error))
1991 error = decode_inline_filename3(xdr, &entry->name, &entry->len);
1992 if (unlikely(error))
1995 error = decode_cookie3(xdr, &new_cookie);
1996 if (unlikely(error))
1999 entry->d_type = DT_UNKNOWN;
2002 entry->fattr->valid = 0;
2003 error = decode_post_op_attr(xdr, entry->fattr, userns);
2004 if (unlikely(error))
2006 if (entry->fattr->valid & NFS_ATTR_FATTR_V3)
2007 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
2009 if (entry->fattr->fileid != entry->ino) {
2010 entry->fattr->mounted_on_fileid = entry->ino;
2011 entry->fattr->valid |= NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
2014 /* In fact, a post_op_fh3: */
2015 p = xdr_inline_decode(xdr, 4);
2018 if (*p != xdr_zero) {
2019 error = decode_nfs_fh3(xdr, entry->fh);
2020 if (unlikely(error)) {
2021 if (error == -E2BIG)
2026 zero_nfs_fh3(entry->fh);
2029 entry->prev_cookie = entry->cookie;
2030 entry->cookie = new_cookie;
2035 dprintk("NFS: directory entry contains invalid file handle\n");
2041 * 3.3.16 READDIR3res
2048 * struct READDIR3resok {
2049 * post_op_attr dir_attributes;
2050 * cookieverf3 cookieverf;
2054 * struct READDIR3resfail {
2055 * post_op_attr dir_attributes;
2058 * union READDIR3res switch (nfsstat3 status) {
2060 * READDIR3resok resok;
2062 * READDIR3resfail resfail;
2065 * Read the directory contents into the page cache, but otherwise
2066 * don't touch them. The actual decoding is done by nfs3_decode_entry()
2067 * during subsequent nfs_readdir() calls.
2069 static int decode_dirlist3(struct xdr_stream *xdr)
2071 return xdr_read_pages(xdr, xdr->buf->page_len);
2074 static int decode_readdir3resok(struct xdr_stream *xdr,
2075 struct nfs3_readdirres *result,
2076 struct user_namespace *userns)
2080 error = decode_post_op_attr(xdr, result->dir_attr, userns);
2081 if (unlikely(error))
2083 /* XXX: do we need to check if result->verf != NULL ? */
2084 error = decode_cookieverf3(xdr, result->verf);
2085 if (unlikely(error))
2087 error = decode_dirlist3(xdr);
2092 static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req,
2093 struct xdr_stream *xdr,
2096 struct nfs3_readdirres *result = data;
2097 enum nfs_stat status;
2100 error = decode_nfsstat3(xdr, &status);
2101 if (unlikely(error))
2103 if (status != NFS3_OK)
2105 error = decode_readdir3resok(xdr, result, rpc_rqst_userns(req));
2109 error = decode_post_op_attr(xdr, result->dir_attr, rpc_rqst_userns(req));
2110 if (unlikely(error))
2112 return nfs3_stat_to_errno(status);
2118 * struct FSSTAT3resok {
2119 * post_op_attr obj_attributes;
2129 * struct FSSTAT3resfail {
2130 * post_op_attr obj_attributes;
2133 * union FSSTAT3res switch (nfsstat3 status) {
2135 * FSSTAT3resok resok;
2137 * FSSTAT3resfail resfail;
2140 static int decode_fsstat3resok(struct xdr_stream *xdr,
2141 struct nfs_fsstat *result)
2145 p = xdr_inline_decode(xdr, 8 * 6 + 4);
2148 p = xdr_decode_size3(p, &result->tbytes);
2149 p = xdr_decode_size3(p, &result->fbytes);
2150 p = xdr_decode_size3(p, &result->abytes);
2151 p = xdr_decode_size3(p, &result->tfiles);
2152 p = xdr_decode_size3(p, &result->ffiles);
2153 xdr_decode_size3(p, &result->afiles);
2154 /* ignore invarsec */
2158 static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
2159 struct xdr_stream *xdr,
2162 struct nfs_fsstat *result = data;
2163 enum nfs_stat status;
2166 error = decode_nfsstat3(xdr, &status);
2167 if (unlikely(error))
2169 error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
2170 if (unlikely(error))
2172 if (status != NFS3_OK)
2174 error = decode_fsstat3resok(xdr, result);
2178 return nfs3_stat_to_errno(status);
2184 * struct FSINFO3resok {
2185 * post_op_attr obj_attributes;
2193 * size3 maxfilesize;
2194 * nfstime3 time_delta;
2195 * uint32 properties;
2198 * struct FSINFO3resfail {
2199 * post_op_attr obj_attributes;
2202 * union FSINFO3res switch (nfsstat3 status) {
2204 * FSINFO3resok resok;
2206 * FSINFO3resfail resfail;
2209 static int decode_fsinfo3resok(struct xdr_stream *xdr,
2210 struct nfs_fsinfo *result)
2214 p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4);
2217 result->rtmax = be32_to_cpup(p++);
2218 result->rtpref = be32_to_cpup(p++);
2219 result->rtmult = be32_to_cpup(p++);
2220 result->wtmax = be32_to_cpup(p++);
2221 result->wtpref = be32_to_cpup(p++);
2222 result->wtmult = be32_to_cpup(p++);
2223 result->dtpref = be32_to_cpup(p++);
2224 p = xdr_decode_size3(p, &result->maxfilesize);
2225 xdr_decode_nfstime3(p, &result->time_delta);
2227 /* ignore properties */
2228 result->lease_time = 0;
2232 static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
2233 struct xdr_stream *xdr,
2236 struct nfs_fsinfo *result = data;
2237 enum nfs_stat status;
2240 error = decode_nfsstat3(xdr, &status);
2241 if (unlikely(error))
2243 error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
2244 if (unlikely(error))
2246 if (status != NFS3_OK)
2248 error = decode_fsinfo3resok(xdr, result);
2252 return nfs3_stat_to_errno(status);
2256 * 3.3.20 PATHCONF3res
2258 * struct PATHCONF3resok {
2259 * post_op_attr obj_attributes;
2263 * bool chown_restricted;
2264 * bool case_insensitive;
2265 * bool case_preserving;
2268 * struct PATHCONF3resfail {
2269 * post_op_attr obj_attributes;
2272 * union PATHCONF3res switch (nfsstat3 status) {
2274 * PATHCONF3resok resok;
2276 * PATHCONF3resfail resfail;
2279 static int decode_pathconf3resok(struct xdr_stream *xdr,
2280 struct nfs_pathconf *result)
2284 p = xdr_inline_decode(xdr, 4 * 6);
2287 result->max_link = be32_to_cpup(p++);
2288 result->max_namelen = be32_to_cpup(p);
2289 /* ignore remaining fields */
2293 static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
2294 struct xdr_stream *xdr,
2297 struct nfs_pathconf *result = data;
2298 enum nfs_stat status;
2301 error = decode_nfsstat3(xdr, &status);
2302 if (unlikely(error))
2304 error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
2305 if (unlikely(error))
2307 if (status != NFS3_OK)
2309 error = decode_pathconf3resok(xdr, result);
2313 return nfs3_stat_to_errno(status);
2319 * struct COMMIT3resok {
2320 * wcc_data file_wcc;
2324 * struct COMMIT3resfail {
2325 * wcc_data file_wcc;
2328 * union COMMIT3res switch (nfsstat3 status) {
2330 * COMMIT3resok resok;
2332 * COMMIT3resfail resfail;
2335 static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
2336 struct xdr_stream *xdr,
2339 struct nfs_commitres *result = data;
2340 struct nfs_writeverf *verf = result->verf;
2341 enum nfs_stat status;
2344 error = decode_nfsstat3(xdr, &status);
2345 if (unlikely(error))
2347 error = decode_wcc_data(xdr, result->fattr, rpc_rqst_userns(req));
2348 if (unlikely(error))
2350 result->op_status = status;
2351 if (status != NFS3_OK)
2353 error = decode_writeverf3(xdr, &verf->verifier);
2355 verf->committed = NFS_FILE_SYNC;
2359 return nfs3_stat_to_errno(status);
2362 #ifdef CONFIG_NFS_V3_ACL
2364 static inline int decode_getacl3resok(struct xdr_stream *xdr,
2365 struct nfs3_getaclres *result,
2366 struct user_namespace *userns)
2368 struct posix_acl **acl;
2369 unsigned int *aclcnt;
2373 error = decode_post_op_attr(xdr, result->fattr, userns);
2374 if (unlikely(error))
2376 error = decode_uint32(xdr, &result->mask);
2377 if (unlikely(error))
2380 if (result->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
2383 hdrlen = xdr_stream_pos(xdr);
2386 if (result->mask & NFS_ACL)
2387 acl = &result->acl_access;
2389 if (result->mask & NFS_ACLCNT)
2390 aclcnt = &result->acl_access_count;
2391 error = nfsacl_decode(xdr->buf, hdrlen, aclcnt, acl);
2392 if (unlikely(error <= 0))
2396 if (result->mask & NFS_DFACL)
2397 acl = &result->acl_default;
2399 if (result->mask & NFS_DFACLCNT)
2400 aclcnt = &result->acl_default_count;
2401 error = nfsacl_decode(xdr->buf, hdrlen + error, aclcnt, acl);
2402 if (unlikely(error <= 0))
2409 static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
2410 struct xdr_stream *xdr,
2413 enum nfs_stat status;
2416 error = decode_nfsstat3(xdr, &status);
2417 if (unlikely(error))
2419 if (status != NFS3_OK)
2421 error = decode_getacl3resok(xdr, result, rpc_rqst_userns(req));
2425 return nfs3_stat_to_errno(status);
2428 static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
2429 struct xdr_stream *xdr,
2432 enum nfs_stat status;
2435 error = decode_nfsstat3(xdr, &status);
2436 if (unlikely(error))
2438 if (status != NFS3_OK)
2440 error = decode_post_op_attr(xdr, result, rpc_rqst_userns(req));
2444 return nfs3_stat_to_errno(status);
2447 #endif /* CONFIG_NFS_V3_ACL */
2451 * We need to translate between nfs status return values and
2452 * the local errno values which may not be the same.
2454 static const struct {
2459 { NFSERR_PERM, -EPERM },
2460 { NFSERR_NOENT, -ENOENT },
2461 { NFSERR_IO, -errno_NFSERR_IO},
2462 { NFSERR_NXIO, -ENXIO },
2463 /* { NFSERR_EAGAIN, -EAGAIN }, */
2464 { NFSERR_ACCES, -EACCES },
2465 { NFSERR_EXIST, -EEXIST },
2466 { NFSERR_XDEV, -EXDEV },
2467 { NFSERR_NODEV, -ENODEV },
2468 { NFSERR_NOTDIR, -ENOTDIR },
2469 { NFSERR_ISDIR, -EISDIR },
2470 { NFSERR_INVAL, -EINVAL },
2471 { NFSERR_FBIG, -EFBIG },
2472 { NFSERR_NOSPC, -ENOSPC },
2473 { NFSERR_ROFS, -EROFS },
2474 { NFSERR_MLINK, -EMLINK },
2475 { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
2476 { NFSERR_NOTEMPTY, -ENOTEMPTY },
2477 { NFSERR_DQUOT, -EDQUOT },
2478 { NFSERR_STALE, -ESTALE },
2479 { NFSERR_REMOTE, -EREMOTE },
2481 { NFSERR_WFLUSH, -EWFLUSH },
2483 { NFSERR_BADHANDLE, -EBADHANDLE },
2484 { NFSERR_NOT_SYNC, -ENOTSYNC },
2485 { NFSERR_BAD_COOKIE, -EBADCOOKIE },
2486 { NFSERR_NOTSUPP, -ENOTSUPP },
2487 { NFSERR_TOOSMALL, -ETOOSMALL },
2488 { NFSERR_SERVERFAULT, -EREMOTEIO },
2489 { NFSERR_BADTYPE, -EBADTYPE },
2490 { NFSERR_JUKEBOX, -EJUKEBOX },
2495 * nfs3_stat_to_errno - convert an NFS status code to a local errno
2496 * @status: NFS status code to convert
2498 * Returns a local errno value, or -EIO if the NFS status code is
2499 * not recognized. This function is used jointly by NFSv2 and NFSv3.
2501 static int nfs3_stat_to_errno(enum nfs_stat status)
2505 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
2506 if (nfs_errtbl[i].stat == (int)status)
2507 return nfs_errtbl[i].errno;
2509 dprintk("NFS: Unrecognized nfs status value: %u\n", status);
2510 return nfs_errtbl[i].errno;
2514 #define PROC(proc, argtype, restype, timer) \
2515 [NFS3PROC_##proc] = { \
2516 .p_proc = NFS3PROC_##proc, \
2517 .p_encode = nfs3_xdr_enc_##argtype##3args, \
2518 .p_decode = nfs3_xdr_dec_##restype##3res, \
2519 .p_arglen = NFS3_##argtype##args_sz, \
2520 .p_replen = NFS3_##restype##res_sz, \
2522 .p_statidx = NFS3PROC_##proc, \
2526 const struct rpc_procinfo nfs3_procedures[] = {
2527 PROC(GETATTR, getattr, getattr, 1),
2528 PROC(SETATTR, setattr, setattr, 0),
2529 PROC(LOOKUP, lookup, lookup, 2),
2530 PROC(ACCESS, access, access, 1),
2531 PROC(READLINK, readlink, readlink, 3),
2532 PROC(READ, read, read, 3),
2533 PROC(WRITE, write, write, 4),
2534 PROC(CREATE, create, create, 0),
2535 PROC(MKDIR, mkdir, create, 0),
2536 PROC(SYMLINK, symlink, create, 0),
2537 PROC(MKNOD, mknod, create, 0),
2538 PROC(REMOVE, remove, remove, 0),
2539 PROC(RMDIR, lookup, setattr, 0),
2540 PROC(RENAME, rename, rename, 0),
2541 PROC(LINK, link, link, 0),
2542 PROC(READDIR, readdir, readdir, 3),
2543 PROC(READDIRPLUS, readdirplus, readdir, 3),
2544 PROC(FSSTAT, getattr, fsstat, 0),
2545 PROC(FSINFO, getattr, fsinfo, 0),
2546 PROC(PATHCONF, getattr, pathconf, 0),
2547 PROC(COMMIT, commit, commit, 5),
2550 static unsigned int nfs_version3_counts[ARRAY_SIZE(nfs3_procedures)];
2551 const struct rpc_version nfs_version3 = {
2553 .nrprocs = ARRAY_SIZE(nfs3_procedures),
2554 .procs = nfs3_procedures,
2555 .counts = nfs_version3_counts,
2558 #ifdef CONFIG_NFS_V3_ACL
2559 static const struct rpc_procinfo nfs3_acl_procedures[] = {
2560 [ACLPROC3_GETACL] = {
2561 .p_proc = ACLPROC3_GETACL,
2562 .p_encode = nfs3_xdr_enc_getacl3args,
2563 .p_decode = nfs3_xdr_dec_getacl3res,
2564 .p_arglen = ACL3_getaclargs_sz,
2565 .p_replen = ACL3_getaclres_sz,
2569 [ACLPROC3_SETACL] = {
2570 .p_proc = ACLPROC3_SETACL,
2571 .p_encode = nfs3_xdr_enc_setacl3args,
2572 .p_decode = nfs3_xdr_dec_setacl3res,
2573 .p_arglen = ACL3_setaclargs_sz,
2574 .p_replen = ACL3_setaclres_sz,
2580 static unsigned int nfs3_acl_counts[ARRAY_SIZE(nfs3_acl_procedures)];
2581 const struct rpc_version nfsacl_version3 = {
2583 .nrprocs = ARRAY_SIZE(nfs3_acl_procedures),
2584 .procs = nfs3_acl_procedures,
2585 .counts = nfs3_acl_counts,
2587 #endif /* CONFIG_NFS_V3_ACL */