1 // SPDX-License-Identifier: GPL-2.0
3 * linux/fs/nfs/nfs2xdr.c
5 * XDR functions to encode/decode NFS RPC arguments and results.
7 * Copyright (C) 1992, 1993, 1994 Rick Sladkey
8 * Copyright (C) 1996 Olaf Kirch
9 * 04 Aug 1998 Ion Badulescu <ionut@cs.columbia.edu>
10 * FIFO's need special handling in NFSv2
13 #include <linux/param.h>
14 #include <linux/time.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
19 #include <linux/pagemap.h>
20 #include <linux/proc_fs.h>
21 #include <linux/sunrpc/clnt.h>
22 #include <linux/nfs.h>
23 #include <linux/nfs2.h>
24 #include <linux/nfs_fs.h>
28 #define NFSDBG_FACILITY NFSDBG_XDR
30 /* Mapping from NFS error code to "errno" error code. */
31 #define errno_NFSERR_IO EIO
34 * Declare the space requirements for NFS arguments and replies as
35 * number of 32bit-words
37 #define NFS_pagepad_sz (1) /* Page padding */
38 #define NFS_fhandle_sz (8)
39 #define NFS_sattr_sz (8)
40 #define NFS_filename_sz (1+(NFS2_MAXNAMLEN>>2))
41 #define NFS_path_sz (1+(NFS2_MAXPATHLEN>>2))
42 #define NFS_fattr_sz (17)
43 #define NFS_info_sz (5)
44 #define NFS_entry_sz (NFS_filename_sz+3)
46 #define NFS_diropargs_sz (NFS_fhandle_sz+NFS_filename_sz)
47 #define NFS_removeargs_sz (NFS_fhandle_sz+NFS_filename_sz)
48 #define NFS_sattrargs_sz (NFS_fhandle_sz+NFS_sattr_sz)
49 #define NFS_readlinkargs_sz (NFS_fhandle_sz)
50 #define NFS_readargs_sz (NFS_fhandle_sz+3)
51 #define NFS_writeargs_sz (NFS_fhandle_sz+4)
52 #define NFS_createargs_sz (NFS_diropargs_sz+NFS_sattr_sz)
53 #define NFS_renameargs_sz (NFS_diropargs_sz+NFS_diropargs_sz)
54 #define NFS_linkargs_sz (NFS_fhandle_sz+NFS_diropargs_sz)
55 #define NFS_symlinkargs_sz (NFS_diropargs_sz+1+NFS_sattr_sz)
56 #define NFS_readdirargs_sz (NFS_fhandle_sz+2)
58 #define NFS_attrstat_sz (1+NFS_fattr_sz)
59 #define NFS_diropres_sz (1+NFS_fhandle_sz+NFS_fattr_sz)
60 #define NFS_readlinkres_sz (2+NFS_pagepad_sz)
61 #define NFS_readres_sz (1+NFS_fattr_sz+1+NFS_pagepad_sz)
62 #define NFS_writeres_sz (NFS_attrstat_sz)
63 #define NFS_stat_sz (1)
64 #define NFS_readdirres_sz (1+NFS_pagepad_sz)
65 #define NFS_statfsres_sz (1+NFS_info_sz)
67 static int nfs_stat_to_errno(enum nfs_stat
);
70 * Encode/decode NFSv2 basic data types
72 * Basic NFSv2 data types are defined in section 2.3 of RFC 1094:
73 * "NFS: Network File System Protocol Specification".
75 * Not all basic data types have their own encoding and decoding
76 * functions. For run-time efficiency, some data types are encoded
80 static struct user_namespace
*rpc_userns(const struct rpc_clnt
*clnt
)
82 if (clnt
&& clnt
->cl_cred
)
83 return clnt
->cl_cred
->user_ns
;
87 static struct user_namespace
*rpc_rqst_userns(const struct rpc_rqst
*rqstp
)
90 return rpc_userns(rqstp
->rq_task
->tk_client
);
95 * typedef opaque nfsdata<>;
97 static int decode_nfsdata(struct xdr_stream
*xdr
, struct nfs_pgio_res
*result
)
102 p
= xdr_inline_decode(xdr
, 4);
105 count
= be32_to_cpup(p
);
106 recvd
= xdr_read_pages(xdr
, count
);
107 if (unlikely(count
> recvd
))
110 result
->eof
= 0; /* NFSv2 does not pass EOF flag on the wire. */
111 result
->count
= count
;
114 dprintk("NFS: server cheating in read result: "
115 "count %u > recvd %u\n", count
, recvd
);
130 * NFSERR_NOTDIR = 20,
135 * NFSERR_NAMETOOLONG = 63,
136 * NFSERR_NOTEMPTY = 66,
142 static int decode_stat(struct xdr_stream
*xdr
, enum nfs_stat
*status
)
146 p
= xdr_inline_decode(xdr
, 4);
149 if (unlikely(*p
!= cpu_to_be32(NFS_OK
)))
154 *status
= be32_to_cpup(p
);
155 trace_nfs_xdr_status(xdr
, (int)*status
);
172 static __be32
*xdr_decode_ftype(__be32
*p
, u32
*type
)
174 *type
= be32_to_cpup(p
++);
175 if (unlikely(*type
> NF2FIFO
))
183 * typedef opaque fhandle[FHSIZE];
185 static void encode_fhandle(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
)
189 p
= xdr_reserve_space(xdr
, NFS2_FHSIZE
);
190 memcpy(p
, fh
->data
, NFS2_FHSIZE
);
193 static int decode_fhandle(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
197 p
= xdr_inline_decode(xdr
, NFS2_FHSIZE
);
200 fh
->size
= NFS2_FHSIZE
;
201 memcpy(fh
->data
, p
, NFS2_FHSIZE
);
209 * unsigned int seconds;
210 * unsigned int useconds;
213 static __be32
*xdr_encode_time(__be32
*p
, const struct timespec64
*timep
)
215 *p
++ = cpu_to_be32((u32
)timep
->tv_sec
);
216 if (timep
->tv_nsec
!= 0)
217 *p
++ = cpu_to_be32(timep
->tv_nsec
/ NSEC_PER_USEC
);
219 *p
++ = cpu_to_be32(0);
224 * Passing the invalid value useconds=1000000 is a Sun convention for
225 * "set to current server time". It's needed to make permissions checks
226 * for the "touch" program across v2 mounts to Solaris and Irix servers
227 * work correctly. See description of sattr in section 6.1 of "NFS
228 * Illustrated" by Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5.
230 static __be32
*xdr_encode_current_server_time(__be32
*p
,
231 const struct timespec64
*timep
)
233 *p
++ = cpu_to_be32(timep
->tv_sec
);
234 *p
++ = cpu_to_be32(1000000);
238 static __be32
*xdr_decode_time(__be32
*p
, struct timespec64
*timep
)
240 timep
->tv_sec
= be32_to_cpup(p
++);
241 timep
->tv_nsec
= be32_to_cpup(p
++) * NSEC_PER_USEC
;
251 * unsigned int nlink;
255 * unsigned int blocksize;
257 * unsigned int blocks;
259 * unsigned int fileid;
266 static int decode_fattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
267 struct user_namespace
*userns
)
272 p
= xdr_inline_decode(xdr
, NFS_fattr_sz
<< 2);
276 fattr
->valid
|= NFS_ATTR_FATTR_V2
;
278 p
= xdr_decode_ftype(p
, &type
);
280 fattr
->mode
= be32_to_cpup(p
++);
281 fattr
->nlink
= be32_to_cpup(p
++);
282 fattr
->uid
= make_kuid(userns
, be32_to_cpup(p
++));
283 if (!uid_valid(fattr
->uid
))
285 fattr
->gid
= make_kgid(userns
, be32_to_cpup(p
++));
286 if (!gid_valid(fattr
->gid
))
289 fattr
->size
= be32_to_cpup(p
++);
290 fattr
->du
.nfs2
.blocksize
= be32_to_cpup(p
++);
292 rdev
= be32_to_cpup(p
++);
293 fattr
->rdev
= new_decode_dev(rdev
);
294 if (type
== (u32
)NFCHR
&& rdev
== (u32
)NFS2_FIFO_DEV
) {
295 fattr
->mode
= (fattr
->mode
& ~S_IFMT
) | S_IFIFO
;
299 fattr
->du
.nfs2
.blocks
= be32_to_cpup(p
++);
300 fattr
->fsid
.major
= be32_to_cpup(p
++);
301 fattr
->fsid
.minor
= 0;
302 fattr
->fileid
= be32_to_cpup(p
++);
304 p
= xdr_decode_time(p
, &fattr
->atime
);
305 p
= xdr_decode_time(p
, &fattr
->mtime
);
306 xdr_decode_time(p
, &fattr
->ctime
);
307 fattr
->change_attr
= nfs_timespec_to_change_attr(&fattr
->ctime
);
311 dprintk("NFS: returned invalid uid\n");
314 dprintk("NFS: returned invalid gid\n");
331 #define NFS2_SATTR_NOT_SET (0xffffffff)
333 static __be32
*xdr_time_not_set(__be32
*p
)
335 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
336 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
340 static void encode_sattr(struct xdr_stream
*xdr
, const struct iattr
*attr
,
341 struct user_namespace
*userns
)
345 p
= xdr_reserve_space(xdr
, NFS_sattr_sz
<< 2);
347 if (attr
->ia_valid
& ATTR_MODE
)
348 *p
++ = cpu_to_be32(attr
->ia_mode
);
350 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
351 if (attr
->ia_valid
& ATTR_UID
)
352 *p
++ = cpu_to_be32(from_kuid_munged(userns
, attr
->ia_uid
));
354 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
355 if (attr
->ia_valid
& ATTR_GID
)
356 *p
++ = cpu_to_be32(from_kgid_munged(userns
, attr
->ia_gid
));
358 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
359 if (attr
->ia_valid
& ATTR_SIZE
)
360 *p
++ = cpu_to_be32((u32
)attr
->ia_size
);
362 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
364 if (attr
->ia_valid
& ATTR_ATIME_SET
)
365 p
= xdr_encode_time(p
, &attr
->ia_atime
);
366 else if (attr
->ia_valid
& ATTR_ATIME
)
367 p
= xdr_encode_current_server_time(p
, &attr
->ia_atime
);
369 p
= xdr_time_not_set(p
);
370 if (attr
->ia_valid
& ATTR_MTIME_SET
)
371 xdr_encode_time(p
, &attr
->ia_mtime
);
372 else if (attr
->ia_valid
& ATTR_MTIME
)
373 xdr_encode_current_server_time(p
, &attr
->ia_mtime
);
381 * typedef string filename<MAXNAMLEN>;
383 static void encode_filename(struct xdr_stream
*xdr
,
384 const char *name
, u32 length
)
388 WARN_ON_ONCE(length
> NFS2_MAXNAMLEN
);
389 p
= xdr_reserve_space(xdr
, 4 + length
);
390 xdr_encode_opaque(p
, name
, length
);
393 static int decode_filename_inline(struct xdr_stream
*xdr
,
394 const char **name
, u32
*length
)
399 p
= xdr_inline_decode(xdr
, 4);
402 count
= be32_to_cpup(p
);
403 if (count
> NFS3_MAXNAMLEN
)
404 goto out_nametoolong
;
405 p
= xdr_inline_decode(xdr
, count
);
408 *name
= (const char *)p
;
412 dprintk("NFS: returned filename too long: %u\n", count
);
413 return -ENAMETOOLONG
;
419 * typedef string path<MAXPATHLEN>;
421 static void encode_path(struct xdr_stream
*xdr
, struct page
**pages
, u32 length
)
425 p
= xdr_reserve_space(xdr
, 4);
426 *p
= cpu_to_be32(length
);
427 xdr_write_pages(xdr
, pages
, 0, length
);
430 static int decode_path(struct xdr_stream
*xdr
)
435 p
= xdr_inline_decode(xdr
, 4);
438 length
= be32_to_cpup(p
);
439 if (unlikely(length
>= xdr
->buf
->page_len
|| length
> NFS_MAXPATHLEN
))
441 recvd
= xdr_read_pages(xdr
, length
);
442 if (unlikely(length
> recvd
))
444 xdr_terminate_string(xdr
->buf
, length
);
447 dprintk("NFS: returned pathname too long: %u\n", length
);
448 return -ENAMETOOLONG
;
450 dprintk("NFS: server cheating in pathname result: "
451 "length %u > received %u\n", length
, recvd
);
458 * union attrstat switch (stat status) {
465 static int decode_attrstat(struct xdr_stream
*xdr
, struct nfs_fattr
*result
,
467 struct user_namespace
*userns
)
469 enum nfs_stat status
;
472 error
= decode_stat(xdr
, &status
);
477 if (status
!= NFS_OK
)
479 error
= decode_fattr(xdr
, result
, userns
);
483 return nfs_stat_to_errno(status
);
494 static void encode_diropargs(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
,
495 const char *name
, u32 length
)
497 encode_fhandle(xdr
, fh
);
498 encode_filename(xdr
, name
, length
);
504 * union diropres switch (stat status) {
514 static int decode_diropok(struct xdr_stream
*xdr
, struct nfs_diropok
*result
,
515 struct user_namespace
*userns
)
519 error
= decode_fhandle(xdr
, result
->fh
);
522 error
= decode_fattr(xdr
, result
->fattr
, userns
);
527 static int decode_diropres(struct xdr_stream
*xdr
, struct nfs_diropok
*result
,
528 struct user_namespace
*userns
)
530 enum nfs_stat status
;
533 error
= decode_stat(xdr
, &status
);
536 if (status
!= NFS_OK
)
538 error
= decode_diropok(xdr
, result
, userns
);
542 return nfs_stat_to_errno(status
);
547 * NFSv2 XDR encode functions
549 * NFSv2 argument types are defined in section 2.2 of RFC 1094:
550 * "NFS: Network File System Protocol Specification".
553 static void nfs2_xdr_enc_fhandle(struct rpc_rqst
*req
,
554 struct xdr_stream
*xdr
,
557 const struct nfs_fh
*fh
= data
;
559 encode_fhandle(xdr
, fh
);
570 static void nfs2_xdr_enc_sattrargs(struct rpc_rqst
*req
,
571 struct xdr_stream
*xdr
,
574 const struct nfs_sattrargs
*args
= data
;
576 encode_fhandle(xdr
, args
->fh
);
577 encode_sattr(xdr
, args
->sattr
, rpc_rqst_userns(req
));
580 static void nfs2_xdr_enc_diropargs(struct rpc_rqst
*req
,
581 struct xdr_stream
*xdr
,
584 const struct nfs_diropargs
*args
= data
;
586 encode_diropargs(xdr
, args
->fh
, args
->name
, args
->len
);
589 static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst
*req
,
590 struct xdr_stream
*xdr
,
593 const struct nfs_readlinkargs
*args
= data
;
595 encode_fhandle(xdr
, args
->fh
);
596 rpc_prepare_reply_pages(req
, args
->pages
, args
->pgbase
, args
->pglen
,
597 NFS_readlinkres_sz
- NFS_pagepad_sz
);
607 * unsigned totalcount;
610 static void encode_readargs(struct xdr_stream
*xdr
,
611 const struct nfs_pgio_args
*args
)
613 u32 offset
= args
->offset
;
614 u32 count
= args
->count
;
617 encode_fhandle(xdr
, args
->fh
);
619 p
= xdr_reserve_space(xdr
, 4 + 4 + 4);
620 *p
++ = cpu_to_be32(offset
);
621 *p
++ = cpu_to_be32(count
);
622 *p
= cpu_to_be32(count
);
625 static void nfs2_xdr_enc_readargs(struct rpc_rqst
*req
,
626 struct xdr_stream
*xdr
,
629 const struct nfs_pgio_args
*args
= data
;
631 encode_readargs(xdr
, args
);
632 rpc_prepare_reply_pages(req
, args
->pages
, args
->pgbase
, args
->count
,
633 NFS_readres_sz
- NFS_pagepad_sz
);
634 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
642 * unsigned beginoffset;
644 * unsigned totalcount;
648 static void encode_writeargs(struct xdr_stream
*xdr
,
649 const struct nfs_pgio_args
*args
)
651 u32 offset
= args
->offset
;
652 u32 count
= args
->count
;
655 encode_fhandle(xdr
, args
->fh
);
657 p
= xdr_reserve_space(xdr
, 4 + 4 + 4 + 4);
658 *p
++ = cpu_to_be32(offset
);
659 *p
++ = cpu_to_be32(offset
);
660 *p
++ = cpu_to_be32(count
);
663 *p
= cpu_to_be32(count
);
664 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, count
);
667 static void nfs2_xdr_enc_writeargs(struct rpc_rqst
*req
,
668 struct xdr_stream
*xdr
,
671 const struct nfs_pgio_args
*args
= data
;
673 encode_writeargs(xdr
, args
);
674 xdr
->buf
->flags
|= XDRBUF_WRITE
;
680 * struct createargs {
685 static void nfs2_xdr_enc_createargs(struct rpc_rqst
*req
,
686 struct xdr_stream
*xdr
,
689 const struct nfs_createargs
*args
= data
;
691 encode_diropargs(xdr
, args
->fh
, args
->name
, args
->len
);
692 encode_sattr(xdr
, args
->sattr
, rpc_rqst_userns(req
));
695 static void nfs2_xdr_enc_removeargs(struct rpc_rqst
*req
,
696 struct xdr_stream
*xdr
,
699 const struct nfs_removeargs
*args
= data
;
701 encode_diropargs(xdr
, args
->fh
, args
->name
.name
, args
->name
.len
);
707 * struct renameargs {
712 static void nfs2_xdr_enc_renameargs(struct rpc_rqst
*req
,
713 struct xdr_stream
*xdr
,
716 const struct nfs_renameargs
*args
= data
;
717 const struct qstr
*old
= args
->old_name
;
718 const struct qstr
*new = args
->new_name
;
720 encode_diropargs(xdr
, args
->old_dir
, old
->name
, old
->len
);
721 encode_diropargs(xdr
, args
->new_dir
, new->name
, new->len
);
732 static void nfs2_xdr_enc_linkargs(struct rpc_rqst
*req
,
733 struct xdr_stream
*xdr
,
736 const struct nfs_linkargs
*args
= data
;
738 encode_fhandle(xdr
, args
->fromfh
);
739 encode_diropargs(xdr
, args
->tofh
, args
->toname
, args
->tolen
);
743 * 2.2.14. symlinkargs
745 * struct symlinkargs {
751 static void nfs2_xdr_enc_symlinkargs(struct rpc_rqst
*req
,
752 struct xdr_stream
*xdr
,
755 const struct nfs_symlinkargs
*args
= data
;
757 encode_diropargs(xdr
, args
->fromfh
, args
->fromname
, args
->fromlen
);
758 encode_path(xdr
, args
->pages
, args
->pathlen
);
759 encode_sattr(xdr
, args
->sattr
, rpc_rqst_userns(req
));
763 * 2.2.17. readdirargs
765 * struct readdirargs {
771 static void encode_readdirargs(struct xdr_stream
*xdr
,
772 const struct nfs_readdirargs
*args
)
776 encode_fhandle(xdr
, args
->fh
);
778 p
= xdr_reserve_space(xdr
, 4 + 4);
779 *p
++ = cpu_to_be32(args
->cookie
);
780 *p
= cpu_to_be32(args
->count
);
783 static void nfs2_xdr_enc_readdirargs(struct rpc_rqst
*req
,
784 struct xdr_stream
*xdr
,
787 const struct nfs_readdirargs
*args
= data
;
789 encode_readdirargs(xdr
, args
);
790 rpc_prepare_reply_pages(req
, args
->pages
, 0, args
->count
,
791 NFS_readdirres_sz
- NFS_pagepad_sz
);
795 * NFSv2 XDR decode functions
797 * NFSv2 result types are defined in section 2.2 of RFC 1094:
798 * "NFS: Network File System Protocol Specification".
801 static int nfs2_xdr_dec_stat(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
804 enum nfs_stat status
;
807 error
= decode_stat(xdr
, &status
);
810 if (status
!= NFS_OK
)
815 return nfs_stat_to_errno(status
);
818 static int nfs2_xdr_dec_attrstat(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
821 return decode_attrstat(xdr
, result
, NULL
, rpc_rqst_userns(req
));
824 static int nfs2_xdr_dec_diropres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
827 return decode_diropres(xdr
, result
, rpc_rqst_userns(req
));
833 * union readlinkres switch (stat status) {
840 static int nfs2_xdr_dec_readlinkres(struct rpc_rqst
*req
,
841 struct xdr_stream
*xdr
, void *__unused
)
843 enum nfs_stat status
;
846 error
= decode_stat(xdr
, &status
);
849 if (status
!= NFS_OK
)
851 error
= decode_path(xdr
);
855 return nfs_stat_to_errno(status
);
861 * union readres switch (stat status) {
869 static int nfs2_xdr_dec_readres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
872 struct nfs_pgio_res
*result
= data
;
873 enum nfs_stat status
;
876 error
= decode_stat(xdr
, &status
);
879 result
->op_status
= status
;
880 if (status
!= NFS_OK
)
882 error
= decode_fattr(xdr
, result
->fattr
, rpc_rqst_userns(req
));
885 error
= decode_nfsdata(xdr
, result
);
889 return nfs_stat_to_errno(status
);
892 static int nfs2_xdr_dec_writeres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
895 struct nfs_pgio_res
*result
= data
;
897 /* All NFSv2 writes are "file sync" writes */
898 result
->verf
->committed
= NFS_FILE_SYNC
;
899 return decode_attrstat(xdr
, result
->fattr
, &result
->op_status
,
900 rpc_rqst_userns(req
));
904 * nfs2_decode_dirent - Decode a single NFSv2 directory entry stored in
905 * the local page cache.
906 * @xdr: XDR stream where entry resides
907 * @entry: buffer to fill in with entry data
908 * @plus: boolean indicating whether this should be a readdirplus entry
910 * Returns zero if successful, otherwise a negative errno value is
913 * This function is not invoked during READDIR reply decoding, but
914 * rather whenever an application invokes the getdents(2) system call
915 * on a directory already in our cache.
926 int nfs2_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
932 p
= xdr_inline_decode(xdr
, 4);
935 if (*p
++ == xdr_zero
) {
936 p
= xdr_inline_decode(xdr
, 4);
939 if (*p
++ == xdr_zero
)
945 p
= xdr_inline_decode(xdr
, 4);
948 entry
->ino
= be32_to_cpup(p
);
950 error
= decode_filename_inline(xdr
, &entry
->name
, &entry
->len
);
955 * The type (size and byte order) of nfscookie isn't defined in
956 * RFC 1094. This implementation assumes that it's an XDR uint32.
958 entry
->prev_cookie
= entry
->cookie
;
959 p
= xdr_inline_decode(xdr
, 4);
962 entry
->cookie
= be32_to_cpup(p
);
964 entry
->d_type
= DT_UNKNOWN
;
972 * union readdirres switch (stat status) {
982 * Read the directory contents into the page cache, but don't
983 * touch them. The actual decoding is done by nfs2_decode_dirent()
984 * during subsequent nfs_readdir() calls.
986 static int decode_readdirok(struct xdr_stream
*xdr
)
988 return xdr_read_pages(xdr
, xdr
->buf
->page_len
);
991 static int nfs2_xdr_dec_readdirres(struct rpc_rqst
*req
,
992 struct xdr_stream
*xdr
, void *__unused
)
994 enum nfs_stat status
;
997 error
= decode_stat(xdr
, &status
);
1000 if (status
!= NFS_OK
)
1002 error
= decode_readdirok(xdr
);
1006 return nfs_stat_to_errno(status
);
1012 * union statfsres (stat status) {
1025 static int decode_info(struct xdr_stream
*xdr
, struct nfs2_fsstat
*result
)
1029 p
= xdr_inline_decode(xdr
, NFS_info_sz
<< 2);
1032 result
->tsize
= be32_to_cpup(p
++);
1033 result
->bsize
= be32_to_cpup(p
++);
1034 result
->blocks
= be32_to_cpup(p
++);
1035 result
->bfree
= be32_to_cpup(p
++);
1036 result
->bavail
= be32_to_cpup(p
);
1040 static int nfs2_xdr_dec_statfsres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
1043 enum nfs_stat status
;
1046 error
= decode_stat(xdr
, &status
);
1047 if (unlikely(error
))
1049 if (status
!= NFS_OK
)
1051 error
= decode_info(xdr
, result
);
1055 return nfs_stat_to_errno(status
);
1060 * We need to translate between nfs status return values and
1061 * the local errno values which may not be the same.
1063 static const struct {
1068 { NFSERR_PERM
, -EPERM
},
1069 { NFSERR_NOENT
, -ENOENT
},
1070 { NFSERR_IO
, -errno_NFSERR_IO
},
1071 { NFSERR_NXIO
, -ENXIO
},
1072 /* { NFSERR_EAGAIN, -EAGAIN }, */
1073 { NFSERR_ACCES
, -EACCES
},
1074 { NFSERR_EXIST
, -EEXIST
},
1075 { NFSERR_XDEV
, -EXDEV
},
1076 { NFSERR_NODEV
, -ENODEV
},
1077 { NFSERR_NOTDIR
, -ENOTDIR
},
1078 { NFSERR_ISDIR
, -EISDIR
},
1079 { NFSERR_INVAL
, -EINVAL
},
1080 { NFSERR_FBIG
, -EFBIG
},
1081 { NFSERR_NOSPC
, -ENOSPC
},
1082 { NFSERR_ROFS
, -EROFS
},
1083 { NFSERR_MLINK
, -EMLINK
},
1084 { NFSERR_NAMETOOLONG
, -ENAMETOOLONG
},
1085 { NFSERR_NOTEMPTY
, -ENOTEMPTY
},
1086 { NFSERR_DQUOT
, -EDQUOT
},
1087 { NFSERR_STALE
, -ESTALE
},
1088 { NFSERR_REMOTE
, -EREMOTE
},
1090 { NFSERR_WFLUSH
, -EWFLUSH
},
1092 { NFSERR_BADHANDLE
, -EBADHANDLE
},
1093 { NFSERR_NOT_SYNC
, -ENOTSYNC
},
1094 { NFSERR_BAD_COOKIE
, -EBADCOOKIE
},
1095 { NFSERR_NOTSUPP
, -ENOTSUPP
},
1096 { NFSERR_TOOSMALL
, -ETOOSMALL
},
1097 { NFSERR_SERVERFAULT
, -EREMOTEIO
},
1098 { NFSERR_BADTYPE
, -EBADTYPE
},
1099 { NFSERR_JUKEBOX
, -EJUKEBOX
},
1104 * nfs_stat_to_errno - convert an NFS status code to a local errno
1105 * @status: NFS status code to convert
1107 * Returns a local errno value, or -EIO if the NFS status code is
1108 * not recognized. This function is used jointly by NFSv2 and NFSv3.
1110 static int nfs_stat_to_errno(enum nfs_stat status
)
1114 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
1115 if (nfs_errtbl
[i
].stat
== (int)status
)
1116 return nfs_errtbl
[i
].errno
;
1118 dprintk("NFS: Unrecognized nfs status value: %u\n", status
);
1119 return nfs_errtbl
[i
].errno
;
1122 #define PROC(proc, argtype, restype, timer) \
1123 [NFSPROC_##proc] = { \
1124 .p_proc = NFSPROC_##proc, \
1125 .p_encode = nfs2_xdr_enc_##argtype, \
1126 .p_decode = nfs2_xdr_dec_##restype, \
1127 .p_arglen = NFS_##argtype##_sz, \
1128 .p_replen = NFS_##restype##_sz, \
1130 .p_statidx = NFSPROC_##proc, \
1133 const struct rpc_procinfo nfs_procedures
[] = {
1134 PROC(GETATTR
, fhandle
, attrstat
, 1),
1135 PROC(SETATTR
, sattrargs
, attrstat
, 0),
1136 PROC(LOOKUP
, diropargs
, diropres
, 2),
1137 PROC(READLINK
, readlinkargs
, readlinkres
, 3),
1138 PROC(READ
, readargs
, readres
, 3),
1139 PROC(WRITE
, writeargs
, writeres
, 4),
1140 PROC(CREATE
, createargs
, diropres
, 0),
1141 PROC(REMOVE
, removeargs
, stat
, 0),
1142 PROC(RENAME
, renameargs
, stat
, 0),
1143 PROC(LINK
, linkargs
, stat
, 0),
1144 PROC(SYMLINK
, symlinkargs
, stat
, 0),
1145 PROC(MKDIR
, createargs
, diropres
, 0),
1146 PROC(RMDIR
, diropargs
, stat
, 0),
1147 PROC(READDIR
, readdirargs
, readdirres
, 3),
1148 PROC(STATFS
, fhandle
, statfsres
, 0),
1151 static unsigned int nfs_version2_counts
[ARRAY_SIZE(nfs_procedures
)];
1152 const struct rpc_version nfs_version2
= {
1154 .nrprocs
= ARRAY_SIZE(nfs_procedures
),
1155 .procs
= nfs_procedures
,
1156 .counts
= nfs_version2_counts
,