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
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_readres *result)
112 p = xdr_inline_decode(xdr, 4);
113 if (unlikely(p == NULL))
115 count = be32_to_cpup(p);
116 hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base;
117 recvd = xdr->buf->len - hdrlen;
118 if (unlikely(count > recvd))
121 xdr_read_pages(xdr, count);
122 result->eof = 0; /* NFSv2 does not pass EOF flag on the wire. */
123 result->count = count;
126 dprintk("NFS: server cheating in read result: "
127 "count %u > recvd %u\n", count, recvd);
131 print_overflow_msg(__func__, xdr);
145 * NFSERR_NOTDIR = 20,
150 * NFSERR_NAMETOOLONG = 63,
151 * NFSERR_NOTEMPTY = 66,
157 static int decode_stat(struct xdr_stream *xdr, enum nfs_stat *status)
161 p = xdr_inline_decode(xdr, 4);
162 if (unlikely(p == NULL))
164 *status = be32_to_cpup(p);
167 print_overflow_msg(__func__, xdr);
184 static __be32 *xdr_decode_ftype(__be32 *p, u32 *type)
186 *type = be32_to_cpup(p++);
187 if (unlikely(*type > NF2FIFO))
195 * typedef opaque fhandle[FHSIZE];
197 static void encode_fhandle(struct xdr_stream *xdr, const struct nfs_fh *fh)
201 BUG_ON(fh->size != NFS2_FHSIZE);
202 p = xdr_reserve_space(xdr, NFS2_FHSIZE);
203 memcpy(p, fh->data, NFS2_FHSIZE);
206 static int decode_fhandle(struct xdr_stream *xdr, struct nfs_fh *fh)
210 p = xdr_inline_decode(xdr, NFS2_FHSIZE);
211 if (unlikely(p == NULL))
213 fh->size = NFS2_FHSIZE;
214 memcpy(fh->data, p, NFS2_FHSIZE);
217 print_overflow_msg(__func__, xdr);
225 * unsigned int seconds;
226 * unsigned int useconds;
229 static __be32 *xdr_encode_time(__be32 *p, const struct timespec *timep)
231 *p++ = cpu_to_be32(timep->tv_sec);
232 if (timep->tv_nsec != 0)
233 *p++ = cpu_to_be32(timep->tv_nsec / NSEC_PER_USEC);
235 *p++ = cpu_to_be32(0);
240 * Passing the invalid value useconds=1000000 is a Sun convention for
241 * "set to current server time". It's needed to make permissions checks
242 * for the "touch" program across v2 mounts to Solaris and Irix servers
243 * work correctly. See description of sattr in section 6.1 of "NFS
244 * Illustrated" by Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5.
246 static __be32 *xdr_encode_current_server_time(__be32 *p,
247 const struct timespec *timep)
249 *p++ = cpu_to_be32(timep->tv_sec);
250 *p++ = cpu_to_be32(1000000);
254 static __be32 *xdr_decode_time(__be32 *p, struct timespec *timep)
256 timep->tv_sec = be32_to_cpup(p++);
257 timep->tv_nsec = be32_to_cpup(p++) * NSEC_PER_USEC;
267 * unsigned int nlink;
271 * unsigned int blocksize;
273 * unsigned int blocks;
275 * unsigned int fileid;
282 static int decode_fattr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
287 p = xdr_inline_decode(xdr, NFS_fattr_sz << 2);
288 if (unlikely(p == NULL))
291 fattr->valid |= NFS_ATTR_FATTR_V2;
293 p = xdr_decode_ftype(p, &type);
295 fattr->mode = be32_to_cpup(p++);
296 fattr->nlink = be32_to_cpup(p++);
297 fattr->uid = be32_to_cpup(p++);
298 fattr->gid = be32_to_cpup(p++);
299 fattr->size = be32_to_cpup(p++);
300 fattr->du.nfs2.blocksize = be32_to_cpup(p++);
302 rdev = be32_to_cpup(p++);
303 fattr->rdev = new_decode_dev(rdev);
304 if (type == (u32)NFCHR && rdev == (u32)NFS2_FIFO_DEV) {
305 fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO;
309 fattr->du.nfs2.blocks = be32_to_cpup(p++);
310 fattr->fsid.major = be32_to_cpup(p++);
311 fattr->fsid.minor = 0;
312 fattr->fileid = be32_to_cpup(p++);
314 p = xdr_decode_time(p, &fattr->atime);
315 p = xdr_decode_time(p, &fattr->mtime);
316 xdr_decode_time(p, &fattr->ctime);
317 fattr->change_attr = nfs_timespec_to_change_attr(&fattr->ctime);
321 print_overflow_msg(__func__, xdr);
338 #define NFS2_SATTR_NOT_SET (0xffffffff)
340 static __be32 *xdr_time_not_set(__be32 *p)
342 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
343 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
347 static void encode_sattr(struct xdr_stream *xdr, const struct iattr *attr)
351 p = xdr_reserve_space(xdr, NFS_sattr_sz << 2);
353 if (attr->ia_valid & ATTR_MODE)
354 *p++ = cpu_to_be32(attr->ia_mode);
356 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
357 if (attr->ia_valid & ATTR_UID)
358 *p++ = cpu_to_be32(attr->ia_uid);
360 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
361 if (attr->ia_valid & ATTR_GID)
362 *p++ = cpu_to_be32(attr->ia_gid);
364 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
365 if (attr->ia_valid & ATTR_SIZE)
366 *p++ = cpu_to_be32((u32)attr->ia_size);
368 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
370 if (attr->ia_valid & ATTR_ATIME_SET)
371 p = xdr_encode_time(p, &attr->ia_atime);
372 else if (attr->ia_valid & ATTR_ATIME)
373 p = xdr_encode_current_server_time(p, &attr->ia_atime);
375 p = xdr_time_not_set(p);
376 if (attr->ia_valid & ATTR_MTIME_SET)
377 xdr_encode_time(p, &attr->ia_mtime);
378 else if (attr->ia_valid & ATTR_MTIME)
379 xdr_encode_current_server_time(p, &attr->ia_mtime);
387 * typedef string filename<MAXNAMLEN>;
389 static void encode_filename(struct xdr_stream *xdr,
390 const char *name, u32 length)
394 BUG_ON(length > NFS2_MAXNAMLEN);
395 p = xdr_reserve_space(xdr, 4 + length);
396 xdr_encode_opaque(p, name, length);
399 static int decode_filename_inline(struct xdr_stream *xdr,
400 const char **name, u32 *length)
405 p = xdr_inline_decode(xdr, 4);
406 if (unlikely(p == NULL))
408 count = be32_to_cpup(p);
409 if (count > NFS3_MAXNAMLEN)
410 goto out_nametoolong;
411 p = xdr_inline_decode(xdr, count);
412 if (unlikely(p == NULL))
414 *name = (const char *)p;
418 dprintk("NFS: returned filename too long: %u\n", count);
419 return -ENAMETOOLONG;
421 print_overflow_msg(__func__, xdr);
428 * typedef string path<MAXPATHLEN>;
430 static void encode_path(struct xdr_stream *xdr, struct page **pages, u32 length)
434 BUG_ON(length > NFS2_MAXPATHLEN);
435 p = xdr_reserve_space(xdr, 4);
436 *p = cpu_to_be32(length);
437 xdr_write_pages(xdr, pages, 0, length);
440 static int decode_path(struct xdr_stream *xdr)
446 p = xdr_inline_decode(xdr, 4);
447 if (unlikely(p == NULL))
449 length = be32_to_cpup(p);
450 if (unlikely(length >= xdr->buf->page_len || length > NFS_MAXPATHLEN))
452 hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base;
453 recvd = xdr->buf->len - hdrlen;
454 if (unlikely(length > recvd))
457 xdr_read_pages(xdr, length);
458 xdr_terminate_string(xdr->buf, length);
461 dprintk("NFS: returned pathname too long: %u\n", length);
462 return -ENAMETOOLONG;
464 dprintk("NFS: server cheating in pathname result: "
465 "length %u > received %u\n", length, recvd);
468 print_overflow_msg(__func__, xdr);
475 * union attrstat switch (stat status) {
482 static int decode_attrstat(struct xdr_stream *xdr, struct nfs_fattr *result)
484 enum nfs_stat status;
487 error = decode_stat(xdr, &status);
490 if (status != NFS_OK)
492 error = decode_fattr(xdr, result);
496 return nfs_stat_to_errno(status);
507 static void encode_diropargs(struct xdr_stream *xdr, const struct nfs_fh *fh,
508 const char *name, u32 length)
510 encode_fhandle(xdr, fh);
511 encode_filename(xdr, name, length);
517 * union diropres switch (stat status) {
527 static int decode_diropok(struct xdr_stream *xdr, struct nfs_diropok *result)
531 error = decode_fhandle(xdr, result->fh);
534 error = decode_fattr(xdr, result->fattr);
539 static int decode_diropres(struct xdr_stream *xdr, struct nfs_diropok *result)
541 enum nfs_stat status;
544 error = decode_stat(xdr, &status);
547 if (status != NFS_OK)
549 error = decode_diropok(xdr, result);
553 return nfs_stat_to_errno(status);
558 * NFSv2 XDR encode functions
560 * NFSv2 argument types are defined in section 2.2 of RFC 1094:
561 * "NFS: Network File System Protocol Specification".
564 static void nfs2_xdr_enc_fhandle(struct rpc_rqst *req,
565 struct xdr_stream *xdr,
566 const struct nfs_fh *fh)
568 encode_fhandle(xdr, fh);
579 static void nfs2_xdr_enc_sattrargs(struct rpc_rqst *req,
580 struct xdr_stream *xdr,
581 const struct nfs_sattrargs *args)
583 encode_fhandle(xdr, args->fh);
584 encode_sattr(xdr, args->sattr);
587 static void nfs2_xdr_enc_diropargs(struct rpc_rqst *req,
588 struct xdr_stream *xdr,
589 const struct nfs_diropargs *args)
591 encode_diropargs(xdr, args->fh, args->name, args->len);
594 static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst *req,
595 struct xdr_stream *xdr,
596 const struct nfs_readlinkargs *args)
598 encode_fhandle(xdr, args->fh);
599 prepare_reply_buffer(req, args->pages, args->pgbase,
600 args->pglen, NFS_readlinkres_sz);
610 * unsigned totalcount;
613 static void encode_readargs(struct xdr_stream *xdr,
614 const struct nfs_readargs *args)
616 u32 offset = args->offset;
617 u32 count = args->count;
620 encode_fhandle(xdr, args->fh);
622 p = xdr_reserve_space(xdr, 4 + 4 + 4);
623 *p++ = cpu_to_be32(offset);
624 *p++ = cpu_to_be32(count);
625 *p = cpu_to_be32(count);
628 static void nfs2_xdr_enc_readargs(struct rpc_rqst *req,
629 struct xdr_stream *xdr,
630 const struct nfs_readargs *args)
632 encode_readargs(xdr, args);
633 prepare_reply_buffer(req, args->pages, args->pgbase,
634 args->count, NFS_readres_sz);
635 req->rq_rcv_buf.flags |= XDRBUF_READ;
643 * unsigned beginoffset;
645 * unsigned totalcount;
649 static void encode_writeargs(struct xdr_stream *xdr,
650 const struct nfs_writeargs *args)
652 u32 offset = args->offset;
653 u32 count = args->count;
656 encode_fhandle(xdr, args->fh);
658 p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4);
659 *p++ = cpu_to_be32(offset);
660 *p++ = cpu_to_be32(offset);
661 *p++ = cpu_to_be32(count);
664 *p = cpu_to_be32(count);
665 xdr_write_pages(xdr, args->pages, args->pgbase, count);
668 static void nfs2_xdr_enc_writeargs(struct rpc_rqst *req,
669 struct xdr_stream *xdr,
670 const struct nfs_writeargs *args)
672 encode_writeargs(xdr, args);
673 xdr->buf->flags |= XDRBUF_WRITE;
679 * struct createargs {
684 static void nfs2_xdr_enc_createargs(struct rpc_rqst *req,
685 struct xdr_stream *xdr,
686 const struct nfs_createargs *args)
688 encode_diropargs(xdr, args->fh, args->name, args->len);
689 encode_sattr(xdr, args->sattr);
692 static void nfs2_xdr_enc_removeargs(struct rpc_rqst *req,
693 struct xdr_stream *xdr,
694 const struct nfs_removeargs *args)
696 encode_diropargs(xdr, args->fh, args->name.name, args->name.len);
702 * struct renameargs {
707 static void nfs2_xdr_enc_renameargs(struct rpc_rqst *req,
708 struct xdr_stream *xdr,
709 const struct nfs_renameargs *args)
711 const struct qstr *old = args->old_name;
712 const struct qstr *new = args->new_name;
714 encode_diropargs(xdr, args->old_dir, old->name, old->len);
715 encode_diropargs(xdr, args->new_dir, new->name, new->len);
726 static void nfs2_xdr_enc_linkargs(struct rpc_rqst *req,
727 struct xdr_stream *xdr,
728 const struct nfs_linkargs *args)
730 encode_fhandle(xdr, args->fromfh);
731 encode_diropargs(xdr, args->tofh, args->toname, args->tolen);
735 * 2.2.14. symlinkargs
737 * struct symlinkargs {
743 static void nfs2_xdr_enc_symlinkargs(struct rpc_rqst *req,
744 struct xdr_stream *xdr,
745 const struct nfs_symlinkargs *args)
747 encode_diropargs(xdr, args->fromfh, args->fromname, args->fromlen);
748 encode_path(xdr, args->pages, args->pathlen);
749 encode_sattr(xdr, args->sattr);
753 * 2.2.17. readdirargs
755 * struct readdirargs {
761 static void encode_readdirargs(struct xdr_stream *xdr,
762 const struct nfs_readdirargs *args)
766 encode_fhandle(xdr, args->fh);
768 p = xdr_reserve_space(xdr, 4 + 4);
769 *p++ = cpu_to_be32(args->cookie);
770 *p = cpu_to_be32(args->count);
773 static void nfs2_xdr_enc_readdirargs(struct rpc_rqst *req,
774 struct xdr_stream *xdr,
775 const struct nfs_readdirargs *args)
777 encode_readdirargs(xdr, args);
778 prepare_reply_buffer(req, args->pages, 0,
779 args->count, NFS_readdirres_sz);
783 * NFSv2 XDR decode functions
785 * NFSv2 result types are defined in section 2.2 of RFC 1094:
786 * "NFS: Network File System Protocol Specification".
789 static int nfs2_xdr_dec_stat(struct rpc_rqst *req, struct xdr_stream *xdr,
792 enum nfs_stat status;
795 error = decode_stat(xdr, &status);
798 if (status != NFS_OK)
803 return nfs_stat_to_errno(status);
806 static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, struct xdr_stream *xdr,
807 struct nfs_fattr *result)
809 return decode_attrstat(xdr, result);
812 static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, struct xdr_stream *xdr,
813 struct nfs_diropok *result)
815 return decode_diropres(xdr, result);
821 * union readlinkres switch (stat status) {
828 static int nfs2_xdr_dec_readlinkres(struct rpc_rqst *req,
829 struct xdr_stream *xdr, void *__unused)
831 enum nfs_stat status;
834 error = decode_stat(xdr, &status);
837 if (status != NFS_OK)
839 error = decode_path(xdr);
843 return nfs_stat_to_errno(status);
849 * union readres switch (stat status) {
857 static int nfs2_xdr_dec_readres(struct rpc_rqst *req, struct xdr_stream *xdr,
858 struct nfs_readres *result)
860 enum nfs_stat status;
863 error = decode_stat(xdr, &status);
866 if (status != NFS_OK)
868 error = decode_fattr(xdr, result->fattr);
871 error = decode_nfsdata(xdr, result);
875 return nfs_stat_to_errno(status);
878 static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, struct xdr_stream *xdr,
879 struct nfs_writeres *result)
881 /* All NFSv2 writes are "file sync" writes */
882 result->verf->committed = NFS_FILE_SYNC;
883 return decode_attrstat(xdr, result->fattr);
887 * nfs2_decode_dirent - Decode a single NFSv2 directory entry stored in
888 * the local page cache.
889 * @xdr: XDR stream where entry resides
890 * @entry: buffer to fill in with entry data
891 * @plus: boolean indicating whether this should be a readdirplus entry
893 * Returns zero if successful, otherwise a negative errno value is
896 * This function is not invoked during READDIR reply decoding, but
897 * rather whenever an application invokes the getdents(2) system call
898 * on a directory already in our cache.
909 int nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
915 p = xdr_inline_decode(xdr, 4);
916 if (unlikely(p == NULL))
918 if (*p++ == xdr_zero) {
919 p = xdr_inline_decode(xdr, 4);
920 if (unlikely(p == NULL))
922 if (*p++ == xdr_zero)
928 p = xdr_inline_decode(xdr, 4);
929 if (unlikely(p == NULL))
931 entry->ino = be32_to_cpup(p);
933 error = decode_filename_inline(xdr, &entry->name, &entry->len);
938 * The type (size and byte order) of nfscookie isn't defined in
939 * RFC 1094. This implementation assumes that it's an XDR uint32.
941 entry->prev_cookie = entry->cookie;
942 p = xdr_inline_decode(xdr, 4);
943 if (unlikely(p == NULL))
945 entry->cookie = be32_to_cpup(p);
947 entry->d_type = DT_UNKNOWN;
952 print_overflow_msg(__func__, xdr);
959 * union readdirres switch (stat status) {
969 * Read the directory contents into the page cache, but don't
970 * touch them. The actual decoding is done by nfs2_decode_dirent()
971 * during subsequent nfs_readdir() calls.
973 static int decode_readdirok(struct xdr_stream *xdr)
978 pglen = xdr->buf->page_len;
979 hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base;
980 recvd = xdr->buf->len - hdrlen;
981 if (unlikely(pglen > recvd))
984 xdr_read_pages(xdr, pglen);
987 dprintk("NFS: server cheating in readdir result: "
988 "pglen %u > recvd %u\n", pglen, recvd);
993 static int nfs2_xdr_dec_readdirres(struct rpc_rqst *req,
994 struct xdr_stream *xdr, void *__unused)
996 enum nfs_stat status;
999 error = decode_stat(xdr, &status);
1000 if (unlikely(error))
1002 if (status != NFS_OK)
1004 error = decode_readdirok(xdr);
1008 return nfs_stat_to_errno(status);
1014 * union statfsres (stat status) {
1027 static int decode_info(struct xdr_stream *xdr, struct nfs2_fsstat *result)
1031 p = xdr_inline_decode(xdr, NFS_info_sz << 2);
1032 if (unlikely(p == NULL))
1034 result->tsize = be32_to_cpup(p++);
1035 result->bsize = be32_to_cpup(p++);
1036 result->blocks = be32_to_cpup(p++);
1037 result->bfree = be32_to_cpup(p++);
1038 result->bavail = be32_to_cpup(p);
1041 print_overflow_msg(__func__, xdr);
1045 static int nfs2_xdr_dec_statfsres(struct rpc_rqst *req, struct xdr_stream *xdr,
1046 struct nfs2_fsstat *result)
1048 enum nfs_stat status;
1051 error = decode_stat(xdr, &status);
1052 if (unlikely(error))
1054 if (status != NFS_OK)
1056 error = decode_info(xdr, result);
1060 return nfs_stat_to_errno(status);
1065 * We need to translate between nfs status return values and
1066 * the local errno values which may not be the same.
1068 static const struct {
1073 { NFSERR_PERM, -EPERM },
1074 { NFSERR_NOENT, -ENOENT },
1075 { NFSERR_IO, -errno_NFSERR_IO},
1076 { NFSERR_NXIO, -ENXIO },
1077 /* { NFSERR_EAGAIN, -EAGAIN }, */
1078 { NFSERR_ACCES, -EACCES },
1079 { NFSERR_EXIST, -EEXIST },
1080 { NFSERR_XDEV, -EXDEV },
1081 { NFSERR_NODEV, -ENODEV },
1082 { NFSERR_NOTDIR, -ENOTDIR },
1083 { NFSERR_ISDIR, -EISDIR },
1084 { NFSERR_INVAL, -EINVAL },
1085 { NFSERR_FBIG, -EFBIG },
1086 { NFSERR_NOSPC, -ENOSPC },
1087 { NFSERR_ROFS, -EROFS },
1088 { NFSERR_MLINK, -EMLINK },
1089 { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
1090 { NFSERR_NOTEMPTY, -ENOTEMPTY },
1091 { NFSERR_DQUOT, -EDQUOT },
1092 { NFSERR_STALE, -ESTALE },
1093 { NFSERR_REMOTE, -EREMOTE },
1095 { NFSERR_WFLUSH, -EWFLUSH },
1097 { NFSERR_BADHANDLE, -EBADHANDLE },
1098 { NFSERR_NOT_SYNC, -ENOTSYNC },
1099 { NFSERR_BAD_COOKIE, -EBADCOOKIE },
1100 { NFSERR_NOTSUPP, -ENOTSUPP },
1101 { NFSERR_TOOSMALL, -ETOOSMALL },
1102 { NFSERR_SERVERFAULT, -EREMOTEIO },
1103 { NFSERR_BADTYPE, -EBADTYPE },
1104 { NFSERR_JUKEBOX, -EJUKEBOX },
1109 * nfs_stat_to_errno - convert an NFS status code to a local errno
1110 * @status: NFS status code to convert
1112 * Returns a local errno value, or -EIO if the NFS status code is
1113 * not recognized. This function is used jointly by NFSv2 and NFSv3.
1115 static int nfs_stat_to_errno(enum nfs_stat status)
1119 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
1120 if (nfs_errtbl[i].stat == (int)status)
1121 return nfs_errtbl[i].errno;
1123 dprintk("NFS: Unrecognized nfs status value: %u\n", status);
1124 return nfs_errtbl[i].errno;
1127 #define PROC(proc, argtype, restype, timer) \
1128 [NFSPROC_##proc] = { \
1129 .p_proc = NFSPROC_##proc, \
1130 .p_encode = (kxdreproc_t)nfs2_xdr_enc_##argtype, \
1131 .p_decode = (kxdrdproc_t)nfs2_xdr_dec_##restype, \
1132 .p_arglen = NFS_##argtype##_sz, \
1133 .p_replen = NFS_##restype##_sz, \
1135 .p_statidx = NFSPROC_##proc, \
1138 struct rpc_procinfo nfs_procedures[] = {
1139 PROC(GETATTR, fhandle, attrstat, 1),
1140 PROC(SETATTR, sattrargs, attrstat, 0),
1141 PROC(LOOKUP, diropargs, diropres, 2),
1142 PROC(READLINK, readlinkargs, readlinkres, 3),
1143 PROC(READ, readargs, readres, 3),
1144 PROC(WRITE, writeargs, writeres, 4),
1145 PROC(CREATE, createargs, diropres, 0),
1146 PROC(REMOVE, removeargs, stat, 0),
1147 PROC(RENAME, renameargs, stat, 0),
1148 PROC(LINK, linkargs, stat, 0),
1149 PROC(SYMLINK, symlinkargs, stat, 0),
1150 PROC(MKDIR, createargs, diropres, 0),
1151 PROC(RMDIR, diropargs, stat, 0),
1152 PROC(READDIR, readdirargs, readdirres, 3),
1153 PROC(STATFS, fhandle, statfsres, 0),
1156 const struct rpc_version nfs_version2 = {
1158 .nrprocs = ARRAY_SIZE(nfs_procedures),
1159 .procs = nfs_procedures