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_fhandle_sz (1+16)
37 #define NFS3_fh_sz (NFS3_fhandle_sz) /* shorthand */
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+1)
73 #define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3+1)
74 #define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4)
75 #define NFS3_createres_sz (1+NFS3_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+1)
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)+1)
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 * Encode/decode NFSv3 basic data types
110 * Basic NFSv3 data types are defined in section 2.5 of RFC 1813:
111 * "NFS Version 3 Protocol Specification".
113 * Not all basic data types have their own encoding and decoding
114 * functions. For run-time efficiency, some data types are encoded
118 static void encode_uint32(struct xdr_stream *xdr, u32 value)
120 __be32 *p = xdr_reserve_space(xdr, 4);
121 *p = cpu_to_be32(value);
124 static int decode_uint32(struct xdr_stream *xdr, u32 *value)
128 p = xdr_inline_decode(xdr, 4);
131 *value = be32_to_cpup(p);
135 static int decode_uint64(struct xdr_stream *xdr, u64 *value)
139 p = xdr_inline_decode(xdr, 8);
142 xdr_decode_hyper(p, value);
149 * typedef uint64 fileid3;
151 static __be32 *xdr_decode_fileid3(__be32 *p, u64 *fileid)
153 return xdr_decode_hyper(p, fileid);
156 static int decode_fileid3(struct xdr_stream *xdr, u64 *fileid)
158 return decode_uint64(xdr, fileid);
164 * typedef string filename3<>;
166 static void encode_filename3(struct xdr_stream *xdr,
167 const char *name, u32 length)
171 WARN_ON_ONCE(length > NFS3_MAXNAMLEN);
172 p = xdr_reserve_space(xdr, 4 + length);
173 xdr_encode_opaque(p, name, length);
176 static int decode_inline_filename3(struct xdr_stream *xdr,
177 const char **name, u32 *length)
182 p = xdr_inline_decode(xdr, 4);
185 count = be32_to_cpup(p);
186 if (count > NFS3_MAXNAMLEN)
187 goto out_nametoolong;
188 p = xdr_inline_decode(xdr, count);
191 *name = (const char *)p;
196 dprintk("NFS: returned filename too long: %u\n", count);
197 return -ENAMETOOLONG;
203 * typedef string nfspath3<>;
205 static void encode_nfspath3(struct xdr_stream *xdr, struct page **pages,
208 encode_uint32(xdr, length);
209 xdr_write_pages(xdr, pages, 0, length);
212 static int decode_nfspath3(struct xdr_stream *xdr)
217 p = xdr_inline_decode(xdr, 4);
220 count = be32_to_cpup(p);
221 if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN))
222 goto out_nametoolong;
223 recvd = xdr_read_pages(xdr, count);
224 if (unlikely(count > recvd))
226 xdr_terminate_string(xdr->buf, count);
230 dprintk("NFS: returned pathname too long: %u\n", count);
231 return -ENAMETOOLONG;
233 dprintk("NFS: server cheating in pathname result: "
234 "count %u > recvd %u\n", count, recvd);
241 * typedef uint64 cookie3
243 static __be32 *xdr_encode_cookie3(__be32 *p, u64 cookie)
245 return xdr_encode_hyper(p, cookie);
248 static int decode_cookie3(struct xdr_stream *xdr, u64 *cookie)
250 return decode_uint64(xdr, cookie);
256 * typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
258 static __be32 *xdr_encode_cookieverf3(__be32 *p, const __be32 *verifier)
260 memcpy(p, verifier, NFS3_COOKIEVERFSIZE);
261 return p + XDR_QUADLEN(NFS3_COOKIEVERFSIZE);
264 static int decode_cookieverf3(struct xdr_stream *xdr, __be32 *verifier)
268 p = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE);
271 memcpy(verifier, p, NFS3_COOKIEVERFSIZE);
278 * typedef opaque createverf3[NFS3_CREATEVERFSIZE];
280 static void encode_createverf3(struct xdr_stream *xdr, const __be32 *verifier)
284 p = xdr_reserve_space(xdr, NFS3_CREATEVERFSIZE);
285 memcpy(p, verifier, NFS3_CREATEVERFSIZE);
288 static int decode_writeverf3(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
292 p = xdr_inline_decode(xdr, NFS3_WRITEVERFSIZE);
295 memcpy(verifier->data, p, NFS3_WRITEVERFSIZE);
302 * typedef uint64 size3;
304 static __be32 *xdr_decode_size3(__be32 *p, u64 *size)
306 return xdr_decode_hyper(p, size);
317 #define NFS3_OK NFS_OK
319 static int decode_nfsstat3(struct xdr_stream *xdr, enum nfs_stat *status)
323 p = xdr_inline_decode(xdr, 4);
326 if (unlikely(*p != cpu_to_be32(NFS3_OK)))
331 *status = be32_to_cpup(p);
332 trace_nfs_xdr_status((int)*status);
349 static void encode_ftype3(struct xdr_stream *xdr, const u32 type)
351 encode_uint32(xdr, type);
354 static __be32 *xdr_decode_ftype3(__be32 *p, umode_t *mode)
358 type = be32_to_cpup(p++);
361 *mode = nfs_type2fmt[type];
373 static void encode_specdata3(struct xdr_stream *xdr, const dev_t rdev)
377 p = xdr_reserve_space(xdr, 8);
378 *p++ = cpu_to_be32(MAJOR(rdev));
379 *p = cpu_to_be32(MINOR(rdev));
382 static __be32 *xdr_decode_specdata3(__be32 *p, dev_t *rdev)
384 unsigned int major, minor;
386 major = be32_to_cpup(p++);
387 minor = be32_to_cpup(p++);
388 *rdev = MKDEV(major, minor);
389 if (MAJOR(*rdev) != major || MINOR(*rdev) != minor)
398 * opaque data<NFS3_FHSIZE>;
401 static void encode_nfs_fh3(struct xdr_stream *xdr, const struct nfs_fh *fh)
405 WARN_ON_ONCE(fh->size > NFS3_FHSIZE);
406 p = xdr_reserve_space(xdr, 4 + fh->size);
407 xdr_encode_opaque(p, fh->data, fh->size);
410 static int decode_nfs_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
415 p = xdr_inline_decode(xdr, 4);
418 length = be32_to_cpup(p++);
419 if (unlikely(length > NFS3_FHSIZE))
421 p = xdr_inline_decode(xdr, length);
425 memcpy(fh->data, p, length);
428 dprintk("NFS: file handle size (%u) too big\n", length);
432 static void zero_nfs_fh3(struct nfs_fh *fh)
434 memset(fh, 0, sizeof(*fh));
445 static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec *timep)
447 *p++ = cpu_to_be32(timep->tv_sec);
448 *p++ = cpu_to_be32(timep->tv_nsec);
452 static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec *timep)
454 timep->tv_sec = be32_to_cpup(p++);
455 timep->tv_nsec = be32_to_cpup(p++);
464 * SET_TO_SERVER_TIME = 1,
465 * SET_TO_CLIENT_TIME = 2
468 * union set_mode3 switch (bool set_it) {
475 * union set_uid3 switch (bool set_it) {
482 * union set_gid3 switch (bool set_it) {
489 * union set_size3 switch (bool set_it) {
496 * union set_atime switch (time_how set_it) {
497 * case SET_TO_CLIENT_TIME:
503 * union set_mtime switch (time_how set_it) {
504 * case SET_TO_CLIENT_TIME:
519 static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
526 * In order to make only a single xdr_reserve_space() call,
527 * pre-compute the total number of bytes to be reserved.
528 * Six boolean values, one for each set_foo field, are always
529 * present in the encoded result, so start there.
532 if (attr->ia_valid & ATTR_MODE)
534 if (attr->ia_valid & ATTR_UID)
536 if (attr->ia_valid & ATTR_GID)
538 if (attr->ia_valid & ATTR_SIZE)
540 if (attr->ia_valid & ATTR_ATIME_SET)
542 if (attr->ia_valid & ATTR_MTIME_SET)
544 p = xdr_reserve_space(xdr, nbytes);
546 if (attr->ia_valid & ATTR_MODE) {
548 *p++ = cpu_to_be32(attr->ia_mode & S_IALLUGO);
552 if (attr->ia_valid & ATTR_UID) {
554 *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
558 if (attr->ia_valid & ATTR_GID) {
560 *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
564 if (attr->ia_valid & ATTR_SIZE) {
566 p = xdr_encode_hyper(p, (u64)attr->ia_size);
570 if (attr->ia_valid & ATTR_ATIME_SET) {
573 ts = timespec64_to_timespec(attr->ia_atime);
574 p = xdr_encode_nfstime3(p, &ts);
575 } else if (attr->ia_valid & ATTR_ATIME) {
580 if (attr->ia_valid & ATTR_MTIME_SET) {
582 ts = timespec64_to_timespec(attr->ia_mtime);
583 xdr_encode_nfstime3(p, &ts);
584 } else if (attr->ia_valid & ATTR_MTIME) {
609 static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr)
614 p = xdr_inline_decode(xdr, NFS3_fattr_sz << 2);
618 p = xdr_decode_ftype3(p, &fmode);
620 fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode;
621 fattr->nlink = be32_to_cpup(p++);
622 fattr->uid = make_kuid(&init_user_ns, be32_to_cpup(p++));
623 if (!uid_valid(fattr->uid))
625 fattr->gid = make_kgid(&init_user_ns, be32_to_cpup(p++));
626 if (!gid_valid(fattr->gid))
629 p = xdr_decode_size3(p, &fattr->size);
630 p = xdr_decode_size3(p, &fattr->du.nfs3.used);
631 p = xdr_decode_specdata3(p, &fattr->rdev);
633 p = xdr_decode_hyper(p, &fattr->fsid.major);
634 fattr->fsid.minor = 0;
636 p = xdr_decode_fileid3(p, &fattr->fileid);
637 p = xdr_decode_nfstime3(p, &fattr->atime);
638 p = xdr_decode_nfstime3(p, &fattr->mtime);
639 xdr_decode_nfstime3(p, &fattr->ctime);
640 fattr->change_attr = nfs_timespec_to_change_attr(&fattr->ctime);
642 fattr->valid |= NFS_ATTR_FATTR_V3;
645 dprintk("NFS: returned invalid uid\n");
648 dprintk("NFS: returned invalid gid\n");
655 * union post_op_attr switch (bool attributes_follow) {
662 static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
666 p = xdr_inline_decode(xdr, 4);
670 return decode_fattr3(xdr, fattr);
682 static int decode_wcc_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
686 p = xdr_inline_decode(xdr, NFS3_wcc_attr_sz << 2);
690 fattr->valid |= NFS_ATTR_FATTR_PRESIZE
691 | NFS_ATTR_FATTR_PRECHANGE
692 | NFS_ATTR_FATTR_PREMTIME
693 | NFS_ATTR_FATTR_PRECTIME;
695 p = xdr_decode_size3(p, &fattr->pre_size);
696 p = xdr_decode_nfstime3(p, &fattr->pre_mtime);
697 xdr_decode_nfstime3(p, &fattr->pre_ctime);
698 fattr->pre_change_attr = nfs_timespec_to_change_attr(&fattr->pre_ctime);
705 * union pre_op_attr switch (bool attributes_follow) {
707 * wcc_attr attributes;
715 * pre_op_attr before;
716 * post_op_attr after;
719 static int decode_pre_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
723 p = xdr_inline_decode(xdr, 4);
727 return decode_wcc_attr(xdr, fattr);
731 static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr)
735 error = decode_pre_op_attr(xdr, fattr);
738 error = decode_post_op_attr(xdr, fattr);
746 * union post_op_fh3 switch (bool handle_follows) {
753 static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
755 __be32 *p = xdr_inline_decode(xdr, 4);
759 return decode_nfs_fh3(xdr, fh);
767 * struct diropargs3 {
772 static void encode_diropargs3(struct xdr_stream *xdr, const struct nfs_fh *fh,
773 const char *name, u32 length)
775 encode_nfs_fh3(xdr, fh);
776 encode_filename3(xdr, name, length);
781 * NFSv3 XDR encode functions
783 * NFSv3 argument types are defined in section 3.3 of RFC 1813:
784 * "NFS Version 3 Protocol Specification".
790 * struct GETATTR3args {
794 static void nfs3_xdr_enc_getattr3args(struct rpc_rqst *req,
795 struct xdr_stream *xdr,
798 const struct nfs_fh *fh = data;
800 encode_nfs_fh3(xdr, fh);
806 * union sattrguard3 switch (bool check) {
808 * nfstime3 obj_ctime;
813 * struct SETATTR3args {
815 * sattr3 new_attributes;
819 static void encode_sattrguard3(struct xdr_stream *xdr,
820 const struct nfs3_sattrargs *args)
825 p = xdr_reserve_space(xdr, 4 + 8);
827 xdr_encode_nfstime3(p, &args->guardtime);
829 p = xdr_reserve_space(xdr, 4);
834 static void nfs3_xdr_enc_setattr3args(struct rpc_rqst *req,
835 struct xdr_stream *xdr,
838 const struct nfs3_sattrargs *args = data;
839 encode_nfs_fh3(xdr, args->fh);
840 encode_sattr3(xdr, args->sattr);
841 encode_sattrguard3(xdr, args);
847 * struct LOOKUP3args {
851 static void nfs3_xdr_enc_lookup3args(struct rpc_rqst *req,
852 struct xdr_stream *xdr,
855 const struct nfs3_diropargs *args = data;
857 encode_diropargs3(xdr, args->fh, args->name, args->len);
863 * struct ACCESS3args {
868 static void encode_access3args(struct xdr_stream *xdr,
869 const struct nfs3_accessargs *args)
871 encode_nfs_fh3(xdr, args->fh);
872 encode_uint32(xdr, args->access);
875 static void nfs3_xdr_enc_access3args(struct rpc_rqst *req,
876 struct xdr_stream *xdr,
879 const struct nfs3_accessargs *args = data;
881 encode_access3args(xdr, args);
885 * 3.3.5 READLINK3args
887 * struct READLINK3args {
891 static void nfs3_xdr_enc_readlink3args(struct rpc_rqst *req,
892 struct xdr_stream *xdr,
895 const struct nfs3_readlinkargs *args = data;
897 encode_nfs_fh3(xdr, args->fh);
898 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
899 args->pglen, NFS3_readlinkres_sz);
911 static void encode_read3args(struct xdr_stream *xdr,
912 const struct nfs_pgio_args *args)
916 encode_nfs_fh3(xdr, args->fh);
918 p = xdr_reserve_space(xdr, 8 + 4);
919 p = xdr_encode_hyper(p, args->offset);
920 *p = cpu_to_be32(args->count);
923 static void nfs3_xdr_enc_read3args(struct rpc_rqst *req,
924 struct xdr_stream *xdr,
927 const struct nfs_pgio_args *args = data;
928 unsigned int replen = args->replen ? args->replen : NFS3_readres_sz;
930 encode_read3args(xdr, args);
931 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
932 args->count, replen);
933 req->rq_rcv_buf.flags |= XDRBUF_READ;
945 * struct WRITE3args {
953 static void encode_write3args(struct xdr_stream *xdr,
954 const struct nfs_pgio_args *args)
958 encode_nfs_fh3(xdr, args->fh);
960 p = xdr_reserve_space(xdr, 8 + 4 + 4 + 4);
961 p = xdr_encode_hyper(p, args->offset);
962 *p++ = cpu_to_be32(args->count);
963 *p++ = cpu_to_be32(args->stable);
964 *p = cpu_to_be32(args->count);
965 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
968 static void nfs3_xdr_enc_write3args(struct rpc_rqst *req,
969 struct xdr_stream *xdr,
972 const struct nfs_pgio_args *args = data;
974 encode_write3args(xdr, args);
975 xdr->buf->flags |= XDRBUF_WRITE;
987 * union createhow3 switch (createmode3 mode) {
990 * sattr3 obj_attributes;
995 * struct CREATE3args {
1000 static void encode_createhow3(struct xdr_stream *xdr,
1001 const struct nfs3_createargs *args)
1003 encode_uint32(xdr, args->createmode);
1004 switch (args->createmode) {
1005 case NFS3_CREATE_UNCHECKED:
1006 case NFS3_CREATE_GUARDED:
1007 encode_sattr3(xdr, args->sattr);
1009 case NFS3_CREATE_EXCLUSIVE:
1010 encode_createverf3(xdr, args->verifier);
1017 static void nfs3_xdr_enc_create3args(struct rpc_rqst *req,
1018 struct xdr_stream *xdr,
1021 const struct nfs3_createargs *args = data;
1023 encode_diropargs3(xdr, args->fh, args->name, args->len);
1024 encode_createhow3(xdr, args);
1030 * struct MKDIR3args {
1032 * sattr3 attributes;
1035 static void nfs3_xdr_enc_mkdir3args(struct rpc_rqst *req,
1036 struct xdr_stream *xdr,
1039 const struct nfs3_mkdirargs *args = data;
1041 encode_diropargs3(xdr, args->fh, args->name, args->len);
1042 encode_sattr3(xdr, args->sattr);
1046 * 3.3.10 SYMLINK3args
1048 * struct symlinkdata3 {
1049 * sattr3 symlink_attributes;
1050 * nfspath3 symlink_data;
1053 * struct SYMLINK3args {
1055 * symlinkdata3 symlink;
1058 static void encode_symlinkdata3(struct xdr_stream *xdr,
1061 const struct nfs3_symlinkargs *args = data;
1063 encode_sattr3(xdr, args->sattr);
1064 encode_nfspath3(xdr, args->pages, args->pathlen);
1067 static void nfs3_xdr_enc_symlink3args(struct rpc_rqst *req,
1068 struct xdr_stream *xdr,
1071 const struct nfs3_symlinkargs *args = data;
1073 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
1074 encode_symlinkdata3(xdr, args);
1075 xdr->buf->flags |= XDRBUF_WRITE;
1081 * struct devicedata3 {
1082 * sattr3 dev_attributes;
1086 * union mknoddata3 switch (ftype3 type) {
1089 * devicedata3 device;
1092 * sattr3 pipe_attributes;
1097 * struct MKNOD3args {
1102 static void encode_devicedata3(struct xdr_stream *xdr,
1103 const struct nfs3_mknodargs *args)
1105 encode_sattr3(xdr, args->sattr);
1106 encode_specdata3(xdr, args->rdev);
1109 static void encode_mknoddata3(struct xdr_stream *xdr,
1110 const struct nfs3_mknodargs *args)
1112 encode_ftype3(xdr, args->type);
1113 switch (args->type) {
1116 encode_devicedata3(xdr, args);
1120 encode_sattr3(xdr, args->sattr);
1130 static void nfs3_xdr_enc_mknod3args(struct rpc_rqst *req,
1131 struct xdr_stream *xdr,
1134 const struct nfs3_mknodargs *args = data;
1136 encode_diropargs3(xdr, args->fh, args->name, args->len);
1137 encode_mknoddata3(xdr, args);
1141 * 3.3.12 REMOVE3args
1143 * struct REMOVE3args {
1144 * diropargs3 object;
1147 static void nfs3_xdr_enc_remove3args(struct rpc_rqst *req,
1148 struct xdr_stream *xdr,
1151 const struct nfs_removeargs *args = data;
1153 encode_diropargs3(xdr, args->fh, args->name.name, args->name.len);
1157 * 3.3.14 RENAME3args
1159 * struct RENAME3args {
1164 static void nfs3_xdr_enc_rename3args(struct rpc_rqst *req,
1165 struct xdr_stream *xdr,
1168 const struct nfs_renameargs *args = data;
1169 const struct qstr *old = args->old_name;
1170 const struct qstr *new = args->new_name;
1172 encode_diropargs3(xdr, args->old_dir, old->name, old->len);
1173 encode_diropargs3(xdr, args->new_dir, new->name, new->len);
1179 * struct LINK3args {
1184 static void nfs3_xdr_enc_link3args(struct rpc_rqst *req,
1185 struct xdr_stream *xdr,
1188 const struct nfs3_linkargs *args = data;
1190 encode_nfs_fh3(xdr, args->fromfh);
1191 encode_diropargs3(xdr, args->tofh, args->toname, args->tolen);
1195 * 3.3.16 READDIR3args
1197 * struct READDIR3args {
1200 * cookieverf3 cookieverf;
1204 static void encode_readdir3args(struct xdr_stream *xdr,
1205 const struct nfs3_readdirargs *args)
1209 encode_nfs_fh3(xdr, args->fh);
1211 p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4);
1212 p = xdr_encode_cookie3(p, args->cookie);
1213 p = xdr_encode_cookieverf3(p, args->verf);
1214 *p = cpu_to_be32(args->count);
1217 static void nfs3_xdr_enc_readdir3args(struct rpc_rqst *req,
1218 struct xdr_stream *xdr,
1221 const struct nfs3_readdirargs *args = data;
1223 encode_readdir3args(xdr, args);
1224 rpc_prepare_reply_pages(req, args->pages, 0,
1225 args->count, NFS3_readdirres_sz);
1229 * 3.3.17 READDIRPLUS3args
1231 * struct READDIRPLUS3args {
1234 * cookieverf3 cookieverf;
1239 static void encode_readdirplus3args(struct xdr_stream *xdr,
1240 const struct nfs3_readdirargs *args)
1244 encode_nfs_fh3(xdr, args->fh);
1246 p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4 + 4);
1247 p = xdr_encode_cookie3(p, args->cookie);
1248 p = xdr_encode_cookieverf3(p, args->verf);
1251 * readdirplus: need dircount + buffer size.
1252 * We just make sure we make dircount big enough
1254 *p++ = cpu_to_be32(args->count >> 3);
1256 *p = cpu_to_be32(args->count);
1259 static void nfs3_xdr_enc_readdirplus3args(struct rpc_rqst *req,
1260 struct xdr_stream *xdr,
1263 const struct nfs3_readdirargs *args = data;
1265 encode_readdirplus3args(xdr, args);
1266 rpc_prepare_reply_pages(req, args->pages, 0,
1267 args->count, NFS3_readdirres_sz);
1271 * 3.3.21 COMMIT3args
1273 * struct COMMIT3args {
1279 static void encode_commit3args(struct xdr_stream *xdr,
1280 const struct nfs_commitargs *args)
1284 encode_nfs_fh3(xdr, args->fh);
1286 p = xdr_reserve_space(xdr, 8 + 4);
1287 p = xdr_encode_hyper(p, args->offset);
1288 *p = cpu_to_be32(args->count);
1291 static void nfs3_xdr_enc_commit3args(struct rpc_rqst *req,
1292 struct xdr_stream *xdr,
1295 const struct nfs_commitargs *args = data;
1297 encode_commit3args(xdr, args);
1300 #ifdef CONFIG_NFS_V3_ACL
1302 static void nfs3_xdr_enc_getacl3args(struct rpc_rqst *req,
1303 struct xdr_stream *xdr,
1306 const struct nfs3_getaclargs *args = data;
1308 encode_nfs_fh3(xdr, args->fh);
1309 encode_uint32(xdr, args->mask);
1310 if (args->mask & (NFS_ACL | NFS_DFACL)) {
1311 rpc_prepare_reply_pages(req, args->pages, 0,
1312 NFSACL_MAXPAGES << PAGE_SHIFT,
1314 req->rq_rcv_buf.flags |= XDRBUF_SPARSE_PAGES;
1318 static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req,
1319 struct xdr_stream *xdr,
1322 const struct nfs3_setaclargs *args = data;
1326 encode_nfs_fh3(xdr, NFS_FH(args->inode));
1327 encode_uint32(xdr, args->mask);
1329 base = req->rq_slen;
1330 if (args->npages != 0)
1331 xdr_write_pages(xdr, args->pages, 0, args->len);
1333 xdr_reserve_space(xdr, args->len);
1335 error = nfsacl_encode(xdr->buf, base, args->inode,
1336 (args->mask & NFS_ACL) ?
1337 args->acl_access : NULL, 1, 0);
1338 /* FIXME: this is just broken */
1340 error = nfsacl_encode(xdr->buf, base + error, args->inode,
1341 (args->mask & NFS_DFACL) ?
1342 args->acl_default : NULL, 1,
1347 #endif /* CONFIG_NFS_V3_ACL */
1350 * NFSv3 XDR decode functions
1352 * NFSv3 result types are defined in section 3.3 of RFC 1813:
1353 * "NFS Version 3 Protocol Specification".
1359 * struct GETATTR3resok {
1360 * fattr3 obj_attributes;
1363 * union GETATTR3res switch (nfsstat3 status) {
1365 * GETATTR3resok resok;
1370 static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
1371 struct xdr_stream *xdr,
1374 enum nfs_stat status;
1377 error = decode_nfsstat3(xdr, &status);
1378 if (unlikely(error))
1380 if (status != NFS3_OK)
1382 error = decode_fattr3(xdr, result);
1386 return nfs3_stat_to_errno(status);
1392 * struct SETATTR3resok {
1396 * struct SETATTR3resfail {
1400 * union SETATTR3res switch (nfsstat3 status) {
1402 * SETATTR3resok resok;
1404 * SETATTR3resfail resfail;
1407 static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
1408 struct xdr_stream *xdr,
1411 enum nfs_stat status;
1414 error = decode_nfsstat3(xdr, &status);
1415 if (unlikely(error))
1417 error = decode_wcc_data(xdr, result);
1418 if (unlikely(error))
1420 if (status != NFS3_OK)
1425 return nfs3_stat_to_errno(status);
1431 * struct LOOKUP3resok {
1433 * post_op_attr obj_attributes;
1434 * post_op_attr dir_attributes;
1437 * struct LOOKUP3resfail {
1438 * post_op_attr dir_attributes;
1441 * union LOOKUP3res switch (nfsstat3 status) {
1443 * LOOKUP3resok resok;
1445 * LOOKUP3resfail resfail;
1448 static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req,
1449 struct xdr_stream *xdr,
1452 struct nfs3_diropres *result = data;
1453 enum nfs_stat status;
1456 error = decode_nfsstat3(xdr, &status);
1457 if (unlikely(error))
1459 if (status != NFS3_OK)
1461 error = decode_nfs_fh3(xdr, result->fh);
1462 if (unlikely(error))
1464 error = decode_post_op_attr(xdr, result->fattr);
1465 if (unlikely(error))
1467 error = decode_post_op_attr(xdr, result->dir_attr);
1471 error = decode_post_op_attr(xdr, result->dir_attr);
1472 if (unlikely(error))
1474 return nfs3_stat_to_errno(status);
1480 * struct ACCESS3resok {
1481 * post_op_attr obj_attributes;
1485 * struct ACCESS3resfail {
1486 * post_op_attr obj_attributes;
1489 * union ACCESS3res switch (nfsstat3 status) {
1491 * ACCESS3resok resok;
1493 * ACCESS3resfail resfail;
1496 static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
1497 struct xdr_stream *xdr,
1500 struct nfs3_accessres *result = data;
1501 enum nfs_stat status;
1504 error = decode_nfsstat3(xdr, &status);
1505 if (unlikely(error))
1507 error = decode_post_op_attr(xdr, result->fattr);
1508 if (unlikely(error))
1510 if (status != NFS3_OK)
1512 error = decode_uint32(xdr, &result->access);
1516 return nfs3_stat_to_errno(status);
1520 * 3.3.5 READLINK3res
1522 * struct READLINK3resok {
1523 * post_op_attr symlink_attributes;
1527 * struct READLINK3resfail {
1528 * post_op_attr symlink_attributes;
1531 * union READLINK3res switch (nfsstat3 status) {
1533 * READLINK3resok resok;
1535 * READLINK3resfail resfail;
1538 static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
1539 struct xdr_stream *xdr,
1542 enum nfs_stat status;
1545 error = decode_nfsstat3(xdr, &status);
1546 if (unlikely(error))
1548 error = decode_post_op_attr(xdr, result);
1549 if (unlikely(error))
1551 if (status != NFS3_OK)
1553 error = decode_nfspath3(xdr);
1557 return nfs3_stat_to_errno(status);
1563 * struct READ3resok {
1564 * post_op_attr file_attributes;
1570 * struct READ3resfail {
1571 * post_op_attr file_attributes;
1574 * union READ3res switch (nfsstat3 status) {
1578 * READ3resfail resfail;
1581 static int decode_read3resok(struct xdr_stream *xdr,
1582 struct nfs_pgio_res *result)
1584 u32 eof, count, ocount, recvd;
1587 p = xdr_inline_decode(xdr, 4 + 4 + 4);
1590 count = be32_to_cpup(p++);
1591 eof = be32_to_cpup(p++);
1592 ocount = be32_to_cpup(p++);
1593 if (unlikely(ocount != count))
1595 recvd = xdr_read_pages(xdr, count);
1596 if (unlikely(count > recvd))
1600 result->count = count;
1603 dprintk("NFS: READ count doesn't match length of opaque: "
1604 "count %u != ocount %u\n", count, ocount);
1607 dprintk("NFS: server cheating in read result: "
1608 "count %u > recvd %u\n", count, recvd);
1614 static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1617 struct nfs_pgio_res *result = data;
1619 enum nfs_stat status;
1622 pos = xdr_stream_pos(xdr);
1623 error = decode_nfsstat3(xdr, &status);
1624 if (unlikely(error))
1626 error = decode_post_op_attr(xdr, result->fattr);
1627 if (unlikely(error))
1629 result->op_status = status;
1630 if (status != NFS3_OK)
1632 result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
1633 error = decode_read3resok(xdr, result);
1637 return nfs3_stat_to_errno(status);
1649 * struct WRITE3resok {
1650 * wcc_data file_wcc;
1652 * stable_how committed;
1656 * struct WRITE3resfail {
1657 * wcc_data file_wcc;
1660 * union WRITE3res switch (nfsstat3 status) {
1662 * WRITE3resok resok;
1664 * WRITE3resfail resfail;
1667 static int decode_write3resok(struct xdr_stream *xdr,
1668 struct nfs_pgio_res *result)
1672 p = xdr_inline_decode(xdr, 4 + 4);
1675 result->count = be32_to_cpup(p++);
1676 result->verf->committed = be32_to_cpup(p++);
1677 if (unlikely(result->verf->committed > NFS_FILE_SYNC))
1679 if (decode_writeverf3(xdr, &result->verf->verifier))
1681 return result->count;
1683 dprintk("NFS: bad stable_how value: %u\n", result->verf->committed);
1687 static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1690 struct nfs_pgio_res *result = data;
1691 enum nfs_stat status;
1694 error = decode_nfsstat3(xdr, &status);
1695 if (unlikely(error))
1697 error = decode_wcc_data(xdr, result->fattr);
1698 if (unlikely(error))
1700 result->op_status = status;
1701 if (status != NFS3_OK)
1703 error = decode_write3resok(xdr, result);
1707 return nfs3_stat_to_errno(status);
1713 * struct CREATE3resok {
1715 * post_op_attr obj_attributes;
1719 * struct CREATE3resfail {
1723 * union CREATE3res switch (nfsstat3 status) {
1725 * CREATE3resok resok;
1727 * CREATE3resfail resfail;
1730 static int decode_create3resok(struct xdr_stream *xdr,
1731 struct nfs3_diropres *result)
1735 error = decode_post_op_fh3(xdr, result->fh);
1736 if (unlikely(error))
1738 error = decode_post_op_attr(xdr, result->fattr);
1739 if (unlikely(error))
1741 /* The server isn't required to return a file handle.
1742 * If it didn't, force the client to perform a LOOKUP
1743 * to determine the correct file handle and attribute
1744 * values for the new object. */
1745 if (result->fh->size == 0)
1746 result->fattr->valid = 0;
1747 error = decode_wcc_data(xdr, result->dir_attr);
1752 static int nfs3_xdr_dec_create3res(struct rpc_rqst *req,
1753 struct xdr_stream *xdr,
1756 struct nfs3_diropres *result = data;
1757 enum nfs_stat status;
1760 error = decode_nfsstat3(xdr, &status);
1761 if (unlikely(error))
1763 if (status != NFS3_OK)
1765 error = decode_create3resok(xdr, result);
1769 error = decode_wcc_data(xdr, result->dir_attr);
1770 if (unlikely(error))
1772 return nfs3_stat_to_errno(status);
1778 * struct REMOVE3resok {
1782 * struct REMOVE3resfail {
1786 * union REMOVE3res switch (nfsstat3 status) {
1788 * REMOVE3resok resok;
1790 * REMOVE3resfail resfail;
1793 static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
1794 struct xdr_stream *xdr,
1797 struct nfs_removeres *result = data;
1798 enum nfs_stat status;
1801 error = decode_nfsstat3(xdr, &status);
1802 if (unlikely(error))
1804 error = decode_wcc_data(xdr, result->dir_attr);
1805 if (unlikely(error))
1807 if (status != NFS3_OK)
1812 return nfs3_stat_to_errno(status);
1818 * struct RENAME3resok {
1819 * wcc_data fromdir_wcc;
1820 * wcc_data todir_wcc;
1823 * struct RENAME3resfail {
1824 * wcc_data fromdir_wcc;
1825 * wcc_data todir_wcc;
1828 * union RENAME3res switch (nfsstat3 status) {
1830 * RENAME3resok resok;
1832 * RENAME3resfail resfail;
1835 static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
1836 struct xdr_stream *xdr,
1839 struct nfs_renameres *result = data;
1840 enum nfs_stat status;
1843 error = decode_nfsstat3(xdr, &status);
1844 if (unlikely(error))
1846 error = decode_wcc_data(xdr, result->old_fattr);
1847 if (unlikely(error))
1849 error = decode_wcc_data(xdr, result->new_fattr);
1850 if (unlikely(error))
1852 if (status != NFS3_OK)
1857 return nfs3_stat_to_errno(status);
1863 * struct LINK3resok {
1864 * post_op_attr file_attributes;
1865 * wcc_data linkdir_wcc;
1868 * struct LINK3resfail {
1869 * post_op_attr file_attributes;
1870 * wcc_data linkdir_wcc;
1873 * union LINK3res switch (nfsstat3 status) {
1877 * LINK3resfail resfail;
1880 static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1883 struct nfs3_linkres *result = data;
1884 enum nfs_stat status;
1887 error = decode_nfsstat3(xdr, &status);
1888 if (unlikely(error))
1890 error = decode_post_op_attr(xdr, result->fattr);
1891 if (unlikely(error))
1893 error = decode_wcc_data(xdr, result->dir_attr);
1894 if (unlikely(error))
1896 if (status != NFS3_OK)
1901 return nfs3_stat_to_errno(status);
1905 * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in
1906 * the local page cache
1907 * @xdr: XDR stream where entry resides
1908 * @entry: buffer to fill in with entry data
1909 * @plus: boolean indicating whether this should be a readdirplus entry
1911 * Returns zero if successful, otherwise a negative errno value is
1914 * This function is not invoked during READDIR reply decoding, but
1915 * rather whenever an application invokes the getdents(2) system call
1916 * on a directory already in our cache.
1924 * fhandle3 filehandle;
1925 * post_op_attr3 attributes;
1926 * entry3 *nextentry;
1930 * struct entryplus3 {
1934 * post_op_attr name_attributes;
1935 * post_op_fh3 name_handle;
1936 * entryplus3 *nextentry;
1939 int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
1942 struct nfs_entry old = *entry;
1947 p = xdr_inline_decode(xdr, 4);
1950 if (*p == xdr_zero) {
1951 p = xdr_inline_decode(xdr, 4);
1960 error = decode_fileid3(xdr, &entry->ino);
1961 if (unlikely(error))
1964 error = decode_inline_filename3(xdr, &entry->name, &entry->len);
1965 if (unlikely(error))
1968 error = decode_cookie3(xdr, &new_cookie);
1969 if (unlikely(error))
1972 entry->d_type = DT_UNKNOWN;
1975 entry->fattr->valid = 0;
1976 error = decode_post_op_attr(xdr, entry->fattr);
1977 if (unlikely(error))
1979 if (entry->fattr->valid & NFS_ATTR_FATTR_V3)
1980 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
1982 if (entry->fattr->fileid != entry->ino) {
1983 entry->fattr->mounted_on_fileid = entry->ino;
1984 entry->fattr->valid |= NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
1987 /* In fact, a post_op_fh3: */
1988 p = xdr_inline_decode(xdr, 4);
1991 if (*p != xdr_zero) {
1992 error = decode_nfs_fh3(xdr, entry->fh);
1993 if (unlikely(error)) {
1994 if (error == -E2BIG)
1999 zero_nfs_fh3(entry->fh);
2002 entry->prev_cookie = entry->cookie;
2003 entry->cookie = new_cookie;
2008 dprintk("NFS: directory entry contains invalid file handle\n");
2014 * 3.3.16 READDIR3res
2021 * struct READDIR3resok {
2022 * post_op_attr dir_attributes;
2023 * cookieverf3 cookieverf;
2027 * struct READDIR3resfail {
2028 * post_op_attr dir_attributes;
2031 * union READDIR3res switch (nfsstat3 status) {
2033 * READDIR3resok resok;
2035 * READDIR3resfail resfail;
2038 * Read the directory contents into the page cache, but otherwise
2039 * don't touch them. The actual decoding is done by nfs3_decode_entry()
2040 * during subsequent nfs_readdir() calls.
2042 static int decode_dirlist3(struct xdr_stream *xdr)
2044 return xdr_read_pages(xdr, xdr->buf->page_len);
2047 static int decode_readdir3resok(struct xdr_stream *xdr,
2048 struct nfs3_readdirres *result)
2052 error = decode_post_op_attr(xdr, result->dir_attr);
2053 if (unlikely(error))
2055 /* XXX: do we need to check if result->verf != NULL ? */
2056 error = decode_cookieverf3(xdr, result->verf);
2057 if (unlikely(error))
2059 error = decode_dirlist3(xdr);
2064 static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req,
2065 struct xdr_stream *xdr,
2068 struct nfs3_readdirres *result = data;
2069 enum nfs_stat status;
2072 error = decode_nfsstat3(xdr, &status);
2073 if (unlikely(error))
2075 if (status != NFS3_OK)
2077 error = decode_readdir3resok(xdr, result);
2081 error = decode_post_op_attr(xdr, result->dir_attr);
2082 if (unlikely(error))
2084 return nfs3_stat_to_errno(status);
2090 * struct FSSTAT3resok {
2091 * post_op_attr obj_attributes;
2101 * struct FSSTAT3resfail {
2102 * post_op_attr obj_attributes;
2105 * union FSSTAT3res switch (nfsstat3 status) {
2107 * FSSTAT3resok resok;
2109 * FSSTAT3resfail resfail;
2112 static int decode_fsstat3resok(struct xdr_stream *xdr,
2113 struct nfs_fsstat *result)
2117 p = xdr_inline_decode(xdr, 8 * 6 + 4);
2120 p = xdr_decode_size3(p, &result->tbytes);
2121 p = xdr_decode_size3(p, &result->fbytes);
2122 p = xdr_decode_size3(p, &result->abytes);
2123 p = xdr_decode_size3(p, &result->tfiles);
2124 p = xdr_decode_size3(p, &result->ffiles);
2125 xdr_decode_size3(p, &result->afiles);
2126 /* ignore invarsec */
2130 static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
2131 struct xdr_stream *xdr,
2134 struct nfs_fsstat *result = data;
2135 enum nfs_stat status;
2138 error = decode_nfsstat3(xdr, &status);
2139 if (unlikely(error))
2141 error = decode_post_op_attr(xdr, result->fattr);
2142 if (unlikely(error))
2144 if (status != NFS3_OK)
2146 error = decode_fsstat3resok(xdr, result);
2150 return nfs3_stat_to_errno(status);
2156 * struct FSINFO3resok {
2157 * post_op_attr obj_attributes;
2165 * size3 maxfilesize;
2166 * nfstime3 time_delta;
2167 * uint32 properties;
2170 * struct FSINFO3resfail {
2171 * post_op_attr obj_attributes;
2174 * union FSINFO3res switch (nfsstat3 status) {
2176 * FSINFO3resok resok;
2178 * FSINFO3resfail resfail;
2181 static int decode_fsinfo3resok(struct xdr_stream *xdr,
2182 struct nfs_fsinfo *result)
2186 p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4);
2189 result->rtmax = be32_to_cpup(p++);
2190 result->rtpref = be32_to_cpup(p++);
2191 result->rtmult = be32_to_cpup(p++);
2192 result->wtmax = be32_to_cpup(p++);
2193 result->wtpref = be32_to_cpup(p++);
2194 result->wtmult = be32_to_cpup(p++);
2195 result->dtpref = be32_to_cpup(p++);
2196 p = xdr_decode_size3(p, &result->maxfilesize);
2197 xdr_decode_nfstime3(p, &result->time_delta);
2199 /* ignore properties */
2200 result->lease_time = 0;
2204 static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
2205 struct xdr_stream *xdr,
2208 struct nfs_fsinfo *result = data;
2209 enum nfs_stat status;
2212 error = decode_nfsstat3(xdr, &status);
2213 if (unlikely(error))
2215 error = decode_post_op_attr(xdr, result->fattr);
2216 if (unlikely(error))
2218 if (status != NFS3_OK)
2220 error = decode_fsinfo3resok(xdr, result);
2224 return nfs3_stat_to_errno(status);
2228 * 3.3.20 PATHCONF3res
2230 * struct PATHCONF3resok {
2231 * post_op_attr obj_attributes;
2235 * bool chown_restricted;
2236 * bool case_insensitive;
2237 * bool case_preserving;
2240 * struct PATHCONF3resfail {
2241 * post_op_attr obj_attributes;
2244 * union PATHCONF3res switch (nfsstat3 status) {
2246 * PATHCONF3resok resok;
2248 * PATHCONF3resfail resfail;
2251 static int decode_pathconf3resok(struct xdr_stream *xdr,
2252 struct nfs_pathconf *result)
2256 p = xdr_inline_decode(xdr, 4 * 6);
2259 result->max_link = be32_to_cpup(p++);
2260 result->max_namelen = be32_to_cpup(p);
2261 /* ignore remaining fields */
2265 static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
2266 struct xdr_stream *xdr,
2269 struct nfs_pathconf *result = data;
2270 enum nfs_stat status;
2273 error = decode_nfsstat3(xdr, &status);
2274 if (unlikely(error))
2276 error = decode_post_op_attr(xdr, result->fattr);
2277 if (unlikely(error))
2279 if (status != NFS3_OK)
2281 error = decode_pathconf3resok(xdr, result);
2285 return nfs3_stat_to_errno(status);
2291 * struct COMMIT3resok {
2292 * wcc_data file_wcc;
2296 * struct COMMIT3resfail {
2297 * wcc_data file_wcc;
2300 * union COMMIT3res switch (nfsstat3 status) {
2302 * COMMIT3resok resok;
2304 * COMMIT3resfail resfail;
2307 static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
2308 struct xdr_stream *xdr,
2311 struct nfs_commitres *result = data;
2312 enum nfs_stat status;
2315 error = decode_nfsstat3(xdr, &status);
2316 if (unlikely(error))
2318 error = decode_wcc_data(xdr, result->fattr);
2319 if (unlikely(error))
2321 result->op_status = status;
2322 if (status != NFS3_OK)
2324 error = decode_writeverf3(xdr, &result->verf->verifier);
2328 return nfs3_stat_to_errno(status);
2331 #ifdef CONFIG_NFS_V3_ACL
2333 static inline int decode_getacl3resok(struct xdr_stream *xdr,
2334 struct nfs3_getaclres *result)
2336 struct posix_acl **acl;
2337 unsigned int *aclcnt;
2341 error = decode_post_op_attr(xdr, result->fattr);
2342 if (unlikely(error))
2344 error = decode_uint32(xdr, &result->mask);
2345 if (unlikely(error))
2348 if (result->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
2351 hdrlen = xdr_stream_pos(xdr);
2354 if (result->mask & NFS_ACL)
2355 acl = &result->acl_access;
2357 if (result->mask & NFS_ACLCNT)
2358 aclcnt = &result->acl_access_count;
2359 error = nfsacl_decode(xdr->buf, hdrlen, aclcnt, acl);
2360 if (unlikely(error <= 0))
2364 if (result->mask & NFS_DFACL)
2365 acl = &result->acl_default;
2367 if (result->mask & NFS_DFACLCNT)
2368 aclcnt = &result->acl_default_count;
2369 error = nfsacl_decode(xdr->buf, hdrlen + error, aclcnt, acl);
2370 if (unlikely(error <= 0))
2377 static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
2378 struct xdr_stream *xdr,
2381 enum nfs_stat status;
2384 error = decode_nfsstat3(xdr, &status);
2385 if (unlikely(error))
2387 if (status != NFS3_OK)
2389 error = decode_getacl3resok(xdr, result);
2393 return nfs3_stat_to_errno(status);
2396 static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
2397 struct xdr_stream *xdr,
2400 enum nfs_stat status;
2403 error = decode_nfsstat3(xdr, &status);
2404 if (unlikely(error))
2406 if (status != NFS3_OK)
2408 error = decode_post_op_attr(xdr, result);
2412 return nfs3_stat_to_errno(status);
2415 #endif /* CONFIG_NFS_V3_ACL */
2419 * We need to translate between nfs status return values and
2420 * the local errno values which may not be the same.
2422 static const struct {
2427 { NFSERR_PERM, -EPERM },
2428 { NFSERR_NOENT, -ENOENT },
2429 { NFSERR_IO, -errno_NFSERR_IO},
2430 { NFSERR_NXIO, -ENXIO },
2431 /* { NFSERR_EAGAIN, -EAGAIN }, */
2432 { NFSERR_ACCES, -EACCES },
2433 { NFSERR_EXIST, -EEXIST },
2434 { NFSERR_XDEV, -EXDEV },
2435 { NFSERR_NODEV, -ENODEV },
2436 { NFSERR_NOTDIR, -ENOTDIR },
2437 { NFSERR_ISDIR, -EISDIR },
2438 { NFSERR_INVAL, -EINVAL },
2439 { NFSERR_FBIG, -EFBIG },
2440 { NFSERR_NOSPC, -ENOSPC },
2441 { NFSERR_ROFS, -EROFS },
2442 { NFSERR_MLINK, -EMLINK },
2443 { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
2444 { NFSERR_NOTEMPTY, -ENOTEMPTY },
2445 { NFSERR_DQUOT, -EDQUOT },
2446 { NFSERR_STALE, -ESTALE },
2447 { NFSERR_REMOTE, -EREMOTE },
2449 { NFSERR_WFLUSH, -EWFLUSH },
2451 { NFSERR_BADHANDLE, -EBADHANDLE },
2452 { NFSERR_NOT_SYNC, -ENOTSYNC },
2453 { NFSERR_BAD_COOKIE, -EBADCOOKIE },
2454 { NFSERR_NOTSUPP, -ENOTSUPP },
2455 { NFSERR_TOOSMALL, -ETOOSMALL },
2456 { NFSERR_SERVERFAULT, -EREMOTEIO },
2457 { NFSERR_BADTYPE, -EBADTYPE },
2458 { NFSERR_JUKEBOX, -EJUKEBOX },
2463 * nfs3_stat_to_errno - convert an NFS status code to a local errno
2464 * @status: NFS status code to convert
2466 * Returns a local errno value, or -EIO if the NFS status code is
2467 * not recognized. This function is used jointly by NFSv2 and NFSv3.
2469 static int nfs3_stat_to_errno(enum nfs_stat status)
2473 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
2474 if (nfs_errtbl[i].stat == (int)status)
2475 return nfs_errtbl[i].errno;
2477 dprintk("NFS: Unrecognized nfs status value: %u\n", status);
2478 return nfs_errtbl[i].errno;
2482 #define PROC(proc, argtype, restype, timer) \
2483 [NFS3PROC_##proc] = { \
2484 .p_proc = NFS3PROC_##proc, \
2485 .p_encode = nfs3_xdr_enc_##argtype##3args, \
2486 .p_decode = nfs3_xdr_dec_##restype##3res, \
2487 .p_arglen = NFS3_##argtype##args_sz, \
2488 .p_replen = NFS3_##restype##res_sz, \
2490 .p_statidx = NFS3PROC_##proc, \
2494 const struct rpc_procinfo nfs3_procedures[] = {
2495 PROC(GETATTR, getattr, getattr, 1),
2496 PROC(SETATTR, setattr, setattr, 0),
2497 PROC(LOOKUP, lookup, lookup, 2),
2498 PROC(ACCESS, access, access, 1),
2499 PROC(READLINK, readlink, readlink, 3),
2500 PROC(READ, read, read, 3),
2501 PROC(WRITE, write, write, 4),
2502 PROC(CREATE, create, create, 0),
2503 PROC(MKDIR, mkdir, create, 0),
2504 PROC(SYMLINK, symlink, create, 0),
2505 PROC(MKNOD, mknod, create, 0),
2506 PROC(REMOVE, remove, remove, 0),
2507 PROC(RMDIR, lookup, setattr, 0),
2508 PROC(RENAME, rename, rename, 0),
2509 PROC(LINK, link, link, 0),
2510 PROC(READDIR, readdir, readdir, 3),
2511 PROC(READDIRPLUS, readdirplus, readdir, 3),
2512 PROC(FSSTAT, getattr, fsstat, 0),
2513 PROC(FSINFO, getattr, fsinfo, 0),
2514 PROC(PATHCONF, getattr, pathconf, 0),
2515 PROC(COMMIT, commit, commit, 5),
2518 static unsigned int nfs_version3_counts[ARRAY_SIZE(nfs3_procedures)];
2519 const struct rpc_version nfs_version3 = {
2521 .nrprocs = ARRAY_SIZE(nfs3_procedures),
2522 .procs = nfs3_procedures,
2523 .counts = nfs_version3_counts,
2526 #ifdef CONFIG_NFS_V3_ACL
2527 static const struct rpc_procinfo nfs3_acl_procedures[] = {
2528 [ACLPROC3_GETACL] = {
2529 .p_proc = ACLPROC3_GETACL,
2530 .p_encode = nfs3_xdr_enc_getacl3args,
2531 .p_decode = nfs3_xdr_dec_getacl3res,
2532 .p_arglen = ACL3_getaclargs_sz,
2533 .p_replen = ACL3_getaclres_sz,
2537 [ACLPROC3_SETACL] = {
2538 .p_proc = ACLPROC3_SETACL,
2539 .p_encode = nfs3_xdr_enc_setacl3args,
2540 .p_decode = nfs3_xdr_dec_setacl3res,
2541 .p_arglen = ACL3_setaclargs_sz,
2542 .p_replen = ACL3_setaclres_sz,
2548 static unsigned int nfs3_acl_counts[ARRAY_SIZE(nfs3_acl_procedures)];
2549 const struct rpc_version nfsacl_version3 = {
2551 .nrprocs = ARRAY_SIZE(nfs3_acl_procedures),
2552 .procs = nfs3_acl_procedures,
2553 .counts = nfs3_acl_counts,
2555 #endif /* CONFIG_NFS_V3_ACL */