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>
27 #define NFSDBG_FACILITY NFSDBG_XDR
29 /* Mapping from NFS error code to "errno" error code. */
30 #define errno_NFSERR_IO EIO
33 * Declare the space requirements for NFS arguments and replies as
34 * number of 32bit-words
36 #define NFS_fhandle_sz (8)
37 #define NFS_sattr_sz (8)
38 #define NFS_filename_sz (1+(NFS2_MAXNAMLEN>>2))
39 #define NFS_path_sz (1+(NFS2_MAXPATHLEN>>2))
40 #define NFS_fattr_sz (17)
41 #define NFS_info_sz (5)
42 #define NFS_entry_sz (NFS_filename_sz+3)
44 #define NFS_diropargs_sz (NFS_fhandle_sz+NFS_filename_sz)
45 #define NFS_removeargs_sz (NFS_fhandle_sz+NFS_filename_sz)
46 #define NFS_sattrargs_sz (NFS_fhandle_sz+NFS_sattr_sz)
47 #define NFS_readlinkargs_sz (NFS_fhandle_sz)
48 #define NFS_readargs_sz (NFS_fhandle_sz+3)
49 #define NFS_writeargs_sz (NFS_fhandle_sz+4)
50 #define NFS_createargs_sz (NFS_diropargs_sz+NFS_sattr_sz)
51 #define NFS_renameargs_sz (NFS_diropargs_sz+NFS_diropargs_sz)
52 #define NFS_linkargs_sz (NFS_fhandle_sz+NFS_diropargs_sz)
53 #define NFS_symlinkargs_sz (NFS_diropargs_sz+1+NFS_sattr_sz)
54 #define NFS_readdirargs_sz (NFS_fhandle_sz+2)
56 #define NFS_attrstat_sz (1+NFS_fattr_sz)
57 #define NFS_diropres_sz (1+NFS_fhandle_sz+NFS_fattr_sz)
58 #define NFS_readlinkres_sz (2)
59 #define NFS_readres_sz (1+NFS_fattr_sz+1)
60 #define NFS_writeres_sz (NFS_attrstat_sz)
61 #define NFS_stat_sz (1)
62 #define NFS_readdirres_sz (1)
63 #define NFS_statfsres_sz (1+NFS_info_sz)
65 static int nfs_stat_to_errno(enum nfs_stat);
68 * While encoding arguments, set up the reply buffer in advance to
69 * receive reply data directly into the page cache.
71 static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages,
72 unsigned int base, unsigned int len,
75 struct rpc_auth *auth = req->rq_cred->cr_auth;
78 replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize;
79 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len);
83 * Handle decode buffer overflows out-of-line.
85 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
87 dprintk("NFS: %s prematurely hit the end of our receive buffer. "
88 "Remaining buffer length is %tu words.\n",
89 func, xdr->end - xdr->p);
94 * Encode/decode NFSv2 basic data types
96 * Basic NFSv2 data types are defined in section 2.3 of RFC 1094:
97 * "NFS: Network File System Protocol Specification".
99 * Not all basic data types have their own encoding and decoding
100 * functions. For run-time efficiency, some data types are encoded
105 * typedef opaque nfsdata<>;
107 static int decode_nfsdata(struct xdr_stream *xdr, struct nfs_pgio_res *result)
112 p = xdr_inline_decode(xdr, 4);
113 if (unlikely(p == NULL))
115 count = be32_to_cpup(p);
116 recvd = xdr_read_pages(xdr, count);
117 if (unlikely(count > recvd))
120 result->eof = 0; /* NFSv2 does not pass EOF flag on the wire. */
121 result->count = count;
124 dprintk("NFS: server cheating in read result: "
125 "count %u > recvd %u\n", count, recvd);
129 print_overflow_msg(__func__, xdr);
143 * NFSERR_NOTDIR = 20,
148 * NFSERR_NAMETOOLONG = 63,
149 * NFSERR_NOTEMPTY = 66,
155 static int decode_stat(struct xdr_stream *xdr, enum nfs_stat *status)
159 p = xdr_inline_decode(xdr, 4);
160 if (unlikely(p == NULL))
162 *status = be32_to_cpup(p);
165 print_overflow_msg(__func__, xdr);
182 static __be32 *xdr_decode_ftype(__be32 *p, u32 *type)
184 *type = be32_to_cpup(p++);
185 if (unlikely(*type > NF2FIFO))
193 * typedef opaque fhandle[FHSIZE];
195 static void encode_fhandle(struct xdr_stream *xdr, const struct nfs_fh *fh)
199 p = xdr_reserve_space(xdr, NFS2_FHSIZE);
200 memcpy(p, fh->data, NFS2_FHSIZE);
203 static int decode_fhandle(struct xdr_stream *xdr, struct nfs_fh *fh)
207 p = xdr_inline_decode(xdr, NFS2_FHSIZE);
208 if (unlikely(p == NULL))
210 fh->size = NFS2_FHSIZE;
211 memcpy(fh->data, p, NFS2_FHSIZE);
214 print_overflow_msg(__func__, xdr);
222 * unsigned int seconds;
223 * unsigned int useconds;
226 static __be32 *xdr_encode_time(__be32 *p, const struct timespec *timep)
228 *p++ = cpu_to_be32(timep->tv_sec);
229 if (timep->tv_nsec != 0)
230 *p++ = cpu_to_be32(timep->tv_nsec / NSEC_PER_USEC);
232 *p++ = cpu_to_be32(0);
237 * Passing the invalid value useconds=1000000 is a Sun convention for
238 * "set to current server time". It's needed to make permissions checks
239 * for the "touch" program across v2 mounts to Solaris and Irix servers
240 * work correctly. See description of sattr in section 6.1 of "NFS
241 * Illustrated" by Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5.
243 static __be32 *xdr_encode_current_server_time(__be32 *p,
244 const struct timespec *timep)
246 *p++ = cpu_to_be32(timep->tv_sec);
247 *p++ = cpu_to_be32(1000000);
251 static __be32 *xdr_decode_time(__be32 *p, struct timespec *timep)
253 timep->tv_sec = be32_to_cpup(p++);
254 timep->tv_nsec = be32_to_cpup(p++) * NSEC_PER_USEC;
264 * unsigned int nlink;
268 * unsigned int blocksize;
270 * unsigned int blocks;
272 * unsigned int fileid;
279 static int decode_fattr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
284 p = xdr_inline_decode(xdr, NFS_fattr_sz << 2);
285 if (unlikely(p == NULL))
288 fattr->valid |= NFS_ATTR_FATTR_V2;
290 p = xdr_decode_ftype(p, &type);
292 fattr->mode = be32_to_cpup(p++);
293 fattr->nlink = be32_to_cpup(p++);
294 fattr->uid = make_kuid(&init_user_ns, be32_to_cpup(p++));
295 if (!uid_valid(fattr->uid))
297 fattr->gid = make_kgid(&init_user_ns, be32_to_cpup(p++));
298 if (!gid_valid(fattr->gid))
301 fattr->size = be32_to_cpup(p++);
302 fattr->du.nfs2.blocksize = be32_to_cpup(p++);
304 rdev = be32_to_cpup(p++);
305 fattr->rdev = new_decode_dev(rdev);
306 if (type == (u32)NFCHR && rdev == (u32)NFS2_FIFO_DEV) {
307 fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO;
311 fattr->du.nfs2.blocks = be32_to_cpup(p++);
312 fattr->fsid.major = be32_to_cpup(p++);
313 fattr->fsid.minor = 0;
314 fattr->fileid = be32_to_cpup(p++);
316 p = xdr_decode_time(p, &fattr->atime);
317 p = xdr_decode_time(p, &fattr->mtime);
318 xdr_decode_time(p, &fattr->ctime);
319 fattr->change_attr = nfs_timespec_to_change_attr(&fattr->ctime);
323 dprintk("NFS: returned invalid uid\n");
326 dprintk("NFS: returned invalid gid\n");
329 print_overflow_msg(__func__, xdr);
346 #define NFS2_SATTR_NOT_SET (0xffffffff)
348 static __be32 *xdr_time_not_set(__be32 *p)
350 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
351 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
355 static void encode_sattr(struct xdr_stream *xdr, const struct iattr *attr)
360 p = xdr_reserve_space(xdr, NFS_sattr_sz << 2);
362 if (attr->ia_valid & ATTR_MODE)
363 *p++ = cpu_to_be32(attr->ia_mode);
365 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
366 if (attr->ia_valid & ATTR_UID)
367 *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
369 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
370 if (attr->ia_valid & ATTR_GID)
371 *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
373 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
374 if (attr->ia_valid & ATTR_SIZE)
375 *p++ = cpu_to_be32((u32)attr->ia_size);
377 *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET);
379 if (attr->ia_valid & ATTR_ATIME_SET) {
380 ts = timespec64_to_timespec(attr->ia_atime);
381 p = xdr_encode_time(p, &ts);
382 } else if (attr->ia_valid & ATTR_ATIME) {
383 ts = timespec64_to_timespec(attr->ia_atime);
384 p = xdr_encode_current_server_time(p, &ts);
386 p = xdr_time_not_set(p);
387 if (attr->ia_valid & ATTR_MTIME_SET) {
388 ts = timespec64_to_timespec(attr->ia_mtime);
389 xdr_encode_time(p, &ts);
390 } else if (attr->ia_valid & ATTR_MTIME) {
391 ts = timespec64_to_timespec(attr->ia_mtime);
392 xdr_encode_current_server_time(p, &ts);
400 * typedef string filename<MAXNAMLEN>;
402 static void encode_filename(struct xdr_stream *xdr,
403 const char *name, u32 length)
407 WARN_ON_ONCE(length > NFS2_MAXNAMLEN);
408 p = xdr_reserve_space(xdr, 4 + length);
409 xdr_encode_opaque(p, name, length);
412 static int decode_filename_inline(struct xdr_stream *xdr,
413 const char **name, u32 *length)
418 p = xdr_inline_decode(xdr, 4);
419 if (unlikely(p == NULL))
421 count = be32_to_cpup(p);
422 if (count > NFS3_MAXNAMLEN)
423 goto out_nametoolong;
424 p = xdr_inline_decode(xdr, count);
425 if (unlikely(p == NULL))
427 *name = (const char *)p;
431 dprintk("NFS: returned filename too long: %u\n", count);
432 return -ENAMETOOLONG;
434 print_overflow_msg(__func__, xdr);
441 * typedef string path<MAXPATHLEN>;
443 static void encode_path(struct xdr_stream *xdr, struct page **pages, u32 length)
447 p = xdr_reserve_space(xdr, 4);
448 *p = cpu_to_be32(length);
449 xdr_write_pages(xdr, pages, 0, length);
452 static int decode_path(struct xdr_stream *xdr)
457 p = xdr_inline_decode(xdr, 4);
458 if (unlikely(p == NULL))
460 length = be32_to_cpup(p);
461 if (unlikely(length >= xdr->buf->page_len || length > NFS_MAXPATHLEN))
463 recvd = xdr_read_pages(xdr, length);
464 if (unlikely(length > recvd))
466 xdr_terminate_string(xdr->buf, length);
469 dprintk("NFS: returned pathname too long: %u\n", length);
470 return -ENAMETOOLONG;
472 dprintk("NFS: server cheating in pathname result: "
473 "length %u > received %u\n", length, recvd);
476 print_overflow_msg(__func__, xdr);
483 * union attrstat switch (stat status) {
490 static int decode_attrstat(struct xdr_stream *xdr, struct nfs_fattr *result,
493 enum nfs_stat status;
496 error = decode_stat(xdr, &status);
501 if (status != NFS_OK)
503 error = decode_fattr(xdr, result);
507 return nfs_stat_to_errno(status);
518 static void encode_diropargs(struct xdr_stream *xdr, const struct nfs_fh *fh,
519 const char *name, u32 length)
521 encode_fhandle(xdr, fh);
522 encode_filename(xdr, name, length);
528 * union diropres switch (stat status) {
538 static int decode_diropok(struct xdr_stream *xdr, struct nfs_diropok *result)
542 error = decode_fhandle(xdr, result->fh);
545 error = decode_fattr(xdr, result->fattr);
550 static int decode_diropres(struct xdr_stream *xdr, struct nfs_diropok *result)
552 enum nfs_stat status;
555 error = decode_stat(xdr, &status);
558 if (status != NFS_OK)
560 error = decode_diropok(xdr, result);
564 return nfs_stat_to_errno(status);
569 * NFSv2 XDR encode functions
571 * NFSv2 argument types are defined in section 2.2 of RFC 1094:
572 * "NFS: Network File System Protocol Specification".
575 static void nfs2_xdr_enc_fhandle(struct rpc_rqst *req,
576 struct xdr_stream *xdr,
579 const struct nfs_fh *fh = data;
581 encode_fhandle(xdr, fh);
592 static void nfs2_xdr_enc_sattrargs(struct rpc_rqst *req,
593 struct xdr_stream *xdr,
596 const struct nfs_sattrargs *args = data;
598 encode_fhandle(xdr, args->fh);
599 encode_sattr(xdr, args->sattr);
602 static void nfs2_xdr_enc_diropargs(struct rpc_rqst *req,
603 struct xdr_stream *xdr,
606 const struct nfs_diropargs *args = data;
608 encode_diropargs(xdr, args->fh, args->name, args->len);
611 static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst *req,
612 struct xdr_stream *xdr,
615 const struct nfs_readlinkargs *args = data;
617 encode_fhandle(xdr, args->fh);
618 prepare_reply_buffer(req, args->pages, args->pgbase,
619 args->pglen, NFS_readlinkres_sz);
629 * unsigned totalcount;
632 static void encode_readargs(struct xdr_stream *xdr,
633 const struct nfs_pgio_args *args)
635 u32 offset = args->offset;
636 u32 count = args->count;
639 encode_fhandle(xdr, args->fh);
641 p = xdr_reserve_space(xdr, 4 + 4 + 4);
642 *p++ = cpu_to_be32(offset);
643 *p++ = cpu_to_be32(count);
644 *p = cpu_to_be32(count);
647 static void nfs2_xdr_enc_readargs(struct rpc_rqst *req,
648 struct xdr_stream *xdr,
651 const struct nfs_pgio_args *args = data;
653 encode_readargs(xdr, args);
654 prepare_reply_buffer(req, args->pages, args->pgbase,
655 args->count, NFS_readres_sz);
656 req->rq_rcv_buf.flags |= XDRBUF_READ;
664 * unsigned beginoffset;
666 * unsigned totalcount;
670 static void encode_writeargs(struct xdr_stream *xdr,
671 const struct nfs_pgio_args *args)
673 u32 offset = args->offset;
674 u32 count = args->count;
677 encode_fhandle(xdr, args->fh);
679 p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4);
680 *p++ = cpu_to_be32(offset);
681 *p++ = cpu_to_be32(offset);
682 *p++ = cpu_to_be32(count);
685 *p = cpu_to_be32(count);
686 xdr_write_pages(xdr, args->pages, args->pgbase, count);
689 static void nfs2_xdr_enc_writeargs(struct rpc_rqst *req,
690 struct xdr_stream *xdr,
693 const struct nfs_pgio_args *args = data;
695 encode_writeargs(xdr, args);
696 xdr->buf->flags |= XDRBUF_WRITE;
702 * struct createargs {
707 static void nfs2_xdr_enc_createargs(struct rpc_rqst *req,
708 struct xdr_stream *xdr,
711 const struct nfs_createargs *args = data;
713 encode_diropargs(xdr, args->fh, args->name, args->len);
714 encode_sattr(xdr, args->sattr);
717 static void nfs2_xdr_enc_removeargs(struct rpc_rqst *req,
718 struct xdr_stream *xdr,
721 const struct nfs_removeargs *args = data;
723 encode_diropargs(xdr, args->fh, args->name.name, args->name.len);
729 * struct renameargs {
734 static void nfs2_xdr_enc_renameargs(struct rpc_rqst *req,
735 struct xdr_stream *xdr,
738 const struct nfs_renameargs *args = data;
739 const struct qstr *old = args->old_name;
740 const struct qstr *new = args->new_name;
742 encode_diropargs(xdr, args->old_dir, old->name, old->len);
743 encode_diropargs(xdr, args->new_dir, new->name, new->len);
754 static void nfs2_xdr_enc_linkargs(struct rpc_rqst *req,
755 struct xdr_stream *xdr,
758 const struct nfs_linkargs *args = data;
760 encode_fhandle(xdr, args->fromfh);
761 encode_diropargs(xdr, args->tofh, args->toname, args->tolen);
765 * 2.2.14. symlinkargs
767 * struct symlinkargs {
773 static void nfs2_xdr_enc_symlinkargs(struct rpc_rqst *req,
774 struct xdr_stream *xdr,
777 const struct nfs_symlinkargs *args = data;
779 encode_diropargs(xdr, args->fromfh, args->fromname, args->fromlen);
780 encode_path(xdr, args->pages, args->pathlen);
781 encode_sattr(xdr, args->sattr);
785 * 2.2.17. readdirargs
787 * struct readdirargs {
793 static void encode_readdirargs(struct xdr_stream *xdr,
794 const struct nfs_readdirargs *args)
798 encode_fhandle(xdr, args->fh);
800 p = xdr_reserve_space(xdr, 4 + 4);
801 *p++ = cpu_to_be32(args->cookie);
802 *p = cpu_to_be32(args->count);
805 static void nfs2_xdr_enc_readdirargs(struct rpc_rqst *req,
806 struct xdr_stream *xdr,
809 const struct nfs_readdirargs *args = data;
811 encode_readdirargs(xdr, args);
812 prepare_reply_buffer(req, args->pages, 0,
813 args->count, NFS_readdirres_sz);
817 * NFSv2 XDR decode functions
819 * NFSv2 result types are defined in section 2.2 of RFC 1094:
820 * "NFS: Network File System Protocol Specification".
823 static int nfs2_xdr_dec_stat(struct rpc_rqst *req, struct xdr_stream *xdr,
826 enum nfs_stat status;
829 error = decode_stat(xdr, &status);
832 if (status != NFS_OK)
837 return nfs_stat_to_errno(status);
840 static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, struct xdr_stream *xdr,
843 return decode_attrstat(xdr, result, NULL);
846 static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, struct xdr_stream *xdr,
849 return decode_diropres(xdr, result);
855 * union readlinkres switch (stat status) {
862 static int nfs2_xdr_dec_readlinkres(struct rpc_rqst *req,
863 struct xdr_stream *xdr, void *__unused)
865 enum nfs_stat status;
868 error = decode_stat(xdr, &status);
871 if (status != NFS_OK)
873 error = decode_path(xdr);
877 return nfs_stat_to_errno(status);
883 * union readres switch (stat status) {
891 static int nfs2_xdr_dec_readres(struct rpc_rqst *req, struct xdr_stream *xdr,
894 struct nfs_pgio_res *result = data;
895 enum nfs_stat status;
898 error = decode_stat(xdr, &status);
901 result->op_status = status;
902 if (status != NFS_OK)
904 error = decode_fattr(xdr, result->fattr);
907 error = decode_nfsdata(xdr, result);
911 return nfs_stat_to_errno(status);
914 static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, struct xdr_stream *xdr,
917 struct nfs_pgio_res *result = data;
919 /* All NFSv2 writes are "file sync" writes */
920 result->verf->committed = NFS_FILE_SYNC;
921 return decode_attrstat(xdr, result->fattr, &result->op_status);
925 * nfs2_decode_dirent - Decode a single NFSv2 directory entry stored in
926 * the local page cache.
927 * @xdr: XDR stream where entry resides
928 * @entry: buffer to fill in with entry data
929 * @plus: boolean indicating whether this should be a readdirplus entry
931 * Returns zero if successful, otherwise a negative errno value is
934 * This function is not invoked during READDIR reply decoding, but
935 * rather whenever an application invokes the getdents(2) system call
936 * on a directory already in our cache.
947 int nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
953 p = xdr_inline_decode(xdr, 4);
954 if (unlikely(p == NULL))
956 if (*p++ == xdr_zero) {
957 p = xdr_inline_decode(xdr, 4);
958 if (unlikely(p == NULL))
960 if (*p++ == xdr_zero)
966 p = xdr_inline_decode(xdr, 4);
967 if (unlikely(p == NULL))
969 entry->ino = be32_to_cpup(p);
971 error = decode_filename_inline(xdr, &entry->name, &entry->len);
976 * The type (size and byte order) of nfscookie isn't defined in
977 * RFC 1094. This implementation assumes that it's an XDR uint32.
979 entry->prev_cookie = entry->cookie;
980 p = xdr_inline_decode(xdr, 4);
981 if (unlikely(p == NULL))
983 entry->cookie = be32_to_cpup(p);
985 entry->d_type = DT_UNKNOWN;
990 print_overflow_msg(__func__, xdr);
997 * union readdirres switch (stat status) {
1007 * Read the directory contents into the page cache, but don't
1008 * touch them. The actual decoding is done by nfs2_decode_dirent()
1009 * during subsequent nfs_readdir() calls.
1011 static int decode_readdirok(struct xdr_stream *xdr)
1013 return xdr_read_pages(xdr, xdr->buf->page_len);
1016 static int nfs2_xdr_dec_readdirres(struct rpc_rqst *req,
1017 struct xdr_stream *xdr, void *__unused)
1019 enum nfs_stat status;
1022 error = decode_stat(xdr, &status);
1023 if (unlikely(error))
1025 if (status != NFS_OK)
1027 error = decode_readdirok(xdr);
1031 return nfs_stat_to_errno(status);
1037 * union statfsres (stat status) {
1050 static int decode_info(struct xdr_stream *xdr, struct nfs2_fsstat *result)
1054 p = xdr_inline_decode(xdr, NFS_info_sz << 2);
1055 if (unlikely(p == NULL))
1057 result->tsize = be32_to_cpup(p++);
1058 result->bsize = be32_to_cpup(p++);
1059 result->blocks = be32_to_cpup(p++);
1060 result->bfree = be32_to_cpup(p++);
1061 result->bavail = be32_to_cpup(p);
1064 print_overflow_msg(__func__, xdr);
1068 static int nfs2_xdr_dec_statfsres(struct rpc_rqst *req, struct xdr_stream *xdr,
1071 enum nfs_stat status;
1074 error = decode_stat(xdr, &status);
1075 if (unlikely(error))
1077 if (status != NFS_OK)
1079 error = decode_info(xdr, result);
1083 return nfs_stat_to_errno(status);
1088 * We need to translate between nfs status return values and
1089 * the local errno values which may not be the same.
1091 static const struct {
1096 { NFSERR_PERM, -EPERM },
1097 { NFSERR_NOENT, -ENOENT },
1098 { NFSERR_IO, -errno_NFSERR_IO},
1099 { NFSERR_NXIO, -ENXIO },
1100 /* { NFSERR_EAGAIN, -EAGAIN }, */
1101 { NFSERR_ACCES, -EACCES },
1102 { NFSERR_EXIST, -EEXIST },
1103 { NFSERR_XDEV, -EXDEV },
1104 { NFSERR_NODEV, -ENODEV },
1105 { NFSERR_NOTDIR, -ENOTDIR },
1106 { NFSERR_ISDIR, -EISDIR },
1107 { NFSERR_INVAL, -EINVAL },
1108 { NFSERR_FBIG, -EFBIG },
1109 { NFSERR_NOSPC, -ENOSPC },
1110 { NFSERR_ROFS, -EROFS },
1111 { NFSERR_MLINK, -EMLINK },
1112 { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
1113 { NFSERR_NOTEMPTY, -ENOTEMPTY },
1114 { NFSERR_DQUOT, -EDQUOT },
1115 { NFSERR_STALE, -ESTALE },
1116 { NFSERR_REMOTE, -EREMOTE },
1118 { NFSERR_WFLUSH, -EWFLUSH },
1120 { NFSERR_BADHANDLE, -EBADHANDLE },
1121 { NFSERR_NOT_SYNC, -ENOTSYNC },
1122 { NFSERR_BAD_COOKIE, -EBADCOOKIE },
1123 { NFSERR_NOTSUPP, -ENOTSUPP },
1124 { NFSERR_TOOSMALL, -ETOOSMALL },
1125 { NFSERR_SERVERFAULT, -EREMOTEIO },
1126 { NFSERR_BADTYPE, -EBADTYPE },
1127 { NFSERR_JUKEBOX, -EJUKEBOX },
1132 * nfs_stat_to_errno - convert an NFS status code to a local errno
1133 * @status: NFS status code to convert
1135 * Returns a local errno value, or -EIO if the NFS status code is
1136 * not recognized. This function is used jointly by NFSv2 and NFSv3.
1138 static int nfs_stat_to_errno(enum nfs_stat status)
1142 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
1143 if (nfs_errtbl[i].stat == (int)status)
1144 return nfs_errtbl[i].errno;
1146 dprintk("NFS: Unrecognized nfs status value: %u\n", status);
1147 return nfs_errtbl[i].errno;
1150 #define PROC(proc, argtype, restype, timer) \
1151 [NFSPROC_##proc] = { \
1152 .p_proc = NFSPROC_##proc, \
1153 .p_encode = nfs2_xdr_enc_##argtype, \
1154 .p_decode = nfs2_xdr_dec_##restype, \
1155 .p_arglen = NFS_##argtype##_sz, \
1156 .p_replen = NFS_##restype##_sz, \
1158 .p_statidx = NFSPROC_##proc, \
1161 const struct rpc_procinfo nfs_procedures[] = {
1162 PROC(GETATTR, fhandle, attrstat, 1),
1163 PROC(SETATTR, sattrargs, attrstat, 0),
1164 PROC(LOOKUP, diropargs, diropres, 2),
1165 PROC(READLINK, readlinkargs, readlinkres, 3),
1166 PROC(READ, readargs, readres, 3),
1167 PROC(WRITE, writeargs, writeres, 4),
1168 PROC(CREATE, createargs, diropres, 0),
1169 PROC(REMOVE, removeargs, stat, 0),
1170 PROC(RENAME, renameargs, stat, 0),
1171 PROC(LINK, linkargs, stat, 0),
1172 PROC(SYMLINK, symlinkargs, stat, 0),
1173 PROC(MKDIR, createargs, diropres, 0),
1174 PROC(RMDIR, diropargs, stat, 0),
1175 PROC(READDIR, readdirargs, readdirres, 3),
1176 PROC(STATFS, fhandle, statfsres, 0),
1179 static unsigned int nfs_version2_counts[ARRAY_SIZE(nfs_procedures)];
1180 const struct rpc_version nfs_version2 = {
1182 .nrprocs = ARRAY_SIZE(nfs_procedures),
1183 .procs = nfs_procedures,
1184 .counts = nfs_version2_counts,