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_sattr_sz (15)
38 #define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2))
39 #define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2))
40 #define NFS3_fattr_sz (21)
41 #define NFS3_cookieverf_sz (NFS3_COOKIEVERFSIZE>>2)
42 #define NFS3_wcc_attr_sz (6)
43 #define NFS3_pre_op_attr_sz (1+NFS3_wcc_attr_sz)
44 #define NFS3_post_op_attr_sz (1+NFS3_fattr_sz)
45 #define NFS3_wcc_data_sz (NFS3_pre_op_attr_sz+NFS3_post_op_attr_sz)
46 #define NFS3_diropargs_sz (NFS3_fh_sz+NFS3_filename_sz)
48 #define NFS3_getattrargs_sz (NFS3_fh_sz)
49 #define NFS3_setattrargs_sz (NFS3_fh_sz+NFS3_sattr_sz+3)
50 #define NFS3_lookupargs_sz (NFS3_fh_sz+NFS3_filename_sz)
51 #define NFS3_accessargs_sz (NFS3_fh_sz+1)
52 #define NFS3_readlinkargs_sz (NFS3_fh_sz)
53 #define NFS3_readargs_sz (NFS3_fh_sz+3)
54 #define NFS3_writeargs_sz (NFS3_fh_sz+5)
55 #define NFS3_createargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
56 #define NFS3_mkdirargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
57 #define NFS3_symlinkargs_sz (NFS3_diropargs_sz+1+NFS3_sattr_sz)
58 #define NFS3_mknodargs_sz (NFS3_diropargs_sz+2+NFS3_sattr_sz)
59 #define NFS3_removeargs_sz (NFS3_fh_sz+NFS3_filename_sz)
60 #define NFS3_renameargs_sz (NFS3_diropargs_sz+NFS3_diropargs_sz)
61 #define NFS3_linkargs_sz (NFS3_fh_sz+NFS3_diropargs_sz)
62 #define NFS3_readdirargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+3)
63 #define NFS3_readdirplusargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+4)
64 #define NFS3_commitargs_sz (NFS3_fh_sz+3)
66 #define NFS3_getattrres_sz (1+NFS3_fattr_sz)
67 #define NFS3_setattrres_sz (1+NFS3_wcc_data_sz)
68 #define NFS3_removeres_sz (NFS3_setattrres_sz)
69 #define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
70 #define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1)
71 #define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1)
72 #define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3)
73 #define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4)
74 #define NFS3_createres_sz (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
75 #define NFS3_renameres_sz (1+(2 * NFS3_wcc_data_sz))
76 #define NFS3_linkres_sz (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
77 #define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2)
78 #define NFS3_fsstatres_sz (1+NFS3_post_op_attr_sz+13)
79 #define NFS3_fsinfores_sz (1+NFS3_post_op_attr_sz+12)
80 #define NFS3_pathconfres_sz (1+NFS3_post_op_attr_sz+6)
81 #define NFS3_commitres_sz (1+NFS3_wcc_data_sz+2)
83 #define ACL3_getaclargs_sz (NFS3_fh_sz+1)
84 #define ACL3_setaclargs_sz (NFS3_fh_sz+1+ \
85 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
86 #define ACL3_getaclres_sz (1+NFS3_post_op_attr_sz+1+ \
87 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
88 #define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
90 static int nfs3_stat_to_errno(enum nfs_stat
);
93 * Map file type to S_IFMT bits
95 static const umode_t nfs_type2fmt
[] = {
102 [NF3SOCK
] = S_IFSOCK
,
107 * While encoding arguments, set up the reply buffer in advance to
108 * receive reply data directly into the page cache.
110 static void prepare_reply_buffer(struct rpc_rqst
*req
, struct page
**pages
,
111 unsigned int base
, unsigned int len
,
112 unsigned int bufsize
)
114 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
117 replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ bufsize
;
118 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, pages
, base
, len
);
122 * Handle decode buffer overflows out-of-line.
124 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
126 dprintk("NFS: %s prematurely hit the end of our receive buffer. "
127 "Remaining buffer length is %tu words.\n",
128 func
, xdr
->end
- xdr
->p
);
133 * Encode/decode NFSv3 basic data types
135 * Basic NFSv3 data types are defined in section 2.5 of RFC 1813:
136 * "NFS Version 3 Protocol Specification".
138 * Not all basic data types have their own encoding and decoding
139 * functions. For run-time efficiency, some data types are encoded
143 static void encode_uint32(struct xdr_stream
*xdr
, u32 value
)
145 __be32
*p
= xdr_reserve_space(xdr
, 4);
146 *p
= cpu_to_be32(value
);
149 static int decode_uint32(struct xdr_stream
*xdr
, u32
*value
)
153 p
= xdr_inline_decode(xdr
, 4);
154 if (unlikely(p
== NULL
))
156 *value
= be32_to_cpup(p
);
159 print_overflow_msg(__func__
, xdr
);
163 static int decode_uint64(struct xdr_stream
*xdr
, u64
*value
)
167 p
= xdr_inline_decode(xdr
, 8);
168 if (unlikely(p
== NULL
))
170 xdr_decode_hyper(p
, value
);
173 print_overflow_msg(__func__
, xdr
);
180 * typedef uint64 fileid3;
182 static __be32
*xdr_decode_fileid3(__be32
*p
, u64
*fileid
)
184 return xdr_decode_hyper(p
, fileid
);
187 static int decode_fileid3(struct xdr_stream
*xdr
, u64
*fileid
)
189 return decode_uint64(xdr
, fileid
);
195 * typedef string filename3<>;
197 static void encode_filename3(struct xdr_stream
*xdr
,
198 const char *name
, u32 length
)
202 WARN_ON_ONCE(length
> NFS3_MAXNAMLEN
);
203 p
= xdr_reserve_space(xdr
, 4 + length
);
204 xdr_encode_opaque(p
, name
, length
);
207 static int decode_inline_filename3(struct xdr_stream
*xdr
,
208 const char **name
, u32
*length
)
213 p
= xdr_inline_decode(xdr
, 4);
214 if (unlikely(p
== NULL
))
216 count
= be32_to_cpup(p
);
217 if (count
> NFS3_MAXNAMLEN
)
218 goto out_nametoolong
;
219 p
= xdr_inline_decode(xdr
, count
);
220 if (unlikely(p
== NULL
))
222 *name
= (const char *)p
;
227 dprintk("NFS: returned filename too long: %u\n", count
);
228 return -ENAMETOOLONG
;
230 print_overflow_msg(__func__
, xdr
);
237 * typedef string nfspath3<>;
239 static void encode_nfspath3(struct xdr_stream
*xdr
, struct page
**pages
,
242 encode_uint32(xdr
, length
);
243 xdr_write_pages(xdr
, pages
, 0, length
);
246 static int decode_nfspath3(struct xdr_stream
*xdr
)
251 p
= xdr_inline_decode(xdr
, 4);
252 if (unlikely(p
== NULL
))
254 count
= be32_to_cpup(p
);
255 if (unlikely(count
>= xdr
->buf
->page_len
|| count
> NFS3_MAXPATHLEN
))
256 goto out_nametoolong
;
257 recvd
= xdr_read_pages(xdr
, count
);
258 if (unlikely(count
> recvd
))
260 xdr_terminate_string(xdr
->buf
, count
);
264 dprintk("NFS: returned pathname too long: %u\n", count
);
265 return -ENAMETOOLONG
;
267 dprintk("NFS: server cheating in pathname result: "
268 "count %u > recvd %u\n", count
, recvd
);
271 print_overflow_msg(__func__
, xdr
);
278 * typedef uint64 cookie3
280 static __be32
*xdr_encode_cookie3(__be32
*p
, u64 cookie
)
282 return xdr_encode_hyper(p
, cookie
);
285 static int decode_cookie3(struct xdr_stream
*xdr
, u64
*cookie
)
287 return decode_uint64(xdr
, cookie
);
293 * typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
295 static __be32
*xdr_encode_cookieverf3(__be32
*p
, const __be32
*verifier
)
297 memcpy(p
, verifier
, NFS3_COOKIEVERFSIZE
);
298 return p
+ XDR_QUADLEN(NFS3_COOKIEVERFSIZE
);
301 static int decode_cookieverf3(struct xdr_stream
*xdr
, __be32
*verifier
)
305 p
= xdr_inline_decode(xdr
, NFS3_COOKIEVERFSIZE
);
306 if (unlikely(p
== NULL
))
308 memcpy(verifier
, p
, NFS3_COOKIEVERFSIZE
);
311 print_overflow_msg(__func__
, xdr
);
318 * typedef opaque createverf3[NFS3_CREATEVERFSIZE];
320 static void encode_createverf3(struct xdr_stream
*xdr
, const __be32
*verifier
)
324 p
= xdr_reserve_space(xdr
, NFS3_CREATEVERFSIZE
);
325 memcpy(p
, verifier
, NFS3_CREATEVERFSIZE
);
328 static int decode_writeverf3(struct xdr_stream
*xdr
, struct nfs_write_verifier
*verifier
)
332 p
= xdr_inline_decode(xdr
, NFS3_WRITEVERFSIZE
);
333 if (unlikely(p
== NULL
))
335 memcpy(verifier
->data
, p
, NFS3_WRITEVERFSIZE
);
338 print_overflow_msg(__func__
, xdr
);
345 * typedef uint64 size3;
347 static __be32
*xdr_decode_size3(__be32
*p
, u64
*size
)
349 return xdr_decode_hyper(p
, size
);
360 #define NFS3_OK NFS_OK
362 static int decode_nfsstat3(struct xdr_stream
*xdr
, enum nfs_stat
*status
)
366 p
= xdr_inline_decode(xdr
, 4);
367 if (unlikely(p
== NULL
))
369 *status
= be32_to_cpup(p
);
372 print_overflow_msg(__func__
, xdr
);
389 static void encode_ftype3(struct xdr_stream
*xdr
, const u32 type
)
391 encode_uint32(xdr
, type
);
394 static __be32
*xdr_decode_ftype3(__be32
*p
, umode_t
*mode
)
398 type
= be32_to_cpup(p
++);
401 *mode
= nfs_type2fmt
[type
];
413 static void encode_specdata3(struct xdr_stream
*xdr
, const dev_t rdev
)
417 p
= xdr_reserve_space(xdr
, 8);
418 *p
++ = cpu_to_be32(MAJOR(rdev
));
419 *p
= cpu_to_be32(MINOR(rdev
));
422 static __be32
*xdr_decode_specdata3(__be32
*p
, dev_t
*rdev
)
424 unsigned int major
, minor
;
426 major
= be32_to_cpup(p
++);
427 minor
= be32_to_cpup(p
++);
428 *rdev
= MKDEV(major
, minor
);
429 if (MAJOR(*rdev
) != major
|| MINOR(*rdev
) != minor
)
438 * opaque data<NFS3_FHSIZE>;
441 static void encode_nfs_fh3(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
)
445 WARN_ON_ONCE(fh
->size
> NFS3_FHSIZE
);
446 p
= xdr_reserve_space(xdr
, 4 + fh
->size
);
447 xdr_encode_opaque(p
, fh
->data
, fh
->size
);
450 static int decode_nfs_fh3(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
455 p
= xdr_inline_decode(xdr
, 4);
456 if (unlikely(p
== NULL
))
458 length
= be32_to_cpup(p
++);
459 if (unlikely(length
> NFS3_FHSIZE
))
461 p
= xdr_inline_decode(xdr
, length
);
462 if (unlikely(p
== NULL
))
465 memcpy(fh
->data
, p
, length
);
468 dprintk("NFS: file handle size (%u) too big\n", length
);
471 print_overflow_msg(__func__
, xdr
);
475 static void zero_nfs_fh3(struct nfs_fh
*fh
)
477 memset(fh
, 0, sizeof(*fh
));
488 static __be32
*xdr_encode_nfstime3(__be32
*p
, const struct timespec
*timep
)
490 *p
++ = cpu_to_be32(timep
->tv_sec
);
491 *p
++ = cpu_to_be32(timep
->tv_nsec
);
495 static __be32
*xdr_decode_nfstime3(__be32
*p
, struct timespec
*timep
)
497 timep
->tv_sec
= be32_to_cpup(p
++);
498 timep
->tv_nsec
= be32_to_cpup(p
++);
507 * SET_TO_SERVER_TIME = 1,
508 * SET_TO_CLIENT_TIME = 2
511 * union set_mode3 switch (bool set_it) {
518 * union set_uid3 switch (bool set_it) {
525 * union set_gid3 switch (bool set_it) {
532 * union set_size3 switch (bool set_it) {
539 * union set_atime switch (time_how set_it) {
540 * case SET_TO_CLIENT_TIME:
546 * union set_mtime switch (time_how set_it) {
547 * case SET_TO_CLIENT_TIME:
562 static void encode_sattr3(struct xdr_stream
*xdr
, const struct iattr
*attr
)
569 * In order to make only a single xdr_reserve_space() call,
570 * pre-compute the total number of bytes to be reserved.
571 * Six boolean values, one for each set_foo field, are always
572 * present in the encoded result, so start there.
575 if (attr
->ia_valid
& ATTR_MODE
)
577 if (attr
->ia_valid
& ATTR_UID
)
579 if (attr
->ia_valid
& ATTR_GID
)
581 if (attr
->ia_valid
& ATTR_SIZE
)
583 if (attr
->ia_valid
& ATTR_ATIME_SET
)
585 if (attr
->ia_valid
& ATTR_MTIME_SET
)
587 p
= xdr_reserve_space(xdr
, nbytes
);
589 if (attr
->ia_valid
& ATTR_MODE
) {
591 *p
++ = cpu_to_be32(attr
->ia_mode
& S_IALLUGO
);
595 if (attr
->ia_valid
& ATTR_UID
) {
597 *p
++ = cpu_to_be32(from_kuid(&init_user_ns
, attr
->ia_uid
));
601 if (attr
->ia_valid
& ATTR_GID
) {
603 *p
++ = cpu_to_be32(from_kgid(&init_user_ns
, attr
->ia_gid
));
607 if (attr
->ia_valid
& ATTR_SIZE
) {
609 p
= xdr_encode_hyper(p
, (u64
)attr
->ia_size
);
613 if (attr
->ia_valid
& ATTR_ATIME_SET
) {
616 ts
= timespec64_to_timespec(attr
->ia_atime
);
617 p
= xdr_encode_nfstime3(p
, &ts
);
618 } else if (attr
->ia_valid
& ATTR_ATIME
) {
623 if (attr
->ia_valid
& ATTR_MTIME_SET
) {
625 ts
= timespec64_to_timespec(attr
->ia_mtime
);
626 xdr_encode_nfstime3(p
, &ts
);
627 } else if (attr
->ia_valid
& ATTR_MTIME
) {
652 static int decode_fattr3(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
)
657 p
= xdr_inline_decode(xdr
, NFS3_fattr_sz
<< 2);
658 if (unlikely(p
== NULL
))
661 p
= xdr_decode_ftype3(p
, &fmode
);
663 fattr
->mode
= (be32_to_cpup(p
++) & ~S_IFMT
) | fmode
;
664 fattr
->nlink
= be32_to_cpup(p
++);
665 fattr
->uid
= make_kuid(&init_user_ns
, be32_to_cpup(p
++));
666 if (!uid_valid(fattr
->uid
))
668 fattr
->gid
= make_kgid(&init_user_ns
, be32_to_cpup(p
++));
669 if (!gid_valid(fattr
->gid
))
672 p
= xdr_decode_size3(p
, &fattr
->size
);
673 p
= xdr_decode_size3(p
, &fattr
->du
.nfs3
.used
);
674 p
= xdr_decode_specdata3(p
, &fattr
->rdev
);
676 p
= xdr_decode_hyper(p
, &fattr
->fsid
.major
);
677 fattr
->fsid
.minor
= 0;
679 p
= xdr_decode_fileid3(p
, &fattr
->fileid
);
680 p
= xdr_decode_nfstime3(p
, &fattr
->atime
);
681 p
= xdr_decode_nfstime3(p
, &fattr
->mtime
);
682 xdr_decode_nfstime3(p
, &fattr
->ctime
);
683 fattr
->change_attr
= nfs_timespec_to_change_attr(&fattr
->ctime
);
685 fattr
->valid
|= NFS_ATTR_FATTR_V3
;
688 dprintk("NFS: returned invalid uid\n");
691 dprintk("NFS: returned invalid gid\n");
694 print_overflow_msg(__func__
, xdr
);
701 * union post_op_attr switch (bool attributes_follow) {
708 static int decode_post_op_attr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
)
712 p
= xdr_inline_decode(xdr
, 4);
713 if (unlikely(p
== NULL
))
716 return decode_fattr3(xdr
, fattr
);
719 print_overflow_msg(__func__
, xdr
);
731 static int decode_wcc_attr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
)
735 p
= xdr_inline_decode(xdr
, NFS3_wcc_attr_sz
<< 2);
736 if (unlikely(p
== NULL
))
739 fattr
->valid
|= NFS_ATTR_FATTR_PRESIZE
740 | NFS_ATTR_FATTR_PRECHANGE
741 | NFS_ATTR_FATTR_PREMTIME
742 | NFS_ATTR_FATTR_PRECTIME
;
744 p
= xdr_decode_size3(p
, &fattr
->pre_size
);
745 p
= xdr_decode_nfstime3(p
, &fattr
->pre_mtime
);
746 xdr_decode_nfstime3(p
, &fattr
->pre_ctime
);
747 fattr
->pre_change_attr
= nfs_timespec_to_change_attr(&fattr
->pre_ctime
);
751 print_overflow_msg(__func__
, xdr
);
757 * union pre_op_attr switch (bool attributes_follow) {
759 * wcc_attr attributes;
767 * pre_op_attr before;
768 * post_op_attr after;
771 static int decode_pre_op_attr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
)
775 p
= xdr_inline_decode(xdr
, 4);
776 if (unlikely(p
== NULL
))
779 return decode_wcc_attr(xdr
, fattr
);
782 print_overflow_msg(__func__
, xdr
);
786 static int decode_wcc_data(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
)
790 error
= decode_pre_op_attr(xdr
, fattr
);
793 error
= decode_post_op_attr(xdr
, fattr
);
801 * union post_op_fh3 switch (bool handle_follows) {
808 static int decode_post_op_fh3(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
810 __be32
*p
= xdr_inline_decode(xdr
, 4);
811 if (unlikely(p
== NULL
))
814 return decode_nfs_fh3(xdr
, fh
);
818 print_overflow_msg(__func__
, xdr
);
825 * struct diropargs3 {
830 static void encode_diropargs3(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
,
831 const char *name
, u32 length
)
833 encode_nfs_fh3(xdr
, fh
);
834 encode_filename3(xdr
, name
, length
);
839 * NFSv3 XDR encode functions
841 * NFSv3 argument types are defined in section 3.3 of RFC 1813:
842 * "NFS Version 3 Protocol Specification".
848 * struct GETATTR3args {
852 static void nfs3_xdr_enc_getattr3args(struct rpc_rqst
*req
,
853 struct xdr_stream
*xdr
,
856 const struct nfs_fh
*fh
= data
;
858 encode_nfs_fh3(xdr
, fh
);
864 * union sattrguard3 switch (bool check) {
866 * nfstime3 obj_ctime;
871 * struct SETATTR3args {
873 * sattr3 new_attributes;
877 static void encode_sattrguard3(struct xdr_stream
*xdr
,
878 const struct nfs3_sattrargs
*args
)
883 p
= xdr_reserve_space(xdr
, 4 + 8);
885 xdr_encode_nfstime3(p
, &args
->guardtime
);
887 p
= xdr_reserve_space(xdr
, 4);
892 static void nfs3_xdr_enc_setattr3args(struct rpc_rqst
*req
,
893 struct xdr_stream
*xdr
,
896 const struct nfs3_sattrargs
*args
= data
;
897 encode_nfs_fh3(xdr
, args
->fh
);
898 encode_sattr3(xdr
, args
->sattr
);
899 encode_sattrguard3(xdr
, args
);
905 * struct LOOKUP3args {
909 static void nfs3_xdr_enc_lookup3args(struct rpc_rqst
*req
,
910 struct xdr_stream
*xdr
,
913 const struct nfs3_diropargs
*args
= data
;
915 encode_diropargs3(xdr
, args
->fh
, args
->name
, args
->len
);
921 * struct ACCESS3args {
926 static void encode_access3args(struct xdr_stream
*xdr
,
927 const struct nfs3_accessargs
*args
)
929 encode_nfs_fh3(xdr
, args
->fh
);
930 encode_uint32(xdr
, args
->access
);
933 static void nfs3_xdr_enc_access3args(struct rpc_rqst
*req
,
934 struct xdr_stream
*xdr
,
937 const struct nfs3_accessargs
*args
= data
;
939 encode_access3args(xdr
, args
);
943 * 3.3.5 READLINK3args
945 * struct READLINK3args {
949 static void nfs3_xdr_enc_readlink3args(struct rpc_rqst
*req
,
950 struct xdr_stream
*xdr
,
953 const struct nfs3_readlinkargs
*args
= data
;
955 encode_nfs_fh3(xdr
, args
->fh
);
956 prepare_reply_buffer(req
, args
->pages
, args
->pgbase
,
957 args
->pglen
, NFS3_readlinkres_sz
);
969 static void encode_read3args(struct xdr_stream
*xdr
,
970 const struct nfs_pgio_args
*args
)
974 encode_nfs_fh3(xdr
, args
->fh
);
976 p
= xdr_reserve_space(xdr
, 8 + 4);
977 p
= xdr_encode_hyper(p
, args
->offset
);
978 *p
= cpu_to_be32(args
->count
);
981 static void nfs3_xdr_enc_read3args(struct rpc_rqst
*req
,
982 struct xdr_stream
*xdr
,
985 const struct nfs_pgio_args
*args
= data
;
987 encode_read3args(xdr
, args
);
988 prepare_reply_buffer(req
, args
->pages
, args
->pgbase
,
989 args
->count
, NFS3_readres_sz
);
990 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
1002 * struct WRITE3args {
1006 * stable_how stable;
1010 static void encode_write3args(struct xdr_stream
*xdr
,
1011 const struct nfs_pgio_args
*args
)
1015 encode_nfs_fh3(xdr
, args
->fh
);
1017 p
= xdr_reserve_space(xdr
, 8 + 4 + 4 + 4);
1018 p
= xdr_encode_hyper(p
, args
->offset
);
1019 *p
++ = cpu_to_be32(args
->count
);
1020 *p
++ = cpu_to_be32(args
->stable
);
1021 *p
= cpu_to_be32(args
->count
);
1022 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1025 static void nfs3_xdr_enc_write3args(struct rpc_rqst
*req
,
1026 struct xdr_stream
*xdr
,
1029 const struct nfs_pgio_args
*args
= data
;
1031 encode_write3args(xdr
, args
);
1032 xdr
->buf
->flags
|= XDRBUF_WRITE
;
1038 * enum createmode3 {
1044 * union createhow3 switch (createmode3 mode) {
1047 * sattr3 obj_attributes;
1052 * struct CREATE3args {
1057 static void encode_createhow3(struct xdr_stream
*xdr
,
1058 const struct nfs3_createargs
*args
)
1060 encode_uint32(xdr
, args
->createmode
);
1061 switch (args
->createmode
) {
1062 case NFS3_CREATE_UNCHECKED
:
1063 case NFS3_CREATE_GUARDED
:
1064 encode_sattr3(xdr
, args
->sattr
);
1066 case NFS3_CREATE_EXCLUSIVE
:
1067 encode_createverf3(xdr
, args
->verifier
);
1074 static void nfs3_xdr_enc_create3args(struct rpc_rqst
*req
,
1075 struct xdr_stream
*xdr
,
1078 const struct nfs3_createargs
*args
= data
;
1080 encode_diropargs3(xdr
, args
->fh
, args
->name
, args
->len
);
1081 encode_createhow3(xdr
, args
);
1087 * struct MKDIR3args {
1089 * sattr3 attributes;
1092 static void nfs3_xdr_enc_mkdir3args(struct rpc_rqst
*req
,
1093 struct xdr_stream
*xdr
,
1096 const struct nfs3_mkdirargs
*args
= data
;
1098 encode_diropargs3(xdr
, args
->fh
, args
->name
, args
->len
);
1099 encode_sattr3(xdr
, args
->sattr
);
1103 * 3.3.10 SYMLINK3args
1105 * struct symlinkdata3 {
1106 * sattr3 symlink_attributes;
1107 * nfspath3 symlink_data;
1110 * struct SYMLINK3args {
1112 * symlinkdata3 symlink;
1115 static void encode_symlinkdata3(struct xdr_stream
*xdr
,
1118 const struct nfs3_symlinkargs
*args
= data
;
1120 encode_sattr3(xdr
, args
->sattr
);
1121 encode_nfspath3(xdr
, args
->pages
, args
->pathlen
);
1124 static void nfs3_xdr_enc_symlink3args(struct rpc_rqst
*req
,
1125 struct xdr_stream
*xdr
,
1128 const struct nfs3_symlinkargs
*args
= data
;
1130 encode_diropargs3(xdr
, args
->fromfh
, args
->fromname
, args
->fromlen
);
1131 encode_symlinkdata3(xdr
, args
);
1132 xdr
->buf
->flags
|= XDRBUF_WRITE
;
1138 * struct devicedata3 {
1139 * sattr3 dev_attributes;
1143 * union mknoddata3 switch (ftype3 type) {
1146 * devicedata3 device;
1149 * sattr3 pipe_attributes;
1154 * struct MKNOD3args {
1159 static void encode_devicedata3(struct xdr_stream
*xdr
,
1160 const struct nfs3_mknodargs
*args
)
1162 encode_sattr3(xdr
, args
->sattr
);
1163 encode_specdata3(xdr
, args
->rdev
);
1166 static void encode_mknoddata3(struct xdr_stream
*xdr
,
1167 const struct nfs3_mknodargs
*args
)
1169 encode_ftype3(xdr
, args
->type
);
1170 switch (args
->type
) {
1173 encode_devicedata3(xdr
, args
);
1177 encode_sattr3(xdr
, args
->sattr
);
1187 static void nfs3_xdr_enc_mknod3args(struct rpc_rqst
*req
,
1188 struct xdr_stream
*xdr
,
1191 const struct nfs3_mknodargs
*args
= data
;
1193 encode_diropargs3(xdr
, args
->fh
, args
->name
, args
->len
);
1194 encode_mknoddata3(xdr
, args
);
1198 * 3.3.12 REMOVE3args
1200 * struct REMOVE3args {
1201 * diropargs3 object;
1204 static void nfs3_xdr_enc_remove3args(struct rpc_rqst
*req
,
1205 struct xdr_stream
*xdr
,
1208 const struct nfs_removeargs
*args
= data
;
1210 encode_diropargs3(xdr
, args
->fh
, args
->name
.name
, args
->name
.len
);
1214 * 3.3.14 RENAME3args
1216 * struct RENAME3args {
1221 static void nfs3_xdr_enc_rename3args(struct rpc_rqst
*req
,
1222 struct xdr_stream
*xdr
,
1225 const struct nfs_renameargs
*args
= data
;
1226 const struct qstr
*old
= args
->old_name
;
1227 const struct qstr
*new = args
->new_name
;
1229 encode_diropargs3(xdr
, args
->old_dir
, old
->name
, old
->len
);
1230 encode_diropargs3(xdr
, args
->new_dir
, new->name
, new->len
);
1236 * struct LINK3args {
1241 static void nfs3_xdr_enc_link3args(struct rpc_rqst
*req
,
1242 struct xdr_stream
*xdr
,
1245 const struct nfs3_linkargs
*args
= data
;
1247 encode_nfs_fh3(xdr
, args
->fromfh
);
1248 encode_diropargs3(xdr
, args
->tofh
, args
->toname
, args
->tolen
);
1252 * 3.3.16 READDIR3args
1254 * struct READDIR3args {
1257 * cookieverf3 cookieverf;
1261 static void encode_readdir3args(struct xdr_stream
*xdr
,
1262 const struct nfs3_readdirargs
*args
)
1266 encode_nfs_fh3(xdr
, args
->fh
);
1268 p
= xdr_reserve_space(xdr
, 8 + NFS3_COOKIEVERFSIZE
+ 4);
1269 p
= xdr_encode_cookie3(p
, args
->cookie
);
1270 p
= xdr_encode_cookieverf3(p
, args
->verf
);
1271 *p
= cpu_to_be32(args
->count
);
1274 static void nfs3_xdr_enc_readdir3args(struct rpc_rqst
*req
,
1275 struct xdr_stream
*xdr
,
1278 const struct nfs3_readdirargs
*args
= data
;
1280 encode_readdir3args(xdr
, args
);
1281 prepare_reply_buffer(req
, args
->pages
, 0,
1282 args
->count
, NFS3_readdirres_sz
);
1286 * 3.3.17 READDIRPLUS3args
1288 * struct READDIRPLUS3args {
1291 * cookieverf3 cookieverf;
1296 static void encode_readdirplus3args(struct xdr_stream
*xdr
,
1297 const struct nfs3_readdirargs
*args
)
1301 encode_nfs_fh3(xdr
, args
->fh
);
1303 p
= xdr_reserve_space(xdr
, 8 + NFS3_COOKIEVERFSIZE
+ 4 + 4);
1304 p
= xdr_encode_cookie3(p
, args
->cookie
);
1305 p
= xdr_encode_cookieverf3(p
, args
->verf
);
1308 * readdirplus: need dircount + buffer size.
1309 * We just make sure we make dircount big enough
1311 *p
++ = cpu_to_be32(args
->count
>> 3);
1313 *p
= cpu_to_be32(args
->count
);
1316 static void nfs3_xdr_enc_readdirplus3args(struct rpc_rqst
*req
,
1317 struct xdr_stream
*xdr
,
1320 const struct nfs3_readdirargs
*args
= data
;
1322 encode_readdirplus3args(xdr
, args
);
1323 prepare_reply_buffer(req
, args
->pages
, 0,
1324 args
->count
, NFS3_readdirres_sz
);
1328 * 3.3.21 COMMIT3args
1330 * struct COMMIT3args {
1336 static void encode_commit3args(struct xdr_stream
*xdr
,
1337 const struct nfs_commitargs
*args
)
1341 encode_nfs_fh3(xdr
, args
->fh
);
1343 p
= xdr_reserve_space(xdr
, 8 + 4);
1344 p
= xdr_encode_hyper(p
, args
->offset
);
1345 *p
= cpu_to_be32(args
->count
);
1348 static void nfs3_xdr_enc_commit3args(struct rpc_rqst
*req
,
1349 struct xdr_stream
*xdr
,
1352 const struct nfs_commitargs
*args
= data
;
1354 encode_commit3args(xdr
, args
);
1357 #ifdef CONFIG_NFS_V3_ACL
1359 static void nfs3_xdr_enc_getacl3args(struct rpc_rqst
*req
,
1360 struct xdr_stream
*xdr
,
1363 const struct nfs3_getaclargs
*args
= data
;
1365 encode_nfs_fh3(xdr
, args
->fh
);
1366 encode_uint32(xdr
, args
->mask
);
1367 if (args
->mask
& (NFS_ACL
| NFS_DFACL
))
1368 prepare_reply_buffer(req
, args
->pages
, 0,
1369 NFSACL_MAXPAGES
<< PAGE_SHIFT
,
1373 static void nfs3_xdr_enc_setacl3args(struct rpc_rqst
*req
,
1374 struct xdr_stream
*xdr
,
1377 const struct nfs3_setaclargs
*args
= data
;
1381 encode_nfs_fh3(xdr
, NFS_FH(args
->inode
));
1382 encode_uint32(xdr
, args
->mask
);
1384 base
= req
->rq_slen
;
1385 if (args
->npages
!= 0)
1386 xdr_write_pages(xdr
, args
->pages
, 0, args
->len
);
1388 xdr_reserve_space(xdr
, args
->len
);
1390 error
= nfsacl_encode(xdr
->buf
, base
, args
->inode
,
1391 (args
->mask
& NFS_ACL
) ?
1392 args
->acl_access
: NULL
, 1, 0);
1393 /* FIXME: this is just broken */
1395 error
= nfsacl_encode(xdr
->buf
, base
+ error
, args
->inode
,
1396 (args
->mask
& NFS_DFACL
) ?
1397 args
->acl_default
: NULL
, 1,
1402 #endif /* CONFIG_NFS_V3_ACL */
1405 * NFSv3 XDR decode functions
1407 * NFSv3 result types are defined in section 3.3 of RFC 1813:
1408 * "NFS Version 3 Protocol Specification".
1414 * struct GETATTR3resok {
1415 * fattr3 obj_attributes;
1418 * union GETATTR3res switch (nfsstat3 status) {
1420 * GETATTR3resok resok;
1425 static int nfs3_xdr_dec_getattr3res(struct rpc_rqst
*req
,
1426 struct xdr_stream
*xdr
,
1429 enum nfs_stat status
;
1432 error
= decode_nfsstat3(xdr
, &status
);
1433 if (unlikely(error
))
1435 if (status
!= NFS3_OK
)
1437 error
= decode_fattr3(xdr
, result
);
1441 return nfs3_stat_to_errno(status
);
1447 * struct SETATTR3resok {
1451 * struct SETATTR3resfail {
1455 * union SETATTR3res switch (nfsstat3 status) {
1457 * SETATTR3resok resok;
1459 * SETATTR3resfail resfail;
1462 static int nfs3_xdr_dec_setattr3res(struct rpc_rqst
*req
,
1463 struct xdr_stream
*xdr
,
1466 enum nfs_stat status
;
1469 error
= decode_nfsstat3(xdr
, &status
);
1470 if (unlikely(error
))
1472 error
= decode_wcc_data(xdr
, result
);
1473 if (unlikely(error
))
1475 if (status
!= NFS3_OK
)
1480 return nfs3_stat_to_errno(status
);
1486 * struct LOOKUP3resok {
1488 * post_op_attr obj_attributes;
1489 * post_op_attr dir_attributes;
1492 * struct LOOKUP3resfail {
1493 * post_op_attr dir_attributes;
1496 * union LOOKUP3res switch (nfsstat3 status) {
1498 * LOOKUP3resok resok;
1500 * LOOKUP3resfail resfail;
1503 static int nfs3_xdr_dec_lookup3res(struct rpc_rqst
*req
,
1504 struct xdr_stream
*xdr
,
1507 struct nfs3_diropres
*result
= data
;
1508 enum nfs_stat status
;
1511 error
= decode_nfsstat3(xdr
, &status
);
1512 if (unlikely(error
))
1514 if (status
!= NFS3_OK
)
1516 error
= decode_nfs_fh3(xdr
, result
->fh
);
1517 if (unlikely(error
))
1519 error
= decode_post_op_attr(xdr
, result
->fattr
);
1520 if (unlikely(error
))
1522 error
= decode_post_op_attr(xdr
, result
->dir_attr
);
1526 error
= decode_post_op_attr(xdr
, result
->dir_attr
);
1527 if (unlikely(error
))
1529 return nfs3_stat_to_errno(status
);
1535 * struct ACCESS3resok {
1536 * post_op_attr obj_attributes;
1540 * struct ACCESS3resfail {
1541 * post_op_attr obj_attributes;
1544 * union ACCESS3res switch (nfsstat3 status) {
1546 * ACCESS3resok resok;
1548 * ACCESS3resfail resfail;
1551 static int nfs3_xdr_dec_access3res(struct rpc_rqst
*req
,
1552 struct xdr_stream
*xdr
,
1555 struct nfs3_accessres
*result
= data
;
1556 enum nfs_stat status
;
1559 error
= decode_nfsstat3(xdr
, &status
);
1560 if (unlikely(error
))
1562 error
= decode_post_op_attr(xdr
, result
->fattr
);
1563 if (unlikely(error
))
1565 if (status
!= NFS3_OK
)
1567 error
= decode_uint32(xdr
, &result
->access
);
1571 return nfs3_stat_to_errno(status
);
1575 * 3.3.5 READLINK3res
1577 * struct READLINK3resok {
1578 * post_op_attr symlink_attributes;
1582 * struct READLINK3resfail {
1583 * post_op_attr symlink_attributes;
1586 * union READLINK3res switch (nfsstat3 status) {
1588 * READLINK3resok resok;
1590 * READLINK3resfail resfail;
1593 static int nfs3_xdr_dec_readlink3res(struct rpc_rqst
*req
,
1594 struct xdr_stream
*xdr
,
1597 enum nfs_stat status
;
1600 error
= decode_nfsstat3(xdr
, &status
);
1601 if (unlikely(error
))
1603 error
= decode_post_op_attr(xdr
, result
);
1604 if (unlikely(error
))
1606 if (status
!= NFS3_OK
)
1608 error
= decode_nfspath3(xdr
);
1612 return nfs3_stat_to_errno(status
);
1618 * struct READ3resok {
1619 * post_op_attr file_attributes;
1625 * struct READ3resfail {
1626 * post_op_attr file_attributes;
1629 * union READ3res switch (nfsstat3 status) {
1633 * READ3resfail resfail;
1636 static int decode_read3resok(struct xdr_stream
*xdr
,
1637 struct nfs_pgio_res
*result
)
1639 u32 eof
, count
, ocount
, recvd
;
1642 p
= xdr_inline_decode(xdr
, 4 + 4 + 4);
1643 if (unlikely(p
== NULL
))
1645 count
= be32_to_cpup(p
++);
1646 eof
= be32_to_cpup(p
++);
1647 ocount
= be32_to_cpup(p
++);
1648 if (unlikely(ocount
!= count
))
1650 recvd
= xdr_read_pages(xdr
, count
);
1651 if (unlikely(count
> recvd
))
1655 result
->count
= count
;
1658 dprintk("NFS: READ count doesn't match length of opaque: "
1659 "count %u != ocount %u\n", count
, ocount
);
1662 dprintk("NFS: server cheating in read result: "
1663 "count %u > recvd %u\n", count
, recvd
);
1668 print_overflow_msg(__func__
, xdr
);
1672 static int nfs3_xdr_dec_read3res(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
1675 struct nfs_pgio_res
*result
= data
;
1676 enum nfs_stat status
;
1679 error
= decode_nfsstat3(xdr
, &status
);
1680 if (unlikely(error
))
1682 error
= decode_post_op_attr(xdr
, result
->fattr
);
1683 if (unlikely(error
))
1685 result
->op_status
= status
;
1686 if (status
!= NFS3_OK
)
1688 error
= decode_read3resok(xdr
, result
);
1692 return nfs3_stat_to_errno(status
);
1704 * struct WRITE3resok {
1705 * wcc_data file_wcc;
1707 * stable_how committed;
1711 * struct WRITE3resfail {
1712 * wcc_data file_wcc;
1715 * union WRITE3res switch (nfsstat3 status) {
1717 * WRITE3resok resok;
1719 * WRITE3resfail resfail;
1722 static int decode_write3resok(struct xdr_stream
*xdr
,
1723 struct nfs_pgio_res
*result
)
1727 p
= xdr_inline_decode(xdr
, 4 + 4);
1728 if (unlikely(p
== NULL
))
1730 result
->count
= be32_to_cpup(p
++);
1731 result
->verf
->committed
= be32_to_cpup(p
++);
1732 if (unlikely(result
->verf
->committed
> NFS_FILE_SYNC
))
1734 if (decode_writeverf3(xdr
, &result
->verf
->verifier
))
1736 return result
->count
;
1738 dprintk("NFS: bad stable_how value: %u\n", result
->verf
->committed
);
1741 print_overflow_msg(__func__
, xdr
);
1746 static int nfs3_xdr_dec_write3res(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
1749 struct nfs_pgio_res
*result
= data
;
1750 enum nfs_stat status
;
1753 error
= decode_nfsstat3(xdr
, &status
);
1754 if (unlikely(error
))
1756 error
= decode_wcc_data(xdr
, result
->fattr
);
1757 if (unlikely(error
))
1759 result
->op_status
= status
;
1760 if (status
!= NFS3_OK
)
1762 error
= decode_write3resok(xdr
, result
);
1766 return nfs3_stat_to_errno(status
);
1772 * struct CREATE3resok {
1774 * post_op_attr obj_attributes;
1778 * struct CREATE3resfail {
1782 * union CREATE3res switch (nfsstat3 status) {
1784 * CREATE3resok resok;
1786 * CREATE3resfail resfail;
1789 static int decode_create3resok(struct xdr_stream
*xdr
,
1790 struct nfs3_diropres
*result
)
1794 error
= decode_post_op_fh3(xdr
, result
->fh
);
1795 if (unlikely(error
))
1797 error
= decode_post_op_attr(xdr
, result
->fattr
);
1798 if (unlikely(error
))
1800 /* The server isn't required to return a file handle.
1801 * If it didn't, force the client to perform a LOOKUP
1802 * to determine the correct file handle and attribute
1803 * values for the new object. */
1804 if (result
->fh
->size
== 0)
1805 result
->fattr
->valid
= 0;
1806 error
= decode_wcc_data(xdr
, result
->dir_attr
);
1811 static int nfs3_xdr_dec_create3res(struct rpc_rqst
*req
,
1812 struct xdr_stream
*xdr
,
1815 struct nfs3_diropres
*result
= data
;
1816 enum nfs_stat status
;
1819 error
= decode_nfsstat3(xdr
, &status
);
1820 if (unlikely(error
))
1822 if (status
!= NFS3_OK
)
1824 error
= decode_create3resok(xdr
, result
);
1828 error
= decode_wcc_data(xdr
, result
->dir_attr
);
1829 if (unlikely(error
))
1831 return nfs3_stat_to_errno(status
);
1837 * struct REMOVE3resok {
1841 * struct REMOVE3resfail {
1845 * union REMOVE3res switch (nfsstat3 status) {
1847 * REMOVE3resok resok;
1849 * REMOVE3resfail resfail;
1852 static int nfs3_xdr_dec_remove3res(struct rpc_rqst
*req
,
1853 struct xdr_stream
*xdr
,
1856 struct nfs_removeres
*result
= data
;
1857 enum nfs_stat status
;
1860 error
= decode_nfsstat3(xdr
, &status
);
1861 if (unlikely(error
))
1863 error
= decode_wcc_data(xdr
, result
->dir_attr
);
1864 if (unlikely(error
))
1866 if (status
!= NFS3_OK
)
1871 return nfs3_stat_to_errno(status
);
1877 * struct RENAME3resok {
1878 * wcc_data fromdir_wcc;
1879 * wcc_data todir_wcc;
1882 * struct RENAME3resfail {
1883 * wcc_data fromdir_wcc;
1884 * wcc_data todir_wcc;
1887 * union RENAME3res switch (nfsstat3 status) {
1889 * RENAME3resok resok;
1891 * RENAME3resfail resfail;
1894 static int nfs3_xdr_dec_rename3res(struct rpc_rqst
*req
,
1895 struct xdr_stream
*xdr
,
1898 struct nfs_renameres
*result
= data
;
1899 enum nfs_stat status
;
1902 error
= decode_nfsstat3(xdr
, &status
);
1903 if (unlikely(error
))
1905 error
= decode_wcc_data(xdr
, result
->old_fattr
);
1906 if (unlikely(error
))
1908 error
= decode_wcc_data(xdr
, result
->new_fattr
);
1909 if (unlikely(error
))
1911 if (status
!= NFS3_OK
)
1916 return nfs3_stat_to_errno(status
);
1922 * struct LINK3resok {
1923 * post_op_attr file_attributes;
1924 * wcc_data linkdir_wcc;
1927 * struct LINK3resfail {
1928 * post_op_attr file_attributes;
1929 * wcc_data linkdir_wcc;
1932 * union LINK3res switch (nfsstat3 status) {
1936 * LINK3resfail resfail;
1939 static int nfs3_xdr_dec_link3res(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
1942 struct nfs3_linkres
*result
= data
;
1943 enum nfs_stat status
;
1946 error
= decode_nfsstat3(xdr
, &status
);
1947 if (unlikely(error
))
1949 error
= decode_post_op_attr(xdr
, result
->fattr
);
1950 if (unlikely(error
))
1952 error
= decode_wcc_data(xdr
, result
->dir_attr
);
1953 if (unlikely(error
))
1955 if (status
!= NFS3_OK
)
1960 return nfs3_stat_to_errno(status
);
1964 * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in
1965 * the local page cache
1966 * @xdr: XDR stream where entry resides
1967 * @entry: buffer to fill in with entry data
1968 * @plus: boolean indicating whether this should be a readdirplus entry
1970 * Returns zero if successful, otherwise a negative errno value is
1973 * This function is not invoked during READDIR reply decoding, but
1974 * rather whenever an application invokes the getdents(2) system call
1975 * on a directory already in our cache.
1983 * fhandle3 filehandle;
1984 * post_op_attr3 attributes;
1985 * entry3 *nextentry;
1989 * struct entryplus3 {
1993 * post_op_attr name_attributes;
1994 * post_op_fh3 name_handle;
1995 * entryplus3 *nextentry;
1998 int nfs3_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
2001 struct nfs_entry old
= *entry
;
2006 p
= xdr_inline_decode(xdr
, 4);
2007 if (unlikely(p
== NULL
))
2009 if (*p
== xdr_zero
) {
2010 p
= xdr_inline_decode(xdr
, 4);
2011 if (unlikely(p
== NULL
))
2019 error
= decode_fileid3(xdr
, &entry
->ino
);
2020 if (unlikely(error
))
2023 error
= decode_inline_filename3(xdr
, &entry
->name
, &entry
->len
);
2024 if (unlikely(error
))
2027 error
= decode_cookie3(xdr
, &new_cookie
);
2028 if (unlikely(error
))
2031 entry
->d_type
= DT_UNKNOWN
;
2034 entry
->fattr
->valid
= 0;
2035 error
= decode_post_op_attr(xdr
, entry
->fattr
);
2036 if (unlikely(error
))
2038 if (entry
->fattr
->valid
& NFS_ATTR_FATTR_V3
)
2039 entry
->d_type
= nfs_umode_to_dtype(entry
->fattr
->mode
);
2041 if (entry
->fattr
->fileid
!= entry
->ino
) {
2042 entry
->fattr
->mounted_on_fileid
= entry
->ino
;
2043 entry
->fattr
->valid
|= NFS_ATTR_FATTR_MOUNTED_ON_FILEID
;
2046 /* In fact, a post_op_fh3: */
2047 p
= xdr_inline_decode(xdr
, 4);
2048 if (unlikely(p
== NULL
))
2050 if (*p
!= xdr_zero
) {
2051 error
= decode_nfs_fh3(xdr
, entry
->fh
);
2052 if (unlikely(error
)) {
2053 if (error
== -E2BIG
)
2058 zero_nfs_fh3(entry
->fh
);
2061 entry
->prev_cookie
= entry
->cookie
;
2062 entry
->cookie
= new_cookie
;
2067 print_overflow_msg(__func__
, xdr
);
2070 dprintk("NFS: directory entry contains invalid file handle\n");
2076 * 3.3.16 READDIR3res
2083 * struct READDIR3resok {
2084 * post_op_attr dir_attributes;
2085 * cookieverf3 cookieverf;
2089 * struct READDIR3resfail {
2090 * post_op_attr dir_attributes;
2093 * union READDIR3res switch (nfsstat3 status) {
2095 * READDIR3resok resok;
2097 * READDIR3resfail resfail;
2100 * Read the directory contents into the page cache, but otherwise
2101 * don't touch them. The actual decoding is done by nfs3_decode_entry()
2102 * during subsequent nfs_readdir() calls.
2104 static int decode_dirlist3(struct xdr_stream
*xdr
)
2106 return xdr_read_pages(xdr
, xdr
->buf
->page_len
);
2109 static int decode_readdir3resok(struct xdr_stream
*xdr
,
2110 struct nfs3_readdirres
*result
)
2114 error
= decode_post_op_attr(xdr
, result
->dir_attr
);
2115 if (unlikely(error
))
2117 /* XXX: do we need to check if result->verf != NULL ? */
2118 error
= decode_cookieverf3(xdr
, result
->verf
);
2119 if (unlikely(error
))
2121 error
= decode_dirlist3(xdr
);
2126 static int nfs3_xdr_dec_readdir3res(struct rpc_rqst
*req
,
2127 struct xdr_stream
*xdr
,
2130 struct nfs3_readdirres
*result
= data
;
2131 enum nfs_stat status
;
2134 error
= decode_nfsstat3(xdr
, &status
);
2135 if (unlikely(error
))
2137 if (status
!= NFS3_OK
)
2139 error
= decode_readdir3resok(xdr
, result
);
2143 error
= decode_post_op_attr(xdr
, result
->dir_attr
);
2144 if (unlikely(error
))
2146 return nfs3_stat_to_errno(status
);
2152 * struct FSSTAT3resok {
2153 * post_op_attr obj_attributes;
2163 * struct FSSTAT3resfail {
2164 * post_op_attr obj_attributes;
2167 * union FSSTAT3res switch (nfsstat3 status) {
2169 * FSSTAT3resok resok;
2171 * FSSTAT3resfail resfail;
2174 static int decode_fsstat3resok(struct xdr_stream
*xdr
,
2175 struct nfs_fsstat
*result
)
2179 p
= xdr_inline_decode(xdr
, 8 * 6 + 4);
2180 if (unlikely(p
== NULL
))
2182 p
= xdr_decode_size3(p
, &result
->tbytes
);
2183 p
= xdr_decode_size3(p
, &result
->fbytes
);
2184 p
= xdr_decode_size3(p
, &result
->abytes
);
2185 p
= xdr_decode_size3(p
, &result
->tfiles
);
2186 p
= xdr_decode_size3(p
, &result
->ffiles
);
2187 xdr_decode_size3(p
, &result
->afiles
);
2188 /* ignore invarsec */
2191 print_overflow_msg(__func__
, xdr
);
2195 static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst
*req
,
2196 struct xdr_stream
*xdr
,
2199 struct nfs_fsstat
*result
= data
;
2200 enum nfs_stat status
;
2203 error
= decode_nfsstat3(xdr
, &status
);
2204 if (unlikely(error
))
2206 error
= decode_post_op_attr(xdr
, result
->fattr
);
2207 if (unlikely(error
))
2209 if (status
!= NFS3_OK
)
2211 error
= decode_fsstat3resok(xdr
, result
);
2215 return nfs3_stat_to_errno(status
);
2221 * struct FSINFO3resok {
2222 * post_op_attr obj_attributes;
2230 * size3 maxfilesize;
2231 * nfstime3 time_delta;
2232 * uint32 properties;
2235 * struct FSINFO3resfail {
2236 * post_op_attr obj_attributes;
2239 * union FSINFO3res switch (nfsstat3 status) {
2241 * FSINFO3resok resok;
2243 * FSINFO3resfail resfail;
2246 static int decode_fsinfo3resok(struct xdr_stream
*xdr
,
2247 struct nfs_fsinfo
*result
)
2251 p
= xdr_inline_decode(xdr
, 4 * 7 + 8 + 8 + 4);
2252 if (unlikely(p
== NULL
))
2254 result
->rtmax
= be32_to_cpup(p
++);
2255 result
->rtpref
= be32_to_cpup(p
++);
2256 result
->rtmult
= be32_to_cpup(p
++);
2257 result
->wtmax
= be32_to_cpup(p
++);
2258 result
->wtpref
= be32_to_cpup(p
++);
2259 result
->wtmult
= be32_to_cpup(p
++);
2260 result
->dtpref
= be32_to_cpup(p
++);
2261 p
= xdr_decode_size3(p
, &result
->maxfilesize
);
2262 xdr_decode_nfstime3(p
, &result
->time_delta
);
2264 /* ignore properties */
2265 result
->lease_time
= 0;
2268 print_overflow_msg(__func__
, xdr
);
2272 static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst
*req
,
2273 struct xdr_stream
*xdr
,
2276 struct nfs_fsinfo
*result
= data
;
2277 enum nfs_stat status
;
2280 error
= decode_nfsstat3(xdr
, &status
);
2281 if (unlikely(error
))
2283 error
= decode_post_op_attr(xdr
, result
->fattr
);
2284 if (unlikely(error
))
2286 if (status
!= NFS3_OK
)
2288 error
= decode_fsinfo3resok(xdr
, result
);
2292 return nfs3_stat_to_errno(status
);
2296 * 3.3.20 PATHCONF3res
2298 * struct PATHCONF3resok {
2299 * post_op_attr obj_attributes;
2303 * bool chown_restricted;
2304 * bool case_insensitive;
2305 * bool case_preserving;
2308 * struct PATHCONF3resfail {
2309 * post_op_attr obj_attributes;
2312 * union PATHCONF3res switch (nfsstat3 status) {
2314 * PATHCONF3resok resok;
2316 * PATHCONF3resfail resfail;
2319 static int decode_pathconf3resok(struct xdr_stream
*xdr
,
2320 struct nfs_pathconf
*result
)
2324 p
= xdr_inline_decode(xdr
, 4 * 6);
2325 if (unlikely(p
== NULL
))
2327 result
->max_link
= be32_to_cpup(p
++);
2328 result
->max_namelen
= be32_to_cpup(p
);
2329 /* ignore remaining fields */
2332 print_overflow_msg(__func__
, xdr
);
2336 static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst
*req
,
2337 struct xdr_stream
*xdr
,
2340 struct nfs_pathconf
*result
= data
;
2341 enum nfs_stat status
;
2344 error
= decode_nfsstat3(xdr
, &status
);
2345 if (unlikely(error
))
2347 error
= decode_post_op_attr(xdr
, result
->fattr
);
2348 if (unlikely(error
))
2350 if (status
!= NFS3_OK
)
2352 error
= decode_pathconf3resok(xdr
, result
);
2356 return nfs3_stat_to_errno(status
);
2362 * struct COMMIT3resok {
2363 * wcc_data file_wcc;
2367 * struct COMMIT3resfail {
2368 * wcc_data file_wcc;
2371 * union COMMIT3res switch (nfsstat3 status) {
2373 * COMMIT3resok resok;
2375 * COMMIT3resfail resfail;
2378 static int nfs3_xdr_dec_commit3res(struct rpc_rqst
*req
,
2379 struct xdr_stream
*xdr
,
2382 struct nfs_commitres
*result
= data
;
2383 enum nfs_stat status
;
2386 error
= decode_nfsstat3(xdr
, &status
);
2387 if (unlikely(error
))
2389 error
= decode_wcc_data(xdr
, result
->fattr
);
2390 if (unlikely(error
))
2392 result
->op_status
= status
;
2393 if (status
!= NFS3_OK
)
2395 error
= decode_writeverf3(xdr
, &result
->verf
->verifier
);
2399 return nfs3_stat_to_errno(status
);
2402 #ifdef CONFIG_NFS_V3_ACL
2404 static inline int decode_getacl3resok(struct xdr_stream
*xdr
,
2405 struct nfs3_getaclres
*result
)
2407 struct posix_acl
**acl
;
2408 unsigned int *aclcnt
;
2412 error
= decode_post_op_attr(xdr
, result
->fattr
);
2413 if (unlikely(error
))
2415 error
= decode_uint32(xdr
, &result
->mask
);
2416 if (unlikely(error
))
2419 if (result
->mask
& ~(NFS_ACL
|NFS_ACLCNT
|NFS_DFACL
|NFS_DFACLCNT
))
2422 hdrlen
= xdr_stream_pos(xdr
);
2425 if (result
->mask
& NFS_ACL
)
2426 acl
= &result
->acl_access
;
2428 if (result
->mask
& NFS_ACLCNT
)
2429 aclcnt
= &result
->acl_access_count
;
2430 error
= nfsacl_decode(xdr
->buf
, hdrlen
, aclcnt
, acl
);
2431 if (unlikely(error
<= 0))
2435 if (result
->mask
& NFS_DFACL
)
2436 acl
= &result
->acl_default
;
2438 if (result
->mask
& NFS_DFACLCNT
)
2439 aclcnt
= &result
->acl_default_count
;
2440 error
= nfsacl_decode(xdr
->buf
, hdrlen
+ error
, aclcnt
, acl
);
2441 if (unlikely(error
<= 0))
2448 static int nfs3_xdr_dec_getacl3res(struct rpc_rqst
*req
,
2449 struct xdr_stream
*xdr
,
2452 enum nfs_stat status
;
2455 error
= decode_nfsstat3(xdr
, &status
);
2456 if (unlikely(error
))
2458 if (status
!= NFS3_OK
)
2460 error
= decode_getacl3resok(xdr
, result
);
2464 return nfs3_stat_to_errno(status
);
2467 static int nfs3_xdr_dec_setacl3res(struct rpc_rqst
*req
,
2468 struct xdr_stream
*xdr
,
2471 enum nfs_stat status
;
2474 error
= decode_nfsstat3(xdr
, &status
);
2475 if (unlikely(error
))
2477 if (status
!= NFS3_OK
)
2479 error
= decode_post_op_attr(xdr
, result
);
2483 return nfs3_stat_to_errno(status
);
2486 #endif /* CONFIG_NFS_V3_ACL */
2490 * We need to translate between nfs status return values and
2491 * the local errno values which may not be the same.
2493 static const struct {
2498 { NFSERR_PERM
, -EPERM
},
2499 { NFSERR_NOENT
, -ENOENT
},
2500 { NFSERR_IO
, -errno_NFSERR_IO
},
2501 { NFSERR_NXIO
, -ENXIO
},
2502 /* { NFSERR_EAGAIN, -EAGAIN }, */
2503 { NFSERR_ACCES
, -EACCES
},
2504 { NFSERR_EXIST
, -EEXIST
},
2505 { NFSERR_XDEV
, -EXDEV
},
2506 { NFSERR_NODEV
, -ENODEV
},
2507 { NFSERR_NOTDIR
, -ENOTDIR
},
2508 { NFSERR_ISDIR
, -EISDIR
},
2509 { NFSERR_INVAL
, -EINVAL
},
2510 { NFSERR_FBIG
, -EFBIG
},
2511 { NFSERR_NOSPC
, -ENOSPC
},
2512 { NFSERR_ROFS
, -EROFS
},
2513 { NFSERR_MLINK
, -EMLINK
},
2514 { NFSERR_NAMETOOLONG
, -ENAMETOOLONG
},
2515 { NFSERR_NOTEMPTY
, -ENOTEMPTY
},
2516 { NFSERR_DQUOT
, -EDQUOT
},
2517 { NFSERR_STALE
, -ESTALE
},
2518 { NFSERR_REMOTE
, -EREMOTE
},
2520 { NFSERR_WFLUSH
, -EWFLUSH
},
2522 { NFSERR_BADHANDLE
, -EBADHANDLE
},
2523 { NFSERR_NOT_SYNC
, -ENOTSYNC
},
2524 { NFSERR_BAD_COOKIE
, -EBADCOOKIE
},
2525 { NFSERR_NOTSUPP
, -ENOTSUPP
},
2526 { NFSERR_TOOSMALL
, -ETOOSMALL
},
2527 { NFSERR_SERVERFAULT
, -EREMOTEIO
},
2528 { NFSERR_BADTYPE
, -EBADTYPE
},
2529 { NFSERR_JUKEBOX
, -EJUKEBOX
},
2534 * nfs3_stat_to_errno - convert an NFS status code to a local errno
2535 * @status: NFS status code to convert
2537 * Returns a local errno value, or -EIO if the NFS status code is
2538 * not recognized. This function is used jointly by NFSv2 and NFSv3.
2540 static int nfs3_stat_to_errno(enum nfs_stat status
)
2544 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
2545 if (nfs_errtbl
[i
].stat
== (int)status
)
2546 return nfs_errtbl
[i
].errno
;
2548 dprintk("NFS: Unrecognized nfs status value: %u\n", status
);
2549 return nfs_errtbl
[i
].errno
;
2553 #define PROC(proc, argtype, restype, timer) \
2554 [NFS3PROC_##proc] = { \
2555 .p_proc = NFS3PROC_##proc, \
2556 .p_encode = nfs3_xdr_enc_##argtype##3args, \
2557 .p_decode = nfs3_xdr_dec_##restype##3res, \
2558 .p_arglen = NFS3_##argtype##args_sz, \
2559 .p_replen = NFS3_##restype##res_sz, \
2561 .p_statidx = NFS3PROC_##proc, \
2565 const struct rpc_procinfo nfs3_procedures
[] = {
2566 PROC(GETATTR
, getattr
, getattr
, 1),
2567 PROC(SETATTR
, setattr
, setattr
, 0),
2568 PROC(LOOKUP
, lookup
, lookup
, 2),
2569 PROC(ACCESS
, access
, access
, 1),
2570 PROC(READLINK
, readlink
, readlink
, 3),
2571 PROC(READ
, read
, read
, 3),
2572 PROC(WRITE
, write
, write
, 4),
2573 PROC(CREATE
, create
, create
, 0),
2574 PROC(MKDIR
, mkdir
, create
, 0),
2575 PROC(SYMLINK
, symlink
, create
, 0),
2576 PROC(MKNOD
, mknod
, create
, 0),
2577 PROC(REMOVE
, remove
, remove
, 0),
2578 PROC(RMDIR
, lookup
, setattr
, 0),
2579 PROC(RENAME
, rename
, rename
, 0),
2580 PROC(LINK
, link
, link
, 0),
2581 PROC(READDIR
, readdir
, readdir
, 3),
2582 PROC(READDIRPLUS
, readdirplus
, readdir
, 3),
2583 PROC(FSSTAT
, getattr
, fsstat
, 0),
2584 PROC(FSINFO
, getattr
, fsinfo
, 0),
2585 PROC(PATHCONF
, getattr
, pathconf
, 0),
2586 PROC(COMMIT
, commit
, commit
, 5),
2589 static unsigned int nfs_version3_counts
[ARRAY_SIZE(nfs3_procedures
)];
2590 const struct rpc_version nfs_version3
= {
2592 .nrprocs
= ARRAY_SIZE(nfs3_procedures
),
2593 .procs
= nfs3_procedures
,
2594 .counts
= nfs_version3_counts
,
2597 #ifdef CONFIG_NFS_V3_ACL
2598 static const struct rpc_procinfo nfs3_acl_procedures
[] = {
2599 [ACLPROC3_GETACL
] = {
2600 .p_proc
= ACLPROC3_GETACL
,
2601 .p_encode
= nfs3_xdr_enc_getacl3args
,
2602 .p_decode
= nfs3_xdr_dec_getacl3res
,
2603 .p_arglen
= ACL3_getaclargs_sz
,
2604 .p_replen
= ACL3_getaclres_sz
,
2608 [ACLPROC3_SETACL
] = {
2609 .p_proc
= ACLPROC3_SETACL
,
2610 .p_encode
= nfs3_xdr_enc_setacl3args
,
2611 .p_decode
= nfs3_xdr_dec_setacl3res
,
2612 .p_arglen
= ACL3_setaclargs_sz
,
2613 .p_replen
= ACL3_setaclres_sz
,
2619 static unsigned int nfs3_acl_counts
[ARRAY_SIZE(nfs3_acl_procedures
)];
2620 const struct rpc_version nfsacl_version3
= {
2622 .nrprocs
= ARRAY_SIZE(nfs3_acl_procedures
),
2623 .procs
= nfs3_acl_procedures
,
2624 .counts
= nfs3_acl_counts
,
2626 #endif /* CONFIG_NFS_V3_ACL */