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
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(xdr, (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 timespec64 *timep)
214 *p++ = cpu_to_be32((u32)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 timespec64 *timep)
232 *p++ = cpu_to_be32(timep->tv_sec);
233 *p++ = cpu_to_be32(1000000);
237 static __be32 *xdr_decode_time(__be32 *p, struct timespec64 *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)
344 p = xdr_reserve_space(xdr, NFS_sattr_sz << 2);
346 if (attr->ia_valid & ATTR_MODE)
347 *p++ = cpu_to_be32(attr->ia_mode);
349 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
350 if (attr->ia_valid & ATTR_UID)
351 *p++ = cpu_to_be32(from_kuid_munged(userns, attr->ia_uid));
353 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
354 if (attr->ia_valid & ATTR_GID)
355 *p++ = cpu_to_be32(from_kgid_munged(userns, attr->ia_gid));
357 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
358 if (attr->ia_valid & ATTR_SIZE)
359 *p++ = cpu_to_be32((u32)attr->ia_size);
361 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
363 if (attr->ia_valid & ATTR_ATIME_SET)
364 p = xdr_encode_time(p, &attr->ia_atime);
365 else if (attr->ia_valid & ATTR_ATIME)
366 p = xdr_encode_current_server_time(p, &attr->ia_atime);
368 p = xdr_time_not_set(p);
369 if (attr->ia_valid & ATTR_MTIME_SET)
370 xdr_encode_time(p, &attr->ia_mtime);
371 else if (attr->ia_valid & ATTR_MTIME)
372 xdr_encode_current_server_time(p, &attr->ia_mtime);
380 * typedef string filename<MAXNAMLEN>;
382 static void encode_filename(struct xdr_stream *xdr,
383 const char *name, u32 length)
387 WARN_ON_ONCE(length > NFS2_MAXNAMLEN);
388 p = xdr_reserve_space(xdr, 4 + length);
389 xdr_encode_opaque(p, name, length);
392 static int decode_filename_inline(struct xdr_stream *xdr,
393 const char **name, u32 *length)
398 p = xdr_inline_decode(xdr, 4);
401 count = be32_to_cpup(p);
402 if (count > NFS3_MAXNAMLEN)
403 goto out_nametoolong;
404 p = xdr_inline_decode(xdr, count);
407 *name = (const char *)p;
411 dprintk("NFS: returned filename too long: %u\n", count);
412 return -ENAMETOOLONG;
418 * typedef string path<MAXPATHLEN>;
420 static void encode_path(struct xdr_stream *xdr, struct page **pages, u32 length)
424 p = xdr_reserve_space(xdr, 4);
425 *p = cpu_to_be32(length);
426 xdr_write_pages(xdr, pages, 0, length);
429 static int decode_path(struct xdr_stream *xdr)
434 p = xdr_inline_decode(xdr, 4);
437 length = be32_to_cpup(p);
438 if (unlikely(length >= xdr->buf->page_len || length > NFS_MAXPATHLEN))
440 recvd = xdr_read_pages(xdr, length);
441 if (unlikely(length > recvd))
443 xdr_terminate_string(xdr->buf, length);
446 dprintk("NFS: returned pathname too long: %u\n", length);
447 return -ENAMETOOLONG;
449 dprintk("NFS: server cheating in pathname result: "
450 "length %u > received %u\n", length, recvd);
457 * union attrstat switch (stat status) {
464 static int decode_attrstat(struct xdr_stream *xdr, struct nfs_fattr *result,
466 struct user_namespace *userns)
468 enum nfs_stat status;
471 error = decode_stat(xdr, &status);
476 if (status != NFS_OK)
478 error = decode_fattr(xdr, result, userns);
482 return nfs_stat_to_errno(status);
493 static void encode_diropargs(struct xdr_stream *xdr, const struct nfs_fh *fh,
494 const char *name, u32 length)
496 encode_fhandle(xdr, fh);
497 encode_filename(xdr, name, length);
503 * union diropres switch (stat status) {
513 static int decode_diropok(struct xdr_stream *xdr, struct nfs_diropok *result,
514 struct user_namespace *userns)
518 error = decode_fhandle(xdr, result->fh);
521 error = decode_fattr(xdr, result->fattr, userns);
526 static int decode_diropres(struct xdr_stream *xdr, struct nfs_diropok *result,
527 struct user_namespace *userns)
529 enum nfs_stat status;
532 error = decode_stat(xdr, &status);
535 if (status != NFS_OK)
537 error = decode_diropok(xdr, result, userns);
541 return nfs_stat_to_errno(status);
546 * NFSv2 XDR encode functions
548 * NFSv2 argument types are defined in section 2.2 of RFC 1094:
549 * "NFS: Network File System Protocol Specification".
552 static void nfs2_xdr_enc_fhandle(struct rpc_rqst *req,
553 struct xdr_stream *xdr,
556 const struct nfs_fh *fh = data;
558 encode_fhandle(xdr, fh);
569 static void nfs2_xdr_enc_sattrargs(struct rpc_rqst *req,
570 struct xdr_stream *xdr,
573 const struct nfs_sattrargs *args = data;
575 encode_fhandle(xdr, args->fh);
576 encode_sattr(xdr, args->sattr, rpc_rqst_userns(req));
579 static void nfs2_xdr_enc_diropargs(struct rpc_rqst *req,
580 struct xdr_stream *xdr,
583 const struct nfs_diropargs *args = data;
585 encode_diropargs(xdr, args->fh, args->name, args->len);
588 static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst *req,
589 struct xdr_stream *xdr,
592 const struct nfs_readlinkargs *args = data;
594 encode_fhandle(xdr, args->fh);
595 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
596 args->pglen, NFS_readlinkres_sz);
606 * unsigned totalcount;
609 static void encode_readargs(struct xdr_stream *xdr,
610 const struct nfs_pgio_args *args)
612 u32 offset = args->offset;
613 u32 count = args->count;
616 encode_fhandle(xdr, args->fh);
618 p = xdr_reserve_space(xdr, 4 + 4 + 4);
619 *p++ = cpu_to_be32(offset);
620 *p++ = cpu_to_be32(count);
621 *p = cpu_to_be32(count);
624 static void nfs2_xdr_enc_readargs(struct rpc_rqst *req,
625 struct xdr_stream *xdr,
628 const struct nfs_pgio_args *args = data;
630 encode_readargs(xdr, args);
631 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
632 args->count, NFS_readres_sz);
633 req->rq_rcv_buf.flags |= XDRBUF_READ;
641 * unsigned beginoffset;
643 * unsigned totalcount;
647 static void encode_writeargs(struct xdr_stream *xdr,
648 const struct nfs_pgio_args *args)
650 u32 offset = args->offset;
651 u32 count = args->count;
654 encode_fhandle(xdr, args->fh);
656 p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4);
657 *p++ = cpu_to_be32(offset);
658 *p++ = cpu_to_be32(offset);
659 *p++ = cpu_to_be32(count);
662 *p = cpu_to_be32(count);
663 xdr_write_pages(xdr, args->pages, args->pgbase, count);
666 static void nfs2_xdr_enc_writeargs(struct rpc_rqst *req,
667 struct xdr_stream *xdr,
670 const struct nfs_pgio_args *args = data;
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,
688 const struct nfs_createargs *args = data;
690 encode_diropargs(xdr, args->fh, args->name, args->len);
691 encode_sattr(xdr, args->sattr, rpc_rqst_userns(req));
694 static void nfs2_xdr_enc_removeargs(struct rpc_rqst *req,
695 struct xdr_stream *xdr,
698 const struct nfs_removeargs *args = data;
700 encode_diropargs(xdr, args->fh, args->name.name, args->name.len);
706 * struct renameargs {
711 static void nfs2_xdr_enc_renameargs(struct rpc_rqst *req,
712 struct xdr_stream *xdr,
715 const struct nfs_renameargs *args = data;
716 const struct qstr *old = args->old_name;
717 const struct qstr *new = args->new_name;
719 encode_diropargs(xdr, args->old_dir, old->name, old->len);
720 encode_diropargs(xdr, args->new_dir, new->name, new->len);
731 static void nfs2_xdr_enc_linkargs(struct rpc_rqst *req,
732 struct xdr_stream *xdr,
735 const struct nfs_linkargs *args = data;
737 encode_fhandle(xdr, args->fromfh);
738 encode_diropargs(xdr, args->tofh, args->toname, args->tolen);
742 * 2.2.14. symlinkargs
744 * struct symlinkargs {
750 static void nfs2_xdr_enc_symlinkargs(struct rpc_rqst *req,
751 struct xdr_stream *xdr,
754 const struct nfs_symlinkargs *args = data;
756 encode_diropargs(xdr, args->fromfh, args->fromname, args->fromlen);
757 encode_path(xdr, args->pages, args->pathlen);
758 encode_sattr(xdr, args->sattr, rpc_rqst_userns(req));
762 * 2.2.17. readdirargs
764 * struct readdirargs {
770 static void encode_readdirargs(struct xdr_stream *xdr,
771 const struct nfs_readdirargs *args)
775 encode_fhandle(xdr, args->fh);
777 p = xdr_reserve_space(xdr, 4 + 4);
778 *p++ = cpu_to_be32(args->cookie);
779 *p = cpu_to_be32(args->count);
782 static void nfs2_xdr_enc_readdirargs(struct rpc_rqst *req,
783 struct xdr_stream *xdr,
786 const struct nfs_readdirargs *args = data;
788 encode_readdirargs(xdr, args);
789 rpc_prepare_reply_pages(req, args->pages, 0,
790 args->count, NFS_readdirres_sz);
794 * NFSv2 XDR decode functions
796 * NFSv2 result types are defined in section 2.2 of RFC 1094:
797 * "NFS: Network File System Protocol Specification".
800 static int nfs2_xdr_dec_stat(struct rpc_rqst *req, struct xdr_stream *xdr,
803 enum nfs_stat status;
806 error = decode_stat(xdr, &status);
809 if (status != NFS_OK)
814 return nfs_stat_to_errno(status);
817 static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, struct xdr_stream *xdr,
820 return decode_attrstat(xdr, result, NULL, rpc_rqst_userns(req));
823 static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, struct xdr_stream *xdr,
826 return decode_diropres(xdr, result, rpc_rqst_userns(req));
832 * union readlinkres switch (stat status) {
839 static int nfs2_xdr_dec_readlinkres(struct rpc_rqst *req,
840 struct xdr_stream *xdr, void *__unused)
842 enum nfs_stat status;
845 error = decode_stat(xdr, &status);
848 if (status != NFS_OK)
850 error = decode_path(xdr);
854 return nfs_stat_to_errno(status);
860 * union readres switch (stat status) {
868 static int nfs2_xdr_dec_readres(struct rpc_rqst *req, struct xdr_stream *xdr,
871 struct nfs_pgio_res *result = data;
872 enum nfs_stat status;
875 error = decode_stat(xdr, &status);
878 result->op_status = status;
879 if (status != NFS_OK)
881 error = decode_fattr(xdr, result->fattr, rpc_rqst_userns(req));
884 error = decode_nfsdata(xdr, result);
888 return nfs_stat_to_errno(status);
891 static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, struct xdr_stream *xdr,
894 struct nfs_pgio_res *result = data;
896 /* All NFSv2 writes are "file sync" writes */
897 result->verf->committed = NFS_FILE_SYNC;
898 return decode_attrstat(xdr, result->fattr, &result->op_status,
899 rpc_rqst_userns(req));
903 * nfs2_decode_dirent - Decode a single NFSv2 directory entry stored in
904 * the local page cache.
905 * @xdr: XDR stream where entry resides
906 * @entry: buffer to fill in with entry data
907 * @plus: boolean indicating whether this should be a readdirplus entry
909 * Returns zero if successful, otherwise a negative errno value is
912 * This function is not invoked during READDIR reply decoding, but
913 * rather whenever an application invokes the getdents(2) system call
914 * on a directory already in our cache.
925 int nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
931 p = xdr_inline_decode(xdr, 4);
934 if (*p++ == xdr_zero) {
935 p = xdr_inline_decode(xdr, 4);
938 if (*p++ == xdr_zero)
944 p = xdr_inline_decode(xdr, 4);
947 entry->ino = be32_to_cpup(p);
949 error = decode_filename_inline(xdr, &entry->name, &entry->len);
954 * The type (size and byte order) of nfscookie isn't defined in
955 * RFC 1094. This implementation assumes that it's an XDR uint32.
957 entry->prev_cookie = entry->cookie;
958 p = xdr_inline_decode(xdr, 4);
961 entry->cookie = be32_to_cpup(p);
963 entry->d_type = DT_UNKNOWN;
971 * union readdirres switch (stat status) {
981 * Read the directory contents into the page cache, but don't
982 * touch them. The actual decoding is done by nfs2_decode_dirent()
983 * during subsequent nfs_readdir() calls.
985 static int decode_readdirok(struct xdr_stream *xdr)
987 return xdr_read_pages(xdr, xdr->buf->page_len);
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);
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);
1039 static int nfs2_xdr_dec_statfsres(struct rpc_rqst *req, struct xdr_stream *xdr,
1042 enum nfs_stat status;
1045 error = decode_stat(xdr, &status);
1046 if (unlikely(error))
1048 if (status != NFS_OK)
1050 error = decode_info(xdr, result);
1054 return nfs_stat_to_errno(status);
1059 * We need to translate between nfs status return values and
1060 * the local errno values which may not be the same.
1062 static const struct {
1067 { NFSERR_PERM, -EPERM },
1068 { NFSERR_NOENT, -ENOENT },
1069 { NFSERR_IO, -errno_NFSERR_IO},
1070 { NFSERR_NXIO, -ENXIO },
1071 /* { NFSERR_EAGAIN, -EAGAIN }, */
1072 { NFSERR_ACCES, -EACCES },
1073 { NFSERR_EXIST, -EEXIST },
1074 { NFSERR_XDEV, -EXDEV },
1075 { NFSERR_NODEV, -ENODEV },
1076 { NFSERR_NOTDIR, -ENOTDIR },
1077 { NFSERR_ISDIR, -EISDIR },
1078 { NFSERR_INVAL, -EINVAL },
1079 { NFSERR_FBIG, -EFBIG },
1080 { NFSERR_NOSPC, -ENOSPC },
1081 { NFSERR_ROFS, -EROFS },
1082 { NFSERR_MLINK, -EMLINK },
1083 { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
1084 { NFSERR_NOTEMPTY, -ENOTEMPTY },
1085 { NFSERR_DQUOT, -EDQUOT },
1086 { NFSERR_STALE, -ESTALE },
1087 { NFSERR_REMOTE, -EREMOTE },
1089 { NFSERR_WFLUSH, -EWFLUSH },
1091 { NFSERR_BADHANDLE, -EBADHANDLE },
1092 { NFSERR_NOT_SYNC, -ENOTSYNC },
1093 { NFSERR_BAD_COOKIE, -EBADCOOKIE },
1094 { NFSERR_NOTSUPP, -ENOTSUPP },
1095 { NFSERR_TOOSMALL, -ETOOSMALL },
1096 { NFSERR_SERVERFAULT, -EREMOTEIO },
1097 { NFSERR_BADTYPE, -EBADTYPE },
1098 { NFSERR_JUKEBOX, -EJUKEBOX },
1103 * nfs_stat_to_errno - convert an NFS status code to a local errno
1104 * @status: NFS status code to convert
1106 * Returns a local errno value, or -EIO if the NFS status code is
1107 * not recognized. This function is used jointly by NFSv2 and NFSv3.
1109 static int nfs_stat_to_errno(enum nfs_stat status)
1113 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
1114 if (nfs_errtbl[i].stat == (int)status)
1115 return nfs_errtbl[i].errno;
1117 dprintk("NFS: Unrecognized nfs status value: %u\n", status);
1118 return nfs_errtbl[i].errno;
1121 #define PROC(proc, argtype, restype, timer) \
1122 [NFSPROC_##proc] = { \
1123 .p_proc = NFSPROC_##proc, \
1124 .p_encode = nfs2_xdr_enc_##argtype, \
1125 .p_decode = nfs2_xdr_dec_##restype, \
1126 .p_arglen = NFS_##argtype##_sz, \
1127 .p_replen = NFS_##restype##_sz, \
1129 .p_statidx = NFSPROC_##proc, \
1132 const struct rpc_procinfo nfs_procedures[] = {
1133 PROC(GETATTR, fhandle, attrstat, 1),
1134 PROC(SETATTR, sattrargs, attrstat, 0),
1135 PROC(LOOKUP, diropargs, diropres, 2),
1136 PROC(READLINK, readlinkargs, readlinkres, 3),
1137 PROC(READ, readargs, readres, 3),
1138 PROC(WRITE, writeargs, writeres, 4),
1139 PROC(CREATE, createargs, diropres, 0),
1140 PROC(REMOVE, removeargs, stat, 0),
1141 PROC(RENAME, renameargs, stat, 0),
1142 PROC(LINK, linkargs, stat, 0),
1143 PROC(SYMLINK, symlinkargs, stat, 0),
1144 PROC(MKDIR, createargs, diropres, 0),
1145 PROC(RMDIR, diropargs, stat, 0),
1146 PROC(READDIR, readdirargs, readdirres, 3),
1147 PROC(STATFS, fhandle, statfsres, 0),
1150 static unsigned int nfs_version2_counts[ARRAY_SIZE(nfs_procedures)];
1151 const struct rpc_version nfs_version2 = {
1153 .nrprocs = ARRAY_SIZE(nfs_procedures),
1154 .procs = nfs_procedures,
1155 .counts = nfs_version2_counts,