2 * linux/fs/nfs/nfs2xdr.c
4 * XDR functions to encode/decode NFS RPC arguments and results.
6 * Copyright (C) 1992, 1993, 1994 Rick Sladkey
7 * Copyright (C) 1996 Olaf Kirch
8 * 04 Aug 1998 Ion Badulescu <ionut@cs.columbia.edu>
9 * FIFO's need special handling in NFSv2
12 #include <linux/param.h>
13 #include <linux/time.h>
15 #include <linux/errno.h>
16 #include <linux/string.h>
18 #include <linux/pagemap.h>
19 #include <linux/proc_fs.h>
20 #include <linux/sunrpc/clnt.h>
21 #include <linux/nfs.h>
22 #include <linux/nfs2.h>
23 #include <linux/nfs_fs.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 NFS_fhandle_sz (8)
36 #define NFS_sattr_sz (8)
37 #define NFS_filename_sz (1+(NFS2_MAXNAMLEN>>2))
38 #define NFS_path_sz (1+(NFS2_MAXPATHLEN>>2))
39 #define NFS_fattr_sz (17)
40 #define NFS_info_sz (5)
41 #define NFS_entry_sz (NFS_filename_sz+3)
43 #define NFS_diropargs_sz (NFS_fhandle_sz+NFS_filename_sz)
44 #define NFS_removeargs_sz (NFS_fhandle_sz+NFS_filename_sz)
45 #define NFS_sattrargs_sz (NFS_fhandle_sz+NFS_sattr_sz)
46 #define NFS_readlinkargs_sz (NFS_fhandle_sz)
47 #define NFS_readargs_sz (NFS_fhandle_sz+3)
48 #define NFS_writeargs_sz (NFS_fhandle_sz+4)
49 #define NFS_createargs_sz (NFS_diropargs_sz+NFS_sattr_sz)
50 #define NFS_renameargs_sz (NFS_diropargs_sz+NFS_diropargs_sz)
51 #define NFS_linkargs_sz (NFS_fhandle_sz+NFS_diropargs_sz)
52 #define NFS_symlinkargs_sz (NFS_diropargs_sz+1+NFS_sattr_sz)
53 #define NFS_readdirargs_sz (NFS_fhandle_sz+2)
55 #define NFS_attrstat_sz (1+NFS_fattr_sz)
56 #define NFS_diropres_sz (1+NFS_fhandle_sz+NFS_fattr_sz)
57 #define NFS_readlinkres_sz (2)
58 #define NFS_readres_sz (1+NFS_fattr_sz+1)
59 #define NFS_writeres_sz (NFS_attrstat_sz)
60 #define NFS_stat_sz (1)
61 #define NFS_readdirres_sz (1)
62 #define NFS_statfsres_sz (1+NFS_info_sz)
64 static int nfs_stat_to_errno(enum nfs_stat
);
67 * While encoding arguments, set up the reply buffer in advance to
68 * receive reply data directly into the page cache.
70 static void prepare_reply_buffer(struct rpc_rqst
*req
, struct page
**pages
,
71 unsigned int base
, unsigned int len
,
74 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
77 replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ bufsize
;
78 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, pages
, base
, len
);
82 * Handle decode buffer overflows out-of-line.
84 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
86 dprintk("NFS: %s prematurely hit the end of our receive buffer. "
87 "Remaining buffer length is %tu words.\n",
88 func
, xdr
->end
- xdr
->p
);
93 * Encode/decode NFSv2 basic data types
95 * Basic NFSv2 data types are defined in section 2.3 of RFC 1094:
96 * "NFS: Network File System Protocol Specification".
98 * Not all basic data types have their own encoding and decoding
99 * functions. For run-time efficiency, some data types are encoded
104 * typedef opaque nfsdata<>;
106 static int decode_nfsdata(struct xdr_stream
*xdr
, struct nfs_pgio_res
*result
)
111 p
= xdr_inline_decode(xdr
, 4);
112 if (unlikely(p
== NULL
))
114 count
= be32_to_cpup(p
);
115 recvd
= xdr_read_pages(xdr
, count
);
116 if (unlikely(count
> recvd
))
119 result
->eof
= 0; /* NFSv2 does not pass EOF flag on the wire. */
120 result
->count
= count
;
123 dprintk("NFS: server cheating in read result: "
124 "count %u > recvd %u\n", count
, recvd
);
128 print_overflow_msg(__func__
, xdr
);
142 * NFSERR_NOTDIR = 20,
147 * NFSERR_NAMETOOLONG = 63,
148 * NFSERR_NOTEMPTY = 66,
154 static int decode_stat(struct xdr_stream
*xdr
, enum nfs_stat
*status
)
158 p
= xdr_inline_decode(xdr
, 4);
159 if (unlikely(p
== NULL
))
161 *status
= be32_to_cpup(p
);
164 print_overflow_msg(__func__
, xdr
);
181 static __be32
*xdr_decode_ftype(__be32
*p
, u32
*type
)
183 *type
= be32_to_cpup(p
++);
184 if (unlikely(*type
> NF2FIFO
))
192 * typedef opaque fhandle[FHSIZE];
194 static void encode_fhandle(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
)
198 p
= xdr_reserve_space(xdr
, NFS2_FHSIZE
);
199 memcpy(p
, fh
->data
, NFS2_FHSIZE
);
202 static int decode_fhandle(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
206 p
= xdr_inline_decode(xdr
, NFS2_FHSIZE
);
207 if (unlikely(p
== NULL
))
209 fh
->size
= NFS2_FHSIZE
;
210 memcpy(fh
->data
, p
, NFS2_FHSIZE
);
213 print_overflow_msg(__func__
, xdr
);
221 * unsigned int seconds;
222 * unsigned int useconds;
225 static __be32
*xdr_encode_time(__be32
*p
, const struct timespec
*timep
)
227 *p
++ = cpu_to_be32(timep
->tv_sec
);
228 if (timep
->tv_nsec
!= 0)
229 *p
++ = cpu_to_be32(timep
->tv_nsec
/ NSEC_PER_USEC
);
231 *p
++ = cpu_to_be32(0);
236 * Passing the invalid value useconds=1000000 is a Sun convention for
237 * "set to current server time". It's needed to make permissions checks
238 * for the "touch" program across v2 mounts to Solaris and Irix servers
239 * work correctly. See description of sattr in section 6.1 of "NFS
240 * Illustrated" by Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5.
242 static __be32
*xdr_encode_current_server_time(__be32
*p
,
243 const struct timespec
*timep
)
245 *p
++ = cpu_to_be32(timep
->tv_sec
);
246 *p
++ = cpu_to_be32(1000000);
250 static __be32
*xdr_decode_time(__be32
*p
, struct timespec
*timep
)
252 timep
->tv_sec
= be32_to_cpup(p
++);
253 timep
->tv_nsec
= be32_to_cpup(p
++) * NSEC_PER_USEC
;
263 * unsigned int nlink;
267 * unsigned int blocksize;
269 * unsigned int blocks;
271 * unsigned int fileid;
278 static int decode_fattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
)
283 p
= xdr_inline_decode(xdr
, NFS_fattr_sz
<< 2);
284 if (unlikely(p
== NULL
))
287 fattr
->valid
|= NFS_ATTR_FATTR_V2
;
289 p
= xdr_decode_ftype(p
, &type
);
291 fattr
->mode
= be32_to_cpup(p
++);
292 fattr
->nlink
= be32_to_cpup(p
++);
293 fattr
->uid
= make_kuid(&init_user_ns
, be32_to_cpup(p
++));
294 if (!uid_valid(fattr
->uid
))
296 fattr
->gid
= make_kgid(&init_user_ns
, be32_to_cpup(p
++));
297 if (!gid_valid(fattr
->gid
))
300 fattr
->size
= be32_to_cpup(p
++);
301 fattr
->du
.nfs2
.blocksize
= be32_to_cpup(p
++);
303 rdev
= be32_to_cpup(p
++);
304 fattr
->rdev
= new_decode_dev(rdev
);
305 if (type
== (u32
)NFCHR
&& rdev
== (u32
)NFS2_FIFO_DEV
) {
306 fattr
->mode
= (fattr
->mode
& ~S_IFMT
) | S_IFIFO
;
310 fattr
->du
.nfs2
.blocks
= be32_to_cpup(p
++);
311 fattr
->fsid
.major
= be32_to_cpup(p
++);
312 fattr
->fsid
.minor
= 0;
313 fattr
->fileid
= be32_to_cpup(p
++);
315 p
= xdr_decode_time(p
, &fattr
->atime
);
316 p
= xdr_decode_time(p
, &fattr
->mtime
);
317 xdr_decode_time(p
, &fattr
->ctime
);
318 fattr
->change_attr
= nfs_timespec_to_change_attr(&fattr
->ctime
);
322 dprintk("NFS: returned invalid uid\n");
325 dprintk("NFS: returned invalid gid\n");
328 print_overflow_msg(__func__
, xdr
);
345 #define NFS2_SATTR_NOT_SET (0xffffffff)
347 static __be32
*xdr_time_not_set(__be32
*p
)
349 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
350 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
354 static void encode_sattr(struct xdr_stream
*xdr
, const struct iattr
*attr
)
358 p
= xdr_reserve_space(xdr
, NFS_sattr_sz
<< 2);
360 if (attr
->ia_valid
& ATTR_MODE
)
361 *p
++ = cpu_to_be32(attr
->ia_mode
);
363 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
364 if (attr
->ia_valid
& ATTR_UID
)
365 *p
++ = cpu_to_be32(from_kuid(&init_user_ns
, attr
->ia_uid
));
367 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
368 if (attr
->ia_valid
& ATTR_GID
)
369 *p
++ = cpu_to_be32(from_kgid(&init_user_ns
, attr
->ia_gid
));
371 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
372 if (attr
->ia_valid
& ATTR_SIZE
)
373 *p
++ = cpu_to_be32((u32
)attr
->ia_size
);
375 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
377 if (attr
->ia_valid
& ATTR_ATIME_SET
)
378 p
= xdr_encode_time(p
, &attr
->ia_atime
);
379 else if (attr
->ia_valid
& ATTR_ATIME
)
380 p
= xdr_encode_current_server_time(p
, &attr
->ia_atime
);
382 p
= xdr_time_not_set(p
);
383 if (attr
->ia_valid
& ATTR_MTIME_SET
)
384 xdr_encode_time(p
, &attr
->ia_mtime
);
385 else if (attr
->ia_valid
& ATTR_MTIME
)
386 xdr_encode_current_server_time(p
, &attr
->ia_mtime
);
394 * typedef string filename<MAXNAMLEN>;
396 static void encode_filename(struct xdr_stream
*xdr
,
397 const char *name
, u32 length
)
401 WARN_ON_ONCE(length
> NFS2_MAXNAMLEN
);
402 p
= xdr_reserve_space(xdr
, 4 + length
);
403 xdr_encode_opaque(p
, name
, length
);
406 static int decode_filename_inline(struct xdr_stream
*xdr
,
407 const char **name
, u32
*length
)
412 p
= xdr_inline_decode(xdr
, 4);
413 if (unlikely(p
== NULL
))
415 count
= be32_to_cpup(p
);
416 if (count
> NFS3_MAXNAMLEN
)
417 goto out_nametoolong
;
418 p
= xdr_inline_decode(xdr
, count
);
419 if (unlikely(p
== NULL
))
421 *name
= (const char *)p
;
425 dprintk("NFS: returned filename too long: %u\n", count
);
426 return -ENAMETOOLONG
;
428 print_overflow_msg(__func__
, xdr
);
435 * typedef string path<MAXPATHLEN>;
437 static void encode_path(struct xdr_stream
*xdr
, struct page
**pages
, u32 length
)
441 p
= xdr_reserve_space(xdr
, 4);
442 *p
= cpu_to_be32(length
);
443 xdr_write_pages(xdr
, pages
, 0, length
);
446 static int decode_path(struct xdr_stream
*xdr
)
451 p
= xdr_inline_decode(xdr
, 4);
452 if (unlikely(p
== NULL
))
454 length
= be32_to_cpup(p
);
455 if (unlikely(length
>= xdr
->buf
->page_len
|| length
> NFS_MAXPATHLEN
))
457 recvd
= xdr_read_pages(xdr
, length
);
458 if (unlikely(length
> recvd
))
460 xdr_terminate_string(xdr
->buf
, length
);
463 dprintk("NFS: returned pathname too long: %u\n", length
);
464 return -ENAMETOOLONG
;
466 dprintk("NFS: server cheating in pathname result: "
467 "length %u > received %u\n", length
, recvd
);
470 print_overflow_msg(__func__
, xdr
);
477 * union attrstat switch (stat status) {
484 static int decode_attrstat(struct xdr_stream
*xdr
, struct nfs_fattr
*result
,
487 enum nfs_stat status
;
490 error
= decode_stat(xdr
, &status
);
495 if (status
!= NFS_OK
)
497 error
= decode_fattr(xdr
, result
);
501 return nfs_stat_to_errno(status
);
512 static void encode_diropargs(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
,
513 const char *name
, u32 length
)
515 encode_fhandle(xdr
, fh
);
516 encode_filename(xdr
, name
, length
);
522 * union diropres switch (stat status) {
532 static int decode_diropok(struct xdr_stream
*xdr
, struct nfs_diropok
*result
)
536 error
= decode_fhandle(xdr
, result
->fh
);
539 error
= decode_fattr(xdr
, result
->fattr
);
544 static int decode_diropres(struct xdr_stream
*xdr
, struct nfs_diropok
*result
)
546 enum nfs_stat status
;
549 error
= decode_stat(xdr
, &status
);
552 if (status
!= NFS_OK
)
554 error
= decode_diropok(xdr
, result
);
558 return nfs_stat_to_errno(status
);
563 * NFSv2 XDR encode functions
565 * NFSv2 argument types are defined in section 2.2 of RFC 1094:
566 * "NFS: Network File System Protocol Specification".
569 static void nfs2_xdr_enc_fhandle(struct rpc_rqst
*req
,
570 struct xdr_stream
*xdr
,
573 const struct nfs_fh
*fh
= data
;
575 encode_fhandle(xdr
, fh
);
586 static void nfs2_xdr_enc_sattrargs(struct rpc_rqst
*req
,
587 struct xdr_stream
*xdr
,
590 const struct nfs_sattrargs
*args
= data
;
592 encode_fhandle(xdr
, args
->fh
);
593 encode_sattr(xdr
, args
->sattr
);
596 static void nfs2_xdr_enc_diropargs(struct rpc_rqst
*req
,
597 struct xdr_stream
*xdr
,
600 const struct nfs_diropargs
*args
= data
;
602 encode_diropargs(xdr
, args
->fh
, args
->name
, args
->len
);
605 static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst
*req
,
606 struct xdr_stream
*xdr
,
609 const struct nfs_readlinkargs
*args
= data
;
611 encode_fhandle(xdr
, args
->fh
);
612 prepare_reply_buffer(req
, args
->pages
, args
->pgbase
,
613 args
->pglen
, NFS_readlinkres_sz
);
623 * unsigned totalcount;
626 static void encode_readargs(struct xdr_stream
*xdr
,
627 const struct nfs_pgio_args
*args
)
629 u32 offset
= args
->offset
;
630 u32 count
= args
->count
;
633 encode_fhandle(xdr
, args
->fh
);
635 p
= xdr_reserve_space(xdr
, 4 + 4 + 4);
636 *p
++ = cpu_to_be32(offset
);
637 *p
++ = cpu_to_be32(count
);
638 *p
= cpu_to_be32(count
);
641 static void nfs2_xdr_enc_readargs(struct rpc_rqst
*req
,
642 struct xdr_stream
*xdr
,
645 const struct nfs_pgio_args
*args
= data
;
647 encode_readargs(xdr
, args
);
648 prepare_reply_buffer(req
, args
->pages
, args
->pgbase
,
649 args
->count
, NFS_readres_sz
);
650 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
658 * unsigned beginoffset;
660 * unsigned totalcount;
664 static void encode_writeargs(struct xdr_stream
*xdr
,
665 const struct nfs_pgio_args
*args
)
667 u32 offset
= args
->offset
;
668 u32 count
= args
->count
;
671 encode_fhandle(xdr
, args
->fh
);
673 p
= xdr_reserve_space(xdr
, 4 + 4 + 4 + 4);
674 *p
++ = cpu_to_be32(offset
);
675 *p
++ = cpu_to_be32(offset
);
676 *p
++ = cpu_to_be32(count
);
679 *p
= cpu_to_be32(count
);
680 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, count
);
683 static void nfs2_xdr_enc_writeargs(struct rpc_rqst
*req
,
684 struct xdr_stream
*xdr
,
687 const struct nfs_pgio_args
*args
= data
;
689 encode_writeargs(xdr
, args
);
690 xdr
->buf
->flags
|= XDRBUF_WRITE
;
696 * struct createargs {
701 static void nfs2_xdr_enc_createargs(struct rpc_rqst
*req
,
702 struct xdr_stream
*xdr
,
705 const struct nfs_createargs
*args
= data
;
707 encode_diropargs(xdr
, args
->fh
, args
->name
, args
->len
);
708 encode_sattr(xdr
, args
->sattr
);
711 static void nfs2_xdr_enc_removeargs(struct rpc_rqst
*req
,
712 struct xdr_stream
*xdr
,
715 const struct nfs_removeargs
*args
= data
;
717 encode_diropargs(xdr
, args
->fh
, args
->name
.name
, args
->name
.len
);
723 * struct renameargs {
728 static void nfs2_xdr_enc_renameargs(struct rpc_rqst
*req
,
729 struct xdr_stream
*xdr
,
732 const struct nfs_renameargs
*args
= data
;
733 const struct qstr
*old
= args
->old_name
;
734 const struct qstr
*new = args
->new_name
;
736 encode_diropargs(xdr
, args
->old_dir
, old
->name
, old
->len
);
737 encode_diropargs(xdr
, args
->new_dir
, new->name
, new->len
);
748 static void nfs2_xdr_enc_linkargs(struct rpc_rqst
*req
,
749 struct xdr_stream
*xdr
,
752 const struct nfs_linkargs
*args
= data
;
754 encode_fhandle(xdr
, args
->fromfh
);
755 encode_diropargs(xdr
, args
->tofh
, args
->toname
, args
->tolen
);
759 * 2.2.14. symlinkargs
761 * struct symlinkargs {
767 static void nfs2_xdr_enc_symlinkargs(struct rpc_rqst
*req
,
768 struct xdr_stream
*xdr
,
771 const struct nfs_symlinkargs
*args
= data
;
773 encode_diropargs(xdr
, args
->fromfh
, args
->fromname
, args
->fromlen
);
774 encode_path(xdr
, args
->pages
, args
->pathlen
);
775 encode_sattr(xdr
, args
->sattr
);
779 * 2.2.17. readdirargs
781 * struct readdirargs {
787 static void encode_readdirargs(struct xdr_stream
*xdr
,
788 const struct nfs_readdirargs
*args
)
792 encode_fhandle(xdr
, args
->fh
);
794 p
= xdr_reserve_space(xdr
, 4 + 4);
795 *p
++ = cpu_to_be32(args
->cookie
);
796 *p
= cpu_to_be32(args
->count
);
799 static void nfs2_xdr_enc_readdirargs(struct rpc_rqst
*req
,
800 struct xdr_stream
*xdr
,
803 const struct nfs_readdirargs
*args
= data
;
805 encode_readdirargs(xdr
, args
);
806 prepare_reply_buffer(req
, args
->pages
, 0,
807 args
->count
, NFS_readdirres_sz
);
811 * NFSv2 XDR decode functions
813 * NFSv2 result types are defined in section 2.2 of RFC 1094:
814 * "NFS: Network File System Protocol Specification".
817 static int nfs2_xdr_dec_stat(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
820 enum nfs_stat status
;
823 error
= decode_stat(xdr
, &status
);
826 if (status
!= NFS_OK
)
831 return nfs_stat_to_errno(status
);
834 static int nfs2_xdr_dec_attrstat(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
837 return decode_attrstat(xdr
, result
, NULL
);
840 static int nfs2_xdr_dec_diropres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
843 return decode_diropres(xdr
, result
);
849 * union readlinkres switch (stat status) {
856 static int nfs2_xdr_dec_readlinkres(struct rpc_rqst
*req
,
857 struct xdr_stream
*xdr
, void *__unused
)
859 enum nfs_stat status
;
862 error
= decode_stat(xdr
, &status
);
865 if (status
!= NFS_OK
)
867 error
= decode_path(xdr
);
871 return nfs_stat_to_errno(status
);
877 * union readres switch (stat status) {
885 static int nfs2_xdr_dec_readres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
888 struct nfs_pgio_res
*result
= data
;
889 enum nfs_stat status
;
892 error
= decode_stat(xdr
, &status
);
895 result
->op_status
= status
;
896 if (status
!= NFS_OK
)
898 error
= decode_fattr(xdr
, result
->fattr
);
901 error
= decode_nfsdata(xdr
, result
);
905 return nfs_stat_to_errno(status
);
908 static int nfs2_xdr_dec_writeres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
911 struct nfs_pgio_res
*result
= data
;
913 /* All NFSv2 writes are "file sync" writes */
914 result
->verf
->committed
= NFS_FILE_SYNC
;
915 return decode_attrstat(xdr
, result
->fattr
, &result
->op_status
);
919 * nfs2_decode_dirent - Decode a single NFSv2 directory entry stored in
920 * the local page cache.
921 * @xdr: XDR stream where entry resides
922 * @entry: buffer to fill in with entry data
923 * @plus: boolean indicating whether this should be a readdirplus entry
925 * Returns zero if successful, otherwise a negative errno value is
928 * This function is not invoked during READDIR reply decoding, but
929 * rather whenever an application invokes the getdents(2) system call
930 * on a directory already in our cache.
941 int nfs2_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
947 p
= xdr_inline_decode(xdr
, 4);
948 if (unlikely(p
== NULL
))
950 if (*p
++ == xdr_zero
) {
951 p
= xdr_inline_decode(xdr
, 4);
952 if (unlikely(p
== NULL
))
954 if (*p
++ == xdr_zero
)
960 p
= xdr_inline_decode(xdr
, 4);
961 if (unlikely(p
== NULL
))
963 entry
->ino
= be32_to_cpup(p
);
965 error
= decode_filename_inline(xdr
, &entry
->name
, &entry
->len
);
970 * The type (size and byte order) of nfscookie isn't defined in
971 * RFC 1094. This implementation assumes that it's an XDR uint32.
973 entry
->prev_cookie
= entry
->cookie
;
974 p
= xdr_inline_decode(xdr
, 4);
975 if (unlikely(p
== NULL
))
977 entry
->cookie
= be32_to_cpup(p
);
979 entry
->d_type
= DT_UNKNOWN
;
984 print_overflow_msg(__func__
, xdr
);
991 * union readdirres switch (stat status) {
1001 * Read the directory contents into the page cache, but don't
1002 * touch them. The actual decoding is done by nfs2_decode_dirent()
1003 * during subsequent nfs_readdir() calls.
1005 static int decode_readdirok(struct xdr_stream
*xdr
)
1007 return xdr_read_pages(xdr
, xdr
->buf
->page_len
);
1010 static int nfs2_xdr_dec_readdirres(struct rpc_rqst
*req
,
1011 struct xdr_stream
*xdr
, void *__unused
)
1013 enum nfs_stat status
;
1016 error
= decode_stat(xdr
, &status
);
1017 if (unlikely(error
))
1019 if (status
!= NFS_OK
)
1021 error
= decode_readdirok(xdr
);
1025 return nfs_stat_to_errno(status
);
1031 * union statfsres (stat status) {
1044 static int decode_info(struct xdr_stream
*xdr
, struct nfs2_fsstat
*result
)
1048 p
= xdr_inline_decode(xdr
, NFS_info_sz
<< 2);
1049 if (unlikely(p
== NULL
))
1051 result
->tsize
= be32_to_cpup(p
++);
1052 result
->bsize
= be32_to_cpup(p
++);
1053 result
->blocks
= be32_to_cpup(p
++);
1054 result
->bfree
= be32_to_cpup(p
++);
1055 result
->bavail
= be32_to_cpup(p
);
1058 print_overflow_msg(__func__
, xdr
);
1062 static int nfs2_xdr_dec_statfsres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
1065 enum nfs_stat status
;
1068 error
= decode_stat(xdr
, &status
);
1069 if (unlikely(error
))
1071 if (status
!= NFS_OK
)
1073 error
= decode_info(xdr
, result
);
1077 return nfs_stat_to_errno(status
);
1082 * We need to translate between nfs status return values and
1083 * the local errno values which may not be the same.
1085 static const struct {
1090 { NFSERR_PERM
, -EPERM
},
1091 { NFSERR_NOENT
, -ENOENT
},
1092 { NFSERR_IO
, -errno_NFSERR_IO
},
1093 { NFSERR_NXIO
, -ENXIO
},
1094 /* { NFSERR_EAGAIN, -EAGAIN }, */
1095 { NFSERR_ACCES
, -EACCES
},
1096 { NFSERR_EXIST
, -EEXIST
},
1097 { NFSERR_XDEV
, -EXDEV
},
1098 { NFSERR_NODEV
, -ENODEV
},
1099 { NFSERR_NOTDIR
, -ENOTDIR
},
1100 { NFSERR_ISDIR
, -EISDIR
},
1101 { NFSERR_INVAL
, -EINVAL
},
1102 { NFSERR_FBIG
, -EFBIG
},
1103 { NFSERR_NOSPC
, -ENOSPC
},
1104 { NFSERR_ROFS
, -EROFS
},
1105 { NFSERR_MLINK
, -EMLINK
},
1106 { NFSERR_NAMETOOLONG
, -ENAMETOOLONG
},
1107 { NFSERR_NOTEMPTY
, -ENOTEMPTY
},
1108 { NFSERR_DQUOT
, -EDQUOT
},
1109 { NFSERR_STALE
, -ESTALE
},
1110 { NFSERR_REMOTE
, -EREMOTE
},
1112 { NFSERR_WFLUSH
, -EWFLUSH
},
1114 { NFSERR_BADHANDLE
, -EBADHANDLE
},
1115 { NFSERR_NOT_SYNC
, -ENOTSYNC
},
1116 { NFSERR_BAD_COOKIE
, -EBADCOOKIE
},
1117 { NFSERR_NOTSUPP
, -ENOTSUPP
},
1118 { NFSERR_TOOSMALL
, -ETOOSMALL
},
1119 { NFSERR_SERVERFAULT
, -EREMOTEIO
},
1120 { NFSERR_BADTYPE
, -EBADTYPE
},
1121 { NFSERR_JUKEBOX
, -EJUKEBOX
},
1126 * nfs_stat_to_errno - convert an NFS status code to a local errno
1127 * @status: NFS status code to convert
1129 * Returns a local errno value, or -EIO if the NFS status code is
1130 * not recognized. This function is used jointly by NFSv2 and NFSv3.
1132 static int nfs_stat_to_errno(enum nfs_stat status
)
1136 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
1137 if (nfs_errtbl
[i
].stat
== (int)status
)
1138 return nfs_errtbl
[i
].errno
;
1140 dprintk("NFS: Unrecognized nfs status value: %u\n", status
);
1141 return nfs_errtbl
[i
].errno
;
1144 #define PROC(proc, argtype, restype, timer) \
1145 [NFSPROC_##proc] = { \
1146 .p_proc = NFSPROC_##proc, \
1147 .p_encode = nfs2_xdr_enc_##argtype, \
1148 .p_decode = nfs2_xdr_dec_##restype, \
1149 .p_arglen = NFS_##argtype##_sz, \
1150 .p_replen = NFS_##restype##_sz, \
1152 .p_statidx = NFSPROC_##proc, \
1155 const struct rpc_procinfo nfs_procedures
[] = {
1156 PROC(GETATTR
, fhandle
, attrstat
, 1),
1157 PROC(SETATTR
, sattrargs
, attrstat
, 0),
1158 PROC(LOOKUP
, diropargs
, diropres
, 2),
1159 PROC(READLINK
, readlinkargs
, readlinkres
, 3),
1160 PROC(READ
, readargs
, readres
, 3),
1161 PROC(WRITE
, writeargs
, writeres
, 4),
1162 PROC(CREATE
, createargs
, diropres
, 0),
1163 PROC(REMOVE
, removeargs
, stat
, 0),
1164 PROC(RENAME
, renameargs
, stat
, 0),
1165 PROC(LINK
, linkargs
, stat
, 0),
1166 PROC(SYMLINK
, symlinkargs
, stat
, 0),
1167 PROC(MKDIR
, createargs
, diropres
, 0),
1168 PROC(RMDIR
, diropargs
, stat
, 0),
1169 PROC(READDIR
, readdirargs
, readdirres
, 3),
1170 PROC(STATFS
, fhandle
, statfsres
, 0),
1173 static unsigned int nfs_version2_counts
[ARRAY_SIZE(nfs_procedures
)];
1174 const struct rpc_version nfs_version2
= {
1176 .nrprocs
= ARRAY_SIZE(nfs_procedures
),
1177 .procs
= nfs_procedures
,
1178 .counts
= nfs_version2_counts
,