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)
66 * While encoding arguments, set up the reply buffer in advance to
67 * receive reply data directly into the page cache.
69 static void prepare_reply_buffer(struct rpc_rqst
*req
, struct page
**pages
,
70 unsigned int base
, unsigned int len
,
73 struct rpc_auth
*auth
= req
->rq_cred
->cr_auth
;
76 replen
= RPC_REPHDRSIZE
+ auth
->au_rslack
+ bufsize
;
77 xdr_inline_pages(&req
->rq_rcv_buf
, replen
<< 2, pages
, base
, len
);
81 * Handle decode buffer overflows out-of-line.
83 static void print_overflow_msg(const char *func
, const struct xdr_stream
*xdr
)
85 dprintk("NFS: %s prematurely hit the end of our receive buffer. "
86 "Remaining buffer length is %tu words.\n",
87 func
, xdr
->end
- xdr
->p
);
92 * Encode/decode NFSv2 basic data types
94 * Basic NFSv2 data types are defined in section 2.3 of RFC 1094:
95 * "NFS: Network File System Protocol Specification".
97 * Not all basic data types have their own encoding and decoding
98 * functions. For run-time efficiency, some data types are encoded
103 * typedef opaque nfsdata<>;
105 static int decode_nfsdata(struct xdr_stream
*xdr
, struct nfs_readres
*result
)
111 p
= xdr_inline_decode(xdr
, 4);
112 if (unlikely(p
== NULL
))
114 count
= be32_to_cpup(p
);
115 hdrlen
= (u8
*)xdr
->p
- (u8
*)xdr
->iov
->iov_base
;
116 recvd
= xdr
->buf
->len
- hdrlen
;
117 if (unlikely(count
> recvd
))
120 xdr_read_pages(xdr
, count
);
121 result
->eof
= 0; /* NFSv2 does not pass EOF flag on the wire. */
122 result
->count
= count
;
125 dprintk("NFS: server cheating in read result: "
126 "count %u > recvd %u\n", count
, recvd
);
130 print_overflow_msg(__func__
, xdr
);
144 * NFSERR_NOTDIR = 20,
149 * NFSERR_NAMETOOLONG = 63,
150 * NFSERR_NOTEMPTY = 66,
156 static int decode_stat(struct xdr_stream
*xdr
, enum nfs_stat
*status
)
160 p
= xdr_inline_decode(xdr
, 4);
161 if (unlikely(p
== NULL
))
163 *status
= be32_to_cpup(p
);
166 print_overflow_msg(__func__
, xdr
);
183 static __be32
*xdr_decode_ftype(__be32
*p
, u32
*type
)
185 *type
= be32_to_cpup(p
++);
186 if (unlikely(*type
> NF2FIFO
))
194 * typedef opaque fhandle[FHSIZE];
196 static void encode_fhandle(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
)
200 BUG_ON(fh
->size
!= NFS2_FHSIZE
);
201 p
= xdr_reserve_space(xdr
, NFS2_FHSIZE
);
202 memcpy(p
, fh
->data
, NFS2_FHSIZE
);
205 static int decode_fhandle(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
209 p
= xdr_inline_decode(xdr
, NFS2_FHSIZE
);
210 if (unlikely(p
== NULL
))
212 fh
->size
= NFS2_FHSIZE
;
213 memcpy(fh
->data
, p
, NFS2_FHSIZE
);
216 print_overflow_msg(__func__
, xdr
);
224 * unsigned int seconds;
225 * unsigned int useconds;
228 static __be32
*xdr_encode_time(__be32
*p
, const struct timespec
*timep
)
230 *p
++ = cpu_to_be32(timep
->tv_sec
);
231 if (timep
->tv_nsec
!= 0)
232 *p
++ = cpu_to_be32(timep
->tv_nsec
/ NSEC_PER_USEC
);
234 *p
++ = cpu_to_be32(0);
239 * Passing the invalid value useconds=1000000 is a Sun convention for
240 * "set to current server time". It's needed to make permissions checks
241 * for the "touch" program across v2 mounts to Solaris and Irix servers
242 * work correctly. See description of sattr in section 6.1 of "NFS
243 * Illustrated" by Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5.
245 static __be32
*xdr_encode_current_server_time(__be32
*p
,
246 const struct timespec
*timep
)
248 *p
++ = cpu_to_be32(timep
->tv_sec
);
249 *p
++ = cpu_to_be32(1000000);
253 static __be32
*xdr_decode_time(__be32
*p
, struct timespec
*timep
)
255 timep
->tv_sec
= be32_to_cpup(p
++);
256 timep
->tv_nsec
= be32_to_cpup(p
++) * NSEC_PER_USEC
;
266 * unsigned int nlink;
270 * unsigned int blocksize;
272 * unsigned int blocks;
274 * unsigned int fileid;
281 static int decode_fattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
)
286 p
= xdr_inline_decode(xdr
, NFS_fattr_sz
<< 2);
287 if (unlikely(p
== NULL
))
290 fattr
->valid
|= NFS_ATTR_FATTR_V2
;
292 p
= xdr_decode_ftype(p
, &type
);
294 fattr
->mode
= be32_to_cpup(p
++);
295 fattr
->nlink
= be32_to_cpup(p
++);
296 fattr
->uid
= be32_to_cpup(p
++);
297 fattr
->gid
= be32_to_cpup(p
++);
298 fattr
->size
= be32_to_cpup(p
++);
299 fattr
->du
.nfs2
.blocksize
= be32_to_cpup(p
++);
301 rdev
= be32_to_cpup(p
++);
302 fattr
->rdev
= new_decode_dev(rdev
);
303 if (type
== (u32
)NFCHR
&& rdev
== (u32
)NFS2_FIFO_DEV
) {
304 fattr
->mode
= (fattr
->mode
& ~S_IFMT
) | S_IFIFO
;
308 fattr
->du
.nfs2
.blocks
= be32_to_cpup(p
++);
309 fattr
->fsid
.major
= be32_to_cpup(p
++);
310 fattr
->fsid
.minor
= 0;
311 fattr
->fileid
= be32_to_cpup(p
++);
313 p
= xdr_decode_time(p
, &fattr
->atime
);
314 p
= xdr_decode_time(p
, &fattr
->mtime
);
315 xdr_decode_time(p
, &fattr
->ctime
);
318 print_overflow_msg(__func__
, xdr
);
335 #define NFS2_SATTR_NOT_SET (0xffffffff)
337 static __be32
*xdr_time_not_set(__be32
*p
)
339 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
340 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
344 static void encode_sattr(struct xdr_stream
*xdr
, const struct iattr
*attr
)
348 p
= xdr_reserve_space(xdr
, NFS_sattr_sz
<< 2);
350 if (attr
->ia_valid
& ATTR_MODE
)
351 *p
++ = cpu_to_be32(attr
->ia_mode
);
353 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
354 if (attr
->ia_valid
& ATTR_UID
)
355 *p
++ = cpu_to_be32(attr
->ia_uid
);
357 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
358 if (attr
->ia_valid
& ATTR_GID
)
359 *p
++ = cpu_to_be32(attr
->ia_gid
);
361 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
362 if (attr
->ia_valid
& ATTR_SIZE
)
363 *p
++ = cpu_to_be32((u32
)attr
->ia_size
);
365 *p
++ = cpu_to_be32(NFS2_SATTR_NOT_SET
);
367 if (attr
->ia_valid
& ATTR_ATIME_SET
)
368 p
= xdr_encode_time(p
, &attr
->ia_atime
);
369 else if (attr
->ia_valid
& ATTR_ATIME
)
370 p
= xdr_encode_current_server_time(p
, &attr
->ia_atime
);
372 p
= xdr_time_not_set(p
);
373 if (attr
->ia_valid
& ATTR_MTIME_SET
)
374 xdr_encode_time(p
, &attr
->ia_mtime
);
375 else if (attr
->ia_valid
& ATTR_MTIME
)
376 xdr_encode_current_server_time(p
, &attr
->ia_mtime
);
384 * typedef string filename<MAXNAMLEN>;
386 static void encode_filename(struct xdr_stream
*xdr
,
387 const char *name
, u32 length
)
391 BUG_ON(length
> NFS2_MAXNAMLEN
);
392 p
= xdr_reserve_space(xdr
, 4 + length
);
393 xdr_encode_opaque(p
, name
, length
);
396 static int decode_filename_inline(struct xdr_stream
*xdr
,
397 const char **name
, u32
*length
)
402 p
= xdr_inline_decode(xdr
, 4);
403 if (unlikely(p
== NULL
))
405 count
= be32_to_cpup(p
);
406 if (count
> NFS3_MAXNAMLEN
)
407 goto out_nametoolong
;
408 p
= xdr_inline_decode(xdr
, count
);
409 if (unlikely(p
== NULL
))
411 *name
= (const char *)p
;
415 dprintk("NFS: returned filename too long: %u\n", count
);
416 return -ENAMETOOLONG
;
418 print_overflow_msg(__func__
, xdr
);
425 * typedef string path<MAXPATHLEN>;
427 static void encode_path(struct xdr_stream
*xdr
, struct page
**pages
, u32 length
)
431 BUG_ON(length
> NFS2_MAXPATHLEN
);
432 p
= xdr_reserve_space(xdr
, 4);
433 *p
= cpu_to_be32(length
);
434 xdr_write_pages(xdr
, pages
, 0, length
);
437 static int decode_path(struct xdr_stream
*xdr
)
443 p
= xdr_inline_decode(xdr
, 4);
444 if (unlikely(p
== NULL
))
446 length
= be32_to_cpup(p
);
447 if (unlikely(length
>= xdr
->buf
->page_len
|| length
> NFS_MAXPATHLEN
))
449 hdrlen
= (u8
*)xdr
->p
- (u8
*)xdr
->iov
->iov_base
;
450 recvd
= xdr
->buf
->len
- hdrlen
;
451 if (unlikely(length
> recvd
))
454 xdr_read_pages(xdr
, length
);
455 xdr_terminate_string(xdr
->buf
, length
);
458 dprintk("NFS: returned pathname too long: %u\n", length
);
459 return -ENAMETOOLONG
;
461 dprintk("NFS: server cheating in pathname result: "
462 "length %u > received %u\n", length
, recvd
);
465 print_overflow_msg(__func__
, xdr
);
472 * union attrstat switch (stat status) {
479 static int decode_attrstat(struct xdr_stream
*xdr
, struct nfs_fattr
*result
)
481 enum nfs_stat status
;
484 error
= decode_stat(xdr
, &status
);
487 if (status
!= NFS_OK
)
489 error
= decode_fattr(xdr
, result
);
493 return nfs_stat_to_errno(status
);
504 static void encode_diropargs(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
,
505 const char *name
, u32 length
)
507 encode_fhandle(xdr
, fh
);
508 encode_filename(xdr
, name
, length
);
514 * union diropres switch (stat status) {
524 static int decode_diropok(struct xdr_stream
*xdr
, struct nfs_diropok
*result
)
528 error
= decode_fhandle(xdr
, result
->fh
);
531 error
= decode_fattr(xdr
, result
->fattr
);
536 static int decode_diropres(struct xdr_stream
*xdr
, struct nfs_diropok
*result
)
538 enum nfs_stat status
;
541 error
= decode_stat(xdr
, &status
);
544 if (status
!= NFS_OK
)
546 error
= decode_diropok(xdr
, result
);
550 return nfs_stat_to_errno(status
);
555 * NFSv2 XDR encode functions
557 * NFSv2 argument types are defined in section 2.2 of RFC 1094:
558 * "NFS: Network File System Protocol Specification".
561 static void nfs2_xdr_enc_fhandle(struct rpc_rqst
*req
,
562 struct xdr_stream
*xdr
,
563 const struct nfs_fh
*fh
)
565 encode_fhandle(xdr
, fh
);
576 static void nfs2_xdr_enc_sattrargs(struct rpc_rqst
*req
,
577 struct xdr_stream
*xdr
,
578 const struct nfs_sattrargs
*args
)
580 encode_fhandle(xdr
, args
->fh
);
581 encode_sattr(xdr
, args
->sattr
);
584 static void nfs2_xdr_enc_diropargs(struct rpc_rqst
*req
,
585 struct xdr_stream
*xdr
,
586 const struct nfs_diropargs
*args
)
588 encode_diropargs(xdr
, args
->fh
, args
->name
, args
->len
);
591 static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst
*req
,
592 struct xdr_stream
*xdr
,
593 const struct nfs_readlinkargs
*args
)
595 encode_fhandle(xdr
, args
->fh
);
596 prepare_reply_buffer(req
, args
->pages
, args
->pgbase
,
597 args
->pglen
, NFS_readlinkres_sz
);
607 * unsigned totalcount;
610 static void encode_readargs(struct xdr_stream
*xdr
,
611 const struct nfs_readargs
*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
,
627 const struct nfs_readargs
*args
)
629 encode_readargs(xdr
, args
);
630 prepare_reply_buffer(req
, args
->pages
, args
->pgbase
,
631 args
->count
, NFS_readres_sz
);
632 req
->rq_rcv_buf
.flags
|= XDRBUF_READ
;
640 * unsigned beginoffset;
642 * unsigned totalcount;
646 static void encode_writeargs(struct xdr_stream
*xdr
,
647 const struct nfs_writeargs
*args
)
649 u32 offset
= args
->offset
;
650 u32 count
= args
->count
;
653 encode_fhandle(xdr
, args
->fh
);
655 p
= xdr_reserve_space(xdr
, 4 + 4 + 4 + 4);
656 *p
++ = cpu_to_be32(offset
);
657 *p
++ = cpu_to_be32(offset
);
658 *p
++ = cpu_to_be32(count
);
661 *p
= cpu_to_be32(count
);
662 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, count
);
665 static void nfs2_xdr_enc_writeargs(struct rpc_rqst
*req
,
666 struct xdr_stream
*xdr
,
667 const struct nfs_writeargs
*args
)
669 encode_writeargs(xdr
, args
);
670 xdr
->buf
->flags
|= XDRBUF_WRITE
;
676 * struct createargs {
681 static void nfs2_xdr_enc_createargs(struct rpc_rqst
*req
,
682 struct xdr_stream
*xdr
,
683 const struct nfs_createargs
*args
)
685 encode_diropargs(xdr
, args
->fh
, args
->name
, args
->len
);
686 encode_sattr(xdr
, args
->sattr
);
689 static void nfs2_xdr_enc_removeargs(struct rpc_rqst
*req
,
690 struct xdr_stream
*xdr
,
691 const struct nfs_removeargs
*args
)
693 encode_diropargs(xdr
, args
->fh
, args
->name
.name
, args
->name
.len
);
699 * struct renameargs {
704 static void nfs2_xdr_enc_renameargs(struct rpc_rqst
*req
,
705 struct xdr_stream
*xdr
,
706 const struct nfs_renameargs
*args
)
708 const struct qstr
*old
= args
->old_name
;
709 const struct qstr
*new = args
->new_name
;
711 encode_diropargs(xdr
, args
->old_dir
, old
->name
, old
->len
);
712 encode_diropargs(xdr
, args
->new_dir
, new->name
, new->len
);
723 static void nfs2_xdr_enc_linkargs(struct rpc_rqst
*req
,
724 struct xdr_stream
*xdr
,
725 const struct nfs_linkargs
*args
)
727 encode_fhandle(xdr
, args
->fromfh
);
728 encode_diropargs(xdr
, args
->tofh
, args
->toname
, args
->tolen
);
732 * 2.2.14. symlinkargs
734 * struct symlinkargs {
740 static void nfs2_xdr_enc_symlinkargs(struct rpc_rqst
*req
,
741 struct xdr_stream
*xdr
,
742 const struct nfs_symlinkargs
*args
)
744 encode_diropargs(xdr
, args
->fromfh
, args
->fromname
, args
->fromlen
);
745 encode_path(xdr
, args
->pages
, args
->pathlen
);
746 encode_sattr(xdr
, args
->sattr
);
750 * 2.2.17. readdirargs
752 * struct readdirargs {
758 static void encode_readdirargs(struct xdr_stream
*xdr
,
759 const struct nfs_readdirargs
*args
)
763 encode_fhandle(xdr
, args
->fh
);
765 p
= xdr_reserve_space(xdr
, 4 + 4);
766 *p
++ = cpu_to_be32(args
->cookie
);
767 *p
= cpu_to_be32(args
->count
);
770 static void nfs2_xdr_enc_readdirargs(struct rpc_rqst
*req
,
771 struct xdr_stream
*xdr
,
772 const struct nfs_readdirargs
*args
)
774 encode_readdirargs(xdr
, args
);
775 prepare_reply_buffer(req
, args
->pages
, 0,
776 args
->count
, NFS_readdirres_sz
);
780 * NFSv2 XDR decode functions
782 * NFSv2 result types are defined in section 2.2 of RFC 1094:
783 * "NFS: Network File System Protocol Specification".
786 static int nfs2_xdr_dec_stat(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
789 enum nfs_stat status
;
792 error
= decode_stat(xdr
, &status
);
795 if (status
!= NFS_OK
)
800 return nfs_stat_to_errno(status
);
803 static int nfs2_xdr_dec_attrstat(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
804 struct nfs_fattr
*result
)
806 return decode_attrstat(xdr
, result
);
809 static int nfs2_xdr_dec_diropres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
810 struct nfs_diropok
*result
)
812 return decode_diropres(xdr
, result
);
818 * union readlinkres switch (stat status) {
825 static int nfs2_xdr_dec_readlinkres(struct rpc_rqst
*req
,
826 struct xdr_stream
*xdr
, void *__unused
)
828 enum nfs_stat status
;
831 error
= decode_stat(xdr
, &status
);
834 if (status
!= NFS_OK
)
836 error
= decode_path(xdr
);
840 return nfs_stat_to_errno(status
);
846 * union readres switch (stat status) {
854 static int nfs2_xdr_dec_readres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
855 struct nfs_readres
*result
)
857 enum nfs_stat status
;
860 error
= decode_stat(xdr
, &status
);
863 if (status
!= NFS_OK
)
865 error
= decode_fattr(xdr
, result
->fattr
);
868 error
= decode_nfsdata(xdr
, result
);
872 return nfs_stat_to_errno(status
);
875 static int nfs2_xdr_dec_writeres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
876 struct nfs_writeres
*result
)
878 /* All NFSv2 writes are "file sync" writes */
879 result
->verf
->committed
= NFS_FILE_SYNC
;
880 return decode_attrstat(xdr
, result
->fattr
);
884 * nfs2_decode_dirent - Decode a single NFSv2 directory entry stored in
885 * the local page cache.
886 * @xdr: XDR stream where entry resides
887 * @entry: buffer to fill in with entry data
888 * @plus: boolean indicating whether this should be a readdirplus entry
890 * Returns zero if successful, otherwise a negative errno value is
893 * This function is not invoked during READDIR reply decoding, but
894 * rather whenever an application invokes the getdents(2) system call
895 * on a directory already in our cache.
906 int nfs2_decode_dirent(struct xdr_stream
*xdr
, struct nfs_entry
*entry
,
912 p
= xdr_inline_decode(xdr
, 4);
913 if (unlikely(p
== NULL
))
915 if (*p
++ == xdr_zero
) {
916 p
= xdr_inline_decode(xdr
, 4);
917 if (unlikely(p
== NULL
))
919 if (*p
++ == xdr_zero
)
925 p
= xdr_inline_decode(xdr
, 4);
926 if (unlikely(p
== NULL
))
928 entry
->ino
= be32_to_cpup(p
);
930 error
= decode_filename_inline(xdr
, &entry
->name
, &entry
->len
);
935 * The type (size and byte order) of nfscookie isn't defined in
936 * RFC 1094. This implementation assumes that it's an XDR uint32.
938 entry
->prev_cookie
= entry
->cookie
;
939 p
= xdr_inline_decode(xdr
, 4);
940 if (unlikely(p
== NULL
))
942 entry
->cookie
= be32_to_cpup(p
);
944 entry
->d_type
= DT_UNKNOWN
;
949 print_overflow_msg(__func__
, xdr
);
956 * union readdirres switch (stat status) {
966 * Read the directory contents into the page cache, but don't
967 * touch them. The actual decoding is done by nfs2_decode_dirent()
968 * during subsequent nfs_readdir() calls.
970 static int decode_readdirok(struct xdr_stream
*xdr
)
975 pglen
= xdr
->buf
->page_len
;
976 hdrlen
= (u8
*)xdr
->p
- (u8
*)xdr
->iov
->iov_base
;
977 recvd
= xdr
->buf
->len
- hdrlen
;
978 if (unlikely(pglen
> recvd
))
981 xdr_read_pages(xdr
, pglen
);
984 dprintk("NFS: server cheating in readdir result: "
985 "pglen %u > recvd %u\n", pglen
, recvd
);
990 static int nfs2_xdr_dec_readdirres(struct rpc_rqst
*req
,
991 struct xdr_stream
*xdr
, void *__unused
)
993 enum nfs_stat status
;
996 error
= decode_stat(xdr
, &status
);
999 if (status
!= NFS_OK
)
1001 error
= decode_readdirok(xdr
);
1005 return nfs_stat_to_errno(status
);
1011 * union statfsres (stat status) {
1024 static int decode_info(struct xdr_stream
*xdr
, struct nfs2_fsstat
*result
)
1028 p
= xdr_inline_decode(xdr
, NFS_info_sz
<< 2);
1029 if (unlikely(p
== NULL
))
1031 result
->tsize
= be32_to_cpup(p
++);
1032 result
->bsize
= be32_to_cpup(p
++);
1033 result
->blocks
= be32_to_cpup(p
++);
1034 result
->bfree
= be32_to_cpup(p
++);
1035 result
->bavail
= be32_to_cpup(p
);
1038 print_overflow_msg(__func__
, xdr
);
1042 static int nfs2_xdr_dec_statfsres(struct rpc_rqst
*req
, struct xdr_stream
*xdr
,
1043 struct nfs2_fsstat
*result
)
1045 enum nfs_stat status
;
1048 error
= decode_stat(xdr
, &status
);
1049 if (unlikely(error
))
1051 if (status
!= NFS_OK
)
1053 error
= decode_info(xdr
, result
);
1057 return nfs_stat_to_errno(status
);
1062 * We need to translate between nfs status return values and
1063 * the local errno values which may not be the same.
1065 static const struct {
1070 { NFSERR_PERM
, -EPERM
},
1071 { NFSERR_NOENT
, -ENOENT
},
1072 { NFSERR_IO
, -errno_NFSERR_IO
},
1073 { NFSERR_NXIO
, -ENXIO
},
1074 /* { NFSERR_EAGAIN, -EAGAIN }, */
1075 { NFSERR_ACCES
, -EACCES
},
1076 { NFSERR_EXIST
, -EEXIST
},
1077 { NFSERR_XDEV
, -EXDEV
},
1078 { NFSERR_NODEV
, -ENODEV
},
1079 { NFSERR_NOTDIR
, -ENOTDIR
},
1080 { NFSERR_ISDIR
, -EISDIR
},
1081 { NFSERR_INVAL
, -EINVAL
},
1082 { NFSERR_FBIG
, -EFBIG
},
1083 { NFSERR_NOSPC
, -ENOSPC
},
1084 { NFSERR_ROFS
, -EROFS
},
1085 { NFSERR_MLINK
, -EMLINK
},
1086 { NFSERR_NAMETOOLONG
, -ENAMETOOLONG
},
1087 { NFSERR_NOTEMPTY
, -ENOTEMPTY
},
1088 { NFSERR_DQUOT
, -EDQUOT
},
1089 { NFSERR_STALE
, -ESTALE
},
1090 { NFSERR_REMOTE
, -EREMOTE
},
1092 { NFSERR_WFLUSH
, -EWFLUSH
},
1094 { NFSERR_BADHANDLE
, -EBADHANDLE
},
1095 { NFSERR_NOT_SYNC
, -ENOTSYNC
},
1096 { NFSERR_BAD_COOKIE
, -EBADCOOKIE
},
1097 { NFSERR_NOTSUPP
, -ENOTSUPP
},
1098 { NFSERR_TOOSMALL
, -ETOOSMALL
},
1099 { NFSERR_SERVERFAULT
, -EREMOTEIO
},
1100 { NFSERR_BADTYPE
, -EBADTYPE
},
1101 { NFSERR_JUKEBOX
, -EJUKEBOX
},
1106 * nfs_stat_to_errno - convert an NFS status code to a local errno
1107 * @status: NFS status code to convert
1109 * Returns a local errno value, or -EIO if the NFS status code is
1110 * not recognized. This function is used jointly by NFSv2 and NFSv3.
1112 int nfs_stat_to_errno(enum nfs_stat status
)
1116 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
1117 if (nfs_errtbl
[i
].stat
== (int)status
)
1118 return nfs_errtbl
[i
].errno
;
1120 dprintk("NFS: Unrecognized nfs status value: %u\n", status
);
1121 return nfs_errtbl
[i
].errno
;
1124 #define PROC(proc, argtype, restype, timer) \
1125 [NFSPROC_##proc] = { \
1126 .p_proc = NFSPROC_##proc, \
1127 .p_encode = (kxdreproc_t)nfs2_xdr_enc_##argtype, \
1128 .p_decode = (kxdrdproc_t)nfs2_xdr_dec_##restype, \
1129 .p_arglen = NFS_##argtype##_sz, \
1130 .p_replen = NFS_##restype##_sz, \
1132 .p_statidx = NFSPROC_##proc, \
1135 struct rpc_procinfo nfs_procedures
[] = {
1136 PROC(GETATTR
, fhandle
, attrstat
, 1),
1137 PROC(SETATTR
, sattrargs
, attrstat
, 0),
1138 PROC(LOOKUP
, diropargs
, diropres
, 2),
1139 PROC(READLINK
, readlinkargs
, readlinkres
, 3),
1140 PROC(READ
, readargs
, readres
, 3),
1141 PROC(WRITE
, writeargs
, writeres
, 4),
1142 PROC(CREATE
, createargs
, diropres
, 0),
1143 PROC(REMOVE
, removeargs
, stat
, 0),
1144 PROC(RENAME
, renameargs
, stat
, 0),
1145 PROC(LINK
, linkargs
, stat
, 0),
1146 PROC(SYMLINK
, symlinkargs
, stat
, 0),
1147 PROC(MKDIR
, createargs
, diropres
, 0),
1148 PROC(RMDIR
, diropargs
, stat
, 0),
1149 PROC(READDIR
, readdirargs
, readdirres
, 3),
1150 PROC(STATFS
, fhandle
, statfsres
, 0),
1153 struct rpc_version nfs_version2
= {
1155 .nrprocs
= ARRAY_SIZE(nfs_procedures
),
1156 .procs
= nfs_procedures