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_fhandle_sz (8)
38 #define NFS_sattr_sz (8)
39 #define NFS_filename_sz (1+(NFS2_MAXNAMLEN>>2))
40 #define NFS_path_sz (1+(NFS2_MAXPATHLEN>>2))
41 #define NFS_fattr_sz (17)
42 #define NFS_info_sz (5)
43 #define NFS_entry_sz (NFS_filename_sz+3)
45 #define NFS_diropargs_sz (NFS_fhandle_sz+NFS_filename_sz)
46 #define NFS_removeargs_sz (NFS_fhandle_sz+NFS_filename_sz)
47 #define NFS_sattrargs_sz (NFS_fhandle_sz+NFS_sattr_sz)
48 #define NFS_readlinkargs_sz (NFS_fhandle_sz)
49 #define NFS_readargs_sz (NFS_fhandle_sz+3)
50 #define NFS_writeargs_sz (NFS_fhandle_sz+4)
51 #define NFS_createargs_sz (NFS_diropargs_sz+NFS_sattr_sz)
52 #define NFS_renameargs_sz (NFS_diropargs_sz+NFS_diropargs_sz)
53 #define NFS_linkargs_sz (NFS_fhandle_sz+NFS_diropargs_sz)
54 #define NFS_symlinkargs_sz (NFS_diropargs_sz+1+NFS_sattr_sz)
55 #define NFS_readdirargs_sz (NFS_fhandle_sz+2)
57 #define NFS_attrstat_sz (1+NFS_fattr_sz)
58 #define NFS_diropres_sz (1+NFS_fhandle_sz+NFS_fattr_sz)
59 #define NFS_readlinkres_sz (2+1)
60 #define NFS_readres_sz (1+NFS_fattr_sz+1+1)
61 #define NFS_writeres_sz (NFS_attrstat_sz)
62 #define NFS_stat_sz (1)
63 #define NFS_readdirres_sz (1+1)
64 #define NFS_statfsres_sz (1+NFS_info_sz)
66 static int nfs_stat_to_errno(enum nfs_stat
);
69 * Encode/decode NFSv2 basic data types
71 * Basic NFSv2 data types are defined in section 2.3 of RFC 1094:
72 * "NFS: Network File System Protocol Specification".
74 * Not all basic data types have their own encoding and decoding
75 * functions. For run-time efficiency, some data types are encoded
79 static struct user_namespace
*rpc_userns(const struct rpc_clnt
*clnt
)
81 if (clnt
&& clnt
->cl_cred
)
82 return clnt
->cl_cred
->user_ns
;
86 static struct user_namespace
*rpc_rqst_userns(const struct rpc_rqst
*rqstp
)
89 return rpc_userns(rqstp
->rq_task
->tk_client
);
94 * typedef opaque nfsdata<>;
96 static int decode_nfsdata(struct xdr_stream
*xdr
, struct nfs_pgio_res
*result
)
101 p
= xdr_inline_decode(xdr
, 4);
104 count
= be32_to_cpup(p
);
105 recvd
= xdr_read_pages(xdr
, count
);
106 if (unlikely(count
> recvd
))
109 result
->eof
= 0; /* NFSv2 does not pass EOF flag on the wire. */
110 result
->count
= count
;
113 dprintk("NFS: server cheating in read result: "
114 "count %u > recvd %u\n", count
, recvd
);
129 * NFSERR_NOTDIR = 20,
134 * NFSERR_NAMETOOLONG = 63,
135 * NFSERR_NOTEMPTY = 66,
141 static int decode_stat(struct xdr_stream
*xdr
, enum nfs_stat
*status
)
145 p
= xdr_inline_decode(xdr
, 4);
148 if (unlikely(*p
!= cpu_to_be32(NFS_OK
)))
153 *status
= be32_to_cpup(p
);
154 trace_nfs_xdr_status((int)*status
);
171 static __be32
*xdr_decode_ftype(__be32
*p
, u32
*type
)
173 *type
= be32_to_cpup(p
++);
174 if (unlikely(*type
> NF2FIFO
))
182 * typedef opaque fhandle[FHSIZE];
184 static void encode_fhandle(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
)
188 p
= xdr_reserve_space(xdr
, NFS2_FHSIZE
);
189 memcpy(p
, fh
->data
, NFS2_FHSIZE
);
192 static int decode_fhandle(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
196 p
= xdr_inline_decode(xdr
, NFS2_FHSIZE
);
199 fh
->size
= NFS2_FHSIZE
;
200 memcpy(fh
->data
, p
, NFS2_FHSIZE
);
208 * unsigned int seconds;
209 * unsigned int useconds;
212 static __be32
*xdr_encode_time(__be32
*p
, const struct timespec
*timep
)
214 *p
++ = cpu_to_be32(timep
->tv_sec
);
215 if (timep
->tv_nsec
!= 0)
216 *p
++ = cpu_to_be32(timep
->tv_nsec
/ NSEC_PER_USEC
);
218 *p
++ = cpu_to_be32(0);
223 * Passing the invalid value useconds=1000000 is a Sun convention for
224 * "set to current server time". It's needed to make permissions checks
225 * for the "touch" program across v2 mounts to Solaris and Irix servers
226 * work correctly. See description of sattr in section 6.1 of "NFS
227 * Illustrated" by Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5.
229 static __be32
*xdr_encode_current_server_time(__be32
*p
,
230 const struct timespec
*timep
)
232 *p
++ = cpu_to_be32(timep
->tv_sec
);
233 *p
++ = cpu_to_be32(1000000);
237 static __be32
*xdr_decode_time(__be32
*p
, struct timespec
*timep
)
239 timep
->tv_sec
= be32_to_cpup(p
++);
240 timep
->tv_nsec
= be32_to_cpup(p
++) * NSEC_PER_USEC
;
250 * unsigned int nlink;
254 * unsigned int blocksize;
256 * unsigned int blocks;
258 * unsigned int fileid;
265 static int decode_fattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
,
266 struct user_namespace
*userns
)
271 p
= xdr_inline_decode(xdr
, NFS_fattr_sz
<< 2);
275 fattr
->valid
|= NFS_ATTR_FATTR_V2
;
277 p
= xdr_decode_ftype(p
, &type
);
279 fattr
->mode
= be32_to_cpup(p
++);
280 fattr
->nlink
= be32_to_cpup(p
++);
281 fattr
->uid
= make_kuid(userns
, be32_to_cpup(p
++));
282 if (!uid_valid(fattr
->uid
))
284 fattr
->gid
= make_kgid(userns
, be32_to_cpup(p
++));
285 if (!gid_valid(fattr
->gid
))
288 fattr
->size
= be32_to_cpup(p
++);
289 fattr
->du
.nfs2
.blocksize
= be32_to_cpup(p
++);
291 rdev
= be32_to_cpup(p
++);
292 fattr
->rdev
= new_decode_dev(rdev
);
293 if (type
== (u32
)NFCHR
&& rdev
== (u32
)NFS2_FIFO_DEV
) {
294 fattr
->mode
= (fattr
->mode
& ~S_IFMT
) | S_IFIFO
;
298 fattr
->du
.nfs2
.blocks
= be32_to_cpup(p
++);
299 fattr
->fsid
.major
= be32_to_cpup(p
++);
300 fattr
->fsid
.minor
= 0;
301 fattr
->fileid
= be32_to_cpup(p
++);
303 p
= xdr_decode_time(p
, &fattr
->atime
);
304 p
= xdr_decode_time(p
, &fattr
->mtime
);
305 xdr_decode_time(p
, &fattr
->ctime
);
306 fattr
->change_attr
= nfs_timespec_to_change_attr(&fattr
->ctime
);
310 dprintk("NFS: returned invalid uid\n");
313 dprintk("NFS: returned invalid gid\n");
330 #define NFS2_SATTR_NOT_SET (0xffffffff)
332 static __be32
*xdr_time_not_set(__be32
*p
)
334 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
335 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
339 static void encode_sattr(struct xdr_stream
*xdr
, const struct iattr
*attr
,
340 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 ts
= timespec64_to_timespec(attr
->ia_atime
);
366 p
= xdr_encode_time(p
, &ts
);
367 } else if (attr
->ia_valid
& ATTR_ATIME
) {
368 ts
= timespec64_to_timespec(attr
->ia_atime
);
369 p
= xdr_encode_current_server_time(p
, &ts
);
371 p
= xdr_time_not_set(p
);
372 if (attr
->ia_valid
& ATTR_MTIME_SET
) {
373 ts
= timespec64_to_timespec(attr
->ia_atime
);
374 xdr_encode_time(p
, &ts
);
375 } else if (attr
->ia_valid
& ATTR_MTIME
) {
376 ts
= timespec64_to_timespec(attr
->ia_mtime
);
377 xdr_encode_current_server_time(p
, &ts
);
385 * typedef string filename<MAXNAMLEN>;
387 static void encode_filename(struct xdr_stream
*xdr
,
388 const char *name
, u32 length
)
392 WARN_ON_ONCE(length
> NFS2_MAXNAMLEN
);
393 p
= xdr_reserve_space(xdr
, 4 + length
);
394 xdr_encode_opaque(p
, name
, length
);
397 static int decode_filename_inline(struct xdr_stream
*xdr
,
398 const char **name
, u32
*length
)
403 p
= xdr_inline_decode(xdr
, 4);
406 count
= be32_to_cpup(p
);
407 if (count
> NFS3_MAXNAMLEN
)
408 goto out_nametoolong
;
409 p
= xdr_inline_decode(xdr
, count
);
412 *name
= (const char *)p
;
416 dprintk("NFS: returned filename too long: %u\n", count
);
417 return -ENAMETOOLONG
;
423 * typedef string path<MAXPATHLEN>;
425 static void encode_path(struct xdr_stream
*xdr
, struct page
**pages
, u32 length
)
429 p
= xdr_reserve_space(xdr
, 4);
430 *p
= cpu_to_be32(length
);
431 xdr_write_pages(xdr
, pages
, 0, length
);
434 static int decode_path(struct xdr_stream
*xdr
)
439 p
= xdr_inline_decode(xdr
, 4);
442 length
= be32_to_cpup(p
);
443 if (unlikely(length
>= xdr
->buf
->page_len
|| length
> NFS_MAXPATHLEN
))
445 recvd
= xdr_read_pages(xdr
, length
);
446 if (unlikely(length
> recvd
))
448 xdr_terminate_string(xdr
->buf
, length
);
451 dprintk("NFS: returned pathname too long: %u\n", length
);
452 return -ENAMETOOLONG
;
454 dprintk("NFS: server cheating in pathname result: "
455 "length %u > received %u\n", length
, recvd
);
462 * union attrstat switch (stat status) {
469 static int decode_attrstat(struct xdr_stream
*xdr
, struct nfs_fattr
*result
,
471 struct user_namespace
*userns
)
473 enum nfs_stat status
;
476 error
= decode_stat(xdr
, &status
);
481 if (status
!= NFS_OK
)
483 error
= decode_fattr(xdr
, result
, userns
);
487 return nfs_stat_to_errno(status
);
498 static void encode_diropargs(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
,
499 const char *name
, u32 length
)
501 encode_fhandle(xdr
, fh
);
502 encode_filename(xdr
, name
, length
);
508 * union diropres switch (stat status) {
518 static int decode_diropok(struct xdr_stream
*xdr
, struct nfs_diropok
*result
,
519 struct user_namespace
*userns
)
523 error
= decode_fhandle(xdr
, result
->fh
);
526 error
= decode_fattr(xdr
, result
->fattr
, userns
);
531 static int decode_diropres(struct xdr_stream
*xdr
, struct nfs_diropok
*result
,
532 struct user_namespace
*userns
)
534 enum nfs_stat status
;
537 error
= decode_stat(xdr
, &status
);
540 if (status
!= NFS_OK
)
542 error
= decode_diropok(xdr
, result
, userns
);
546 return nfs_stat_to_errno(status
);
551 * NFSv2 XDR encode functions
553 * NFSv2 argument types are defined in section 2.2 of RFC 1094:
554 * "NFS: Network File System Protocol Specification".
557 static void nfs2_xdr_enc_fhandle(struct rpc_rqst
*req
,
558 struct xdr_stream
*xdr
,
561 const struct nfs_fh
*fh
= data
;
563 encode_fhandle(xdr
, fh
);
574 static void nfs2_xdr_enc_sattrargs(struct rpc_rqst
*req
,
575 struct xdr_stream
*xdr
,
578 const struct nfs_sattrargs
*args
= data
;
580 encode_fhandle(xdr
, args
->fh
);
581 encode_sattr(xdr
, args
->sattr
, rpc_rqst_userns(req
));
584 static void nfs2_xdr_enc_diropargs(struct rpc_rqst
*req
,
585 struct xdr_stream
*xdr
,
588 const struct nfs_diropargs
*args
= data
;
590 encode_diropargs(xdr
, args
->fh
, args
->name
, args
->len
);
593 static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst
*req
,
594 struct xdr_stream
*xdr
,
597 const struct nfs_readlinkargs
*args
= data
;
599 encode_fhandle(xdr
, args
->fh
);
600 rpc_prepare_reply_pages(req
, args
->pages
, args
->pgbase
,
601 args
->pglen
, NFS_readlinkres_sz
);
611 * unsigned totalcount;
614 static void encode_readargs(struct xdr_stream
*xdr
,
615 const struct nfs_pgio_args
*args
)
617 u32 offset
= args
->offset
;
618 u32 count
= args
->count
;
621 encode_fhandle(xdr
, args
->fh
);
623 p
= xdr_reserve_space(xdr
, 4 + 4 + 4);
624 *p
++ = cpu_to_be32(offset
);
625 *p
++ = cpu_to_be32(count
);
626 *p
= cpu_to_be32(count
);
629 static void nfs2_xdr_enc_readargs(struct rpc_rqst
*req
,
630 struct xdr_stream
*xdr
,
633 const struct nfs_pgio_args
*args
= data
;
635 encode_readargs(xdr
, args
);
636 rpc_prepare_reply_pages(req
, args
->pages
, args
->pgbase
,
637 args
->count
, NFS_readres_sz
);
638 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
646 * unsigned beginoffset;
648 * unsigned totalcount;
652 static void encode_writeargs(struct xdr_stream
*xdr
,
653 const struct nfs_pgio_args
*args
)
655 u32 offset
= args
->offset
;
656 u32 count
= args
->count
;
659 encode_fhandle(xdr
, args
->fh
);
661 p
= xdr_reserve_space(xdr
, 4 + 4 + 4 + 4);
662 *p
++ = cpu_to_be32(offset
);
663 *p
++ = cpu_to_be32(offset
);
664 *p
++ = cpu_to_be32(count
);
667 *p
= cpu_to_be32(count
);
668 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, count
);
671 static void nfs2_xdr_enc_writeargs(struct rpc_rqst
*req
,
672 struct xdr_stream
*xdr
,
675 const struct nfs_pgio_args
*args
= data
;
677 encode_writeargs(xdr
, args
);
678 xdr
->buf
->flags
|= XDRBUF_WRITE
;
684 * struct createargs {
689 static void nfs2_xdr_enc_createargs(struct rpc_rqst
*req
,
690 struct xdr_stream
*xdr
,
693 const struct nfs_createargs
*args
= data
;
695 encode_diropargs(xdr
, args
->fh
, args
->name
, args
->len
);
696 encode_sattr(xdr
, args
->sattr
, rpc_rqst_userns(req
));
699 static void nfs2_xdr_enc_removeargs(struct rpc_rqst
*req
,
700 struct xdr_stream
*xdr
,
703 const struct nfs_removeargs
*args
= data
;
705 encode_diropargs(xdr
, args
->fh
, args
->name
.name
, args
->name
.len
);
711 * struct renameargs {
716 static void nfs2_xdr_enc_renameargs(struct rpc_rqst
*req
,
717 struct xdr_stream
*xdr
,
720 const struct nfs_renameargs
*args
= data
;
721 const struct qstr
*old
= args
->old_name
;
722 const struct qstr
*new = args
->new_name
;
724 encode_diropargs(xdr
, args
->old_dir
, old
->name
, old
->len
);
725 encode_diropargs(xdr
, args
->new_dir
, new->name
, new->len
);
736 static void nfs2_xdr_enc_linkargs(struct rpc_rqst
*req
,
737 struct xdr_stream
*xdr
,
740 const struct nfs_linkargs
*args
= data
;
742 encode_fhandle(xdr
, args
->fromfh
);
743 encode_diropargs(xdr
, args
->tofh
, args
->toname
, args
->tolen
);
747 * 2.2.14. symlinkargs
749 * struct symlinkargs {
755 static void nfs2_xdr_enc_symlinkargs(struct rpc_rqst
*req
,
756 struct xdr_stream
*xdr
,
759 const struct nfs_symlinkargs
*args
= data
;
761 encode_diropargs(xdr
, args
->fromfh
, args
->fromname
, args
->fromlen
);
762 encode_path(xdr
, args
->pages
, args
->pathlen
);
763 encode_sattr(xdr
, args
->sattr
, rpc_rqst_userns(req
));
767 * 2.2.17. readdirargs
769 * struct readdirargs {
775 static void encode_readdirargs(struct xdr_stream
*xdr
,
776 const struct nfs_readdirargs
*args
)
780 encode_fhandle(xdr
, args
->fh
);
782 p
= xdr_reserve_space(xdr
, 4 + 4);
783 *p
++ = cpu_to_be32(args
->cookie
);
784 *p
= cpu_to_be32(args
->count
);
787 static void nfs2_xdr_enc_readdirargs(struct rpc_rqst
*req
,
788 struct xdr_stream
*xdr
,
791 const struct nfs_readdirargs
*args
= data
;
793 encode_readdirargs(xdr
, args
);
794 rpc_prepare_reply_pages(req
, args
->pages
, 0,
795 args
->count
, NFS_readdirres_sz
);
799 * NFSv2 XDR decode functions
801 * NFSv2 result types are defined in section 2.2 of RFC 1094:
802 * "NFS: Network File System Protocol Specification".
805 static int nfs2_xdr_dec_stat(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
808 enum nfs_stat status
;
811 error
= decode_stat(xdr
, &status
);
814 if (status
!= NFS_OK
)
819 return nfs_stat_to_errno(status
);
822 static int nfs2_xdr_dec_attrstat(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
825 return decode_attrstat(xdr
, result
, NULL
, rpc_rqst_userns(req
));
828 static int nfs2_xdr_dec_diropres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
831 return decode_diropres(xdr
, result
, rpc_rqst_userns(req
));
837 * union readlinkres switch (stat status) {
844 static int nfs2_xdr_dec_readlinkres(struct rpc_rqst
*req
,
845 struct xdr_stream
*xdr
, void *__unused
)
847 enum nfs_stat status
;
850 error
= decode_stat(xdr
, &status
);
853 if (status
!= NFS_OK
)
855 error
= decode_path(xdr
);
859 return nfs_stat_to_errno(status
);
865 * union readres switch (stat status) {
873 static int nfs2_xdr_dec_readres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
876 struct nfs_pgio_res
*result
= data
;
877 enum nfs_stat status
;
880 error
= decode_stat(xdr
, &status
);
883 result
->op_status
= status
;
884 if (status
!= NFS_OK
)
886 error
= decode_fattr(xdr
, result
->fattr
, rpc_rqst_userns(req
));
889 error
= decode_nfsdata(xdr
, result
);
893 return nfs_stat_to_errno(status
);
896 static int nfs2_xdr_dec_writeres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
899 struct nfs_pgio_res
*result
= data
;
901 /* All NFSv2 writes are "file sync" writes */
902 result
->verf
->committed
= NFS_FILE_SYNC
;
903 return decode_attrstat(xdr
, result
->fattr
, &result
->op_status
,
904 rpc_rqst_userns(req
));
908 * nfs2_decode_dirent - Decode a single NFSv2 directory entry stored in
909 * the local page cache.
910 * @xdr: XDR stream where entry resides
911 * @entry: buffer to fill in with entry data
912 * @plus: boolean indicating whether this should be a readdirplus entry
914 * Returns zero if successful, otherwise a negative errno value is
917 * This function is not invoked during READDIR reply decoding, but
918 * rather whenever an application invokes the getdents(2) system call
919 * on a directory already in our cache.
930 int nfs2_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
936 p
= xdr_inline_decode(xdr
, 4);
939 if (*p
++ == xdr_zero
) {
940 p
= xdr_inline_decode(xdr
, 4);
943 if (*p
++ == xdr_zero
)
949 p
= xdr_inline_decode(xdr
, 4);
952 entry
->ino
= be32_to_cpup(p
);
954 error
= decode_filename_inline(xdr
, &entry
->name
, &entry
->len
);
959 * The type (size and byte order) of nfscookie isn't defined in
960 * RFC 1094. This implementation assumes that it's an XDR uint32.
962 entry
->prev_cookie
= entry
->cookie
;
963 p
= xdr_inline_decode(xdr
, 4);
966 entry
->cookie
= be32_to_cpup(p
);
968 entry
->d_type
= DT_UNKNOWN
;
976 * union readdirres switch (stat status) {
986 * Read the directory contents into the page cache, but don't
987 * touch them. The actual decoding is done by nfs2_decode_dirent()
988 * during subsequent nfs_readdir() calls.
990 static int decode_readdirok(struct xdr_stream
*xdr
)
992 return xdr_read_pages(xdr
, xdr
->buf
->page_len
);
995 static int nfs2_xdr_dec_readdirres(struct rpc_rqst
*req
,
996 struct xdr_stream
*xdr
, void *__unused
)
998 enum nfs_stat status
;
1001 error
= decode_stat(xdr
, &status
);
1002 if (unlikely(error
))
1004 if (status
!= NFS_OK
)
1006 error
= decode_readdirok(xdr
);
1010 return nfs_stat_to_errno(status
);
1016 * union statfsres (stat status) {
1029 static int decode_info(struct xdr_stream
*xdr
, struct nfs2_fsstat
*result
)
1033 p
= xdr_inline_decode(xdr
, NFS_info_sz
<< 2);
1036 result
->tsize
= be32_to_cpup(p
++);
1037 result
->bsize
= be32_to_cpup(p
++);
1038 result
->blocks
= be32_to_cpup(p
++);
1039 result
->bfree
= be32_to_cpup(p
++);
1040 result
->bavail
= be32_to_cpup(p
);
1044 static int nfs2_xdr_dec_statfsres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
1047 enum nfs_stat status
;
1050 error
= decode_stat(xdr
, &status
);
1051 if (unlikely(error
))
1053 if (status
!= NFS_OK
)
1055 error
= decode_info(xdr
, result
);
1059 return nfs_stat_to_errno(status
);
1064 * We need to translate between nfs status return values and
1065 * the local errno values which may not be the same.
1067 static const struct {
1072 { NFSERR_PERM
, -EPERM
},
1073 { NFSERR_NOENT
, -ENOENT
},
1074 { NFSERR_IO
, -errno_NFSERR_IO
},
1075 { NFSERR_NXIO
, -ENXIO
},
1076 /* { NFSERR_EAGAIN, -EAGAIN }, */
1077 { NFSERR_ACCES
, -EACCES
},
1078 { NFSERR_EXIST
, -EEXIST
},
1079 { NFSERR_XDEV
, -EXDEV
},
1080 { NFSERR_NODEV
, -ENODEV
},
1081 { NFSERR_NOTDIR
, -ENOTDIR
},
1082 { NFSERR_ISDIR
, -EISDIR
},
1083 { NFSERR_INVAL
, -EINVAL
},
1084 { NFSERR_FBIG
, -EFBIG
},
1085 { NFSERR_NOSPC
, -ENOSPC
},
1086 { NFSERR_ROFS
, -EROFS
},
1087 { NFSERR_MLINK
, -EMLINK
},
1088 { NFSERR_NAMETOOLONG
, -ENAMETOOLONG
},
1089 { NFSERR_NOTEMPTY
, -ENOTEMPTY
},
1090 { NFSERR_DQUOT
, -EDQUOT
},
1091 { NFSERR_STALE
, -ESTALE
},
1092 { NFSERR_REMOTE
, -EREMOTE
},
1094 { NFSERR_WFLUSH
, -EWFLUSH
},
1096 { NFSERR_BADHANDLE
, -EBADHANDLE
},
1097 { NFSERR_NOT_SYNC
, -ENOTSYNC
},
1098 { NFSERR_BAD_COOKIE
, -EBADCOOKIE
},
1099 { NFSERR_NOTSUPP
, -ENOTSUPP
},
1100 { NFSERR_TOOSMALL
, -ETOOSMALL
},
1101 { NFSERR_SERVERFAULT
, -EREMOTEIO
},
1102 { NFSERR_BADTYPE
, -EBADTYPE
},
1103 { NFSERR_JUKEBOX
, -EJUKEBOX
},
1108 * nfs_stat_to_errno - convert an NFS status code to a local errno
1109 * @status: NFS status code to convert
1111 * Returns a local errno value, or -EIO if the NFS status code is
1112 * not recognized. This function is used jointly by NFSv2 and NFSv3.
1114 static int nfs_stat_to_errno(enum nfs_stat status
)
1118 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
1119 if (nfs_errtbl
[i
].stat
== (int)status
)
1120 return nfs_errtbl
[i
].errno
;
1122 dprintk("NFS: Unrecognized nfs status value: %u\n", status
);
1123 return nfs_errtbl
[i
].errno
;
1126 #define PROC(proc, argtype, restype, timer) \
1127 [NFSPROC_##proc] = { \
1128 .p_proc = NFSPROC_##proc, \
1129 .p_encode = nfs2_xdr_enc_##argtype, \
1130 .p_decode = nfs2_xdr_dec_##restype, \
1131 .p_arglen = NFS_##argtype##_sz, \
1132 .p_replen = NFS_##restype##_sz, \
1134 .p_statidx = NFSPROC_##proc, \
1137 const struct rpc_procinfo nfs_procedures
[] = {
1138 PROC(GETATTR
, fhandle
, attrstat
, 1),
1139 PROC(SETATTR
, sattrargs
, attrstat
, 0),
1140 PROC(LOOKUP
, diropargs
, diropres
, 2),
1141 PROC(READLINK
, readlinkargs
, readlinkres
, 3),
1142 PROC(READ
, readargs
, readres
, 3),
1143 PROC(WRITE
, writeargs
, writeres
, 4),
1144 PROC(CREATE
, createargs
, diropres
, 0),
1145 PROC(REMOVE
, removeargs
, stat
, 0),
1146 PROC(RENAME
, renameargs
, stat
, 0),
1147 PROC(LINK
, linkargs
, stat
, 0),
1148 PROC(SYMLINK
, symlinkargs
, stat
, 0),
1149 PROC(MKDIR
, createargs
, diropres
, 0),
1150 PROC(RMDIR
, diropargs
, stat
, 0),
1151 PROC(READDIR
, readdirargs
, readdirres
, 3),
1152 PROC(STATFS
, fhandle
, statfsres
, 0),
1155 static unsigned int nfs_version2_counts
[ARRAY_SIZE(nfs_procedures
)];
1156 const struct rpc_version nfs_version2
= {
1158 .nrprocs
= ARRAY_SIZE(nfs_procedures
),
1159 .procs
= nfs_procedures
,
1160 .counts
= nfs_version2_counts
,