13 #include <linux/time.h>
15 #include <linux/errno.h>
16 #include <linux/string.h>
21 #include <linux/nfs.h>
23 #include <linux/nfs_fs.h>
26 #define NFSDBG_FACILITY NFSDBG_XDR
29 #define errno_NFSERR_IO EIO
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);
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;
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);
123 dprintk(
"NFS: server cheating in read result: "
124 "count %u > recvd %u\n", count, recvd);
128 print_overflow_msg(__func__, xdr);
154 static int decode_stat(
struct xdr_stream *xdr,
enum nfs_stat *
status)
164 print_overflow_msg(__func__, xdr);
194 static void encode_fhandle(
struct xdr_stream *xdr,
const struct nfs_fh *fh)
203 static int decode_fhandle(
struct xdr_stream *xdr,
struct nfs_fh *fh)
214 print_overflow_msg(__func__, xdr);
243 static __be32 *xdr_encode_current_server_time(
__be32 *p,
279 static int decode_fattr(
struct xdr_stream *xdr,
struct nfs_fattr *fattr)
290 p = xdr_decode_ftype(p, &type);
300 fattr->
rdev = new_decode_dev(rdev);
308 fattr->
fsid.minor = 0;
311 p = xdr_decode_time(p, &fattr->
atime);
312 p = xdr_decode_time(p, &fattr->
mtime);
313 xdr_decode_time(p, &fattr->
ctime);
318 print_overflow_msg(__func__, xdr);
335 #define NFS2_SATTR_NOT_SET (0xffffffff)
344 static void encode_sattr(
struct xdr_stream *xdr,
const struct iattr *
attr)
368 p = xdr_encode_time(p, &attr->
ia_atime);
370 p = xdr_encode_current_server_time(p, &attr->
ia_atime);
372 p = xdr_time_not_set(p);
374 xdr_encode_time(p, &attr->
ia_mtime);
376 xdr_encode_current_server_time(p, &attr->
ia_mtime);
386 static void encode_filename(
struct xdr_stream *xdr,
396 static int decode_filename_inline(
struct xdr_stream *xdr,
407 goto out_nametoolong;
411 *name = (
const char *)p;
415 dprintk(
"NFS: returned filename too long: %u\n", count);
418 print_overflow_msg(__func__, xdr);
427 static void encode_path(
struct xdr_stream *xdr,
struct page **
pages,
u32 length)
437 static int decode_path(
struct xdr_stream *xdr)
454 dprintk(
"NFS: returned pathname too long: %u\n", length);
457 dprintk(
"NFS: server cheating in pathname result: "
458 "length %u > received %u\n", length, recvd);
461 print_overflow_msg(__func__, xdr);
475 static int decode_attrstat(
struct xdr_stream *xdr,
struct nfs_fattr *result)
480 error = decode_stat(xdr, &status);
485 error = decode_fattr(xdr, result);
489 return nfs_stat_to_errno(status);
500 static void encode_diropargs(
struct xdr_stream *xdr,
const struct nfs_fh *fh,
501 const char *name,
u32 length)
503 encode_fhandle(xdr, fh);
504 encode_filename(xdr, name, length);
520 static int decode_diropok(
struct xdr_stream *xdr,
struct nfs_diropok *result)
524 error = decode_fhandle(xdr, result->
fh);
527 error = decode_fattr(xdr, result->
fattr);
532 static int decode_diropres(
struct xdr_stream *xdr,
struct nfs_diropok *result)
537 error = decode_stat(xdr, &status);
542 error = decode_diropok(xdr, result);
546 return nfs_stat_to_errno(status);
557 static void nfs2_xdr_enc_fhandle(
struct rpc_rqst *
req,
558 struct xdr_stream *xdr,
561 encode_fhandle(xdr, fh);
572 static void nfs2_xdr_enc_sattrargs(
struct rpc_rqst *
req,
573 struct xdr_stream *xdr,
576 encode_fhandle(xdr, args->
fh);
577 encode_sattr(xdr, args->
sattr);
580 static void nfs2_xdr_enc_diropargs(
struct rpc_rqst *
req,
581 struct xdr_stream *xdr,
584 encode_diropargs(xdr, args->
fh, args->
name, args->
len);
587 static void nfs2_xdr_enc_readlinkargs(
struct rpc_rqst *
req,
588 struct xdr_stream *xdr,
591 encode_fhandle(xdr, args->
fh);
592 prepare_reply_buffer(req, args->
pages, args->
pgbase,
606 static void encode_readargs(
struct xdr_stream *xdr,
613 encode_fhandle(xdr, args->
fh);
621 static void nfs2_xdr_enc_readargs(
struct rpc_rqst *
req,
622 struct xdr_stream *xdr,
625 encode_readargs(xdr, args);
626 prepare_reply_buffer(req, args->
pages, args->
pgbase,
628 req->rq_rcv_buf.flags |= XDRBUF_READ;
642 static void encode_writeargs(
struct xdr_stream *xdr,
649 encode_fhandle(xdr, args->
fh);
661 static void nfs2_xdr_enc_writeargs(
struct rpc_rqst *
req,
662 struct xdr_stream *xdr,
665 encode_writeargs(xdr, args);
666 xdr->buf->flags |= XDRBUF_WRITE;
677 static void nfs2_xdr_enc_createargs(
struct rpc_rqst *
req,
678 struct xdr_stream *xdr,
681 encode_diropargs(xdr, args->
fh, args->
name, args->
len);
682 encode_sattr(xdr, args->
sattr);
685 static void nfs2_xdr_enc_removeargs(
struct rpc_rqst *
req,
686 struct xdr_stream *xdr,
689 encode_diropargs(xdr, args->
fh, args->
name.name, args->
name.len);
700 static void nfs2_xdr_enc_renameargs(
struct rpc_rqst *
req,
701 struct xdr_stream *xdr,
707 encode_diropargs(xdr, args->
old_dir, old->
name, old->len);
708 encode_diropargs(xdr, args->
new_dir, new->name, new->len);
719 static void nfs2_xdr_enc_linkargs(
struct rpc_rqst *
req,
720 struct xdr_stream *xdr,
723 encode_fhandle(xdr, args->
fromfh);
736 static void nfs2_xdr_enc_symlinkargs(
struct rpc_rqst *
req,
737 struct xdr_stream *xdr,
742 encode_sattr(xdr, args->
sattr);
754 static void encode_readdirargs(
struct xdr_stream *xdr,
759 encode_fhandle(xdr, args->
fh);
766 static void nfs2_xdr_enc_readdirargs(
struct rpc_rqst *
req,
767 struct xdr_stream *xdr,
770 encode_readdirargs(xdr, args);
771 prepare_reply_buffer(req, args->
pages, 0,
782 static int nfs2_xdr_dec_stat(
struct rpc_rqst *
req,
struct xdr_stream *xdr,
788 error = decode_stat(xdr, &status);
796 return nfs_stat_to_errno(status);
799 static int nfs2_xdr_dec_attrstat(
struct rpc_rqst *req,
struct xdr_stream *xdr,
802 return decode_attrstat(xdr, result);
805 static int nfs2_xdr_dec_diropres(
struct rpc_rqst *req,
struct xdr_stream *xdr,
808 return decode_diropres(xdr, result);
821 static int nfs2_xdr_dec_readlinkres(
struct rpc_rqst *req,
822 struct xdr_stream *xdr,
void *__unused)
827 error = decode_stat(xdr, &status);
832 error = decode_path(xdr);
836 return nfs_stat_to_errno(status);
850 static int nfs2_xdr_dec_readres(
struct rpc_rqst *req,
struct xdr_stream *xdr,
856 error = decode_stat(xdr, &status);
861 error = decode_fattr(xdr, result->
fattr);
864 error = decode_nfsdata(xdr, result);
868 return nfs_stat_to_errno(status);
871 static int nfs2_xdr_dec_writeres(
struct rpc_rqst *req,
struct xdr_stream *xdr,
876 return decode_attrstat(xdr, result->
fattr);
911 if (*p++ == xdr_zero) {
915 if (*p++ == xdr_zero)
926 error = decode_filename_inline(xdr, &entry->
name, &entry->
len);
945 print_overflow_msg(__func__, xdr);
966 static int decode_readdirok(
struct xdr_stream *xdr)
971 static int nfs2_xdr_dec_readdirres(
struct rpc_rqst *req,
972 struct xdr_stream *xdr,
void *__unused)
977 error = decode_stat(xdr, &status);
982 error = decode_readdirok(xdr);
986 return nfs_stat_to_errno(status);
1005 static int decode_info(
struct xdr_stream *xdr,
struct nfs2_fsstat *result)
1019 print_overflow_msg(__func__, xdr);
1023 static int nfs2_xdr_dec_statfsres(
struct rpc_rqst *req,
struct xdr_stream *xdr,
1029 error = decode_stat(xdr, &status);
1034 error = decode_info(xdr, result);
1038 return nfs_stat_to_errno(status);
1046 static const struct {
1093 static int nfs_stat_to_errno(
enum nfs_stat status)
1097 for (i = 0; nfs_errtbl[
i].stat != -1; i++) {
1098 if (nfs_errtbl[i].
stat == (
int)status)
1099 return nfs_errtbl[
i].errno;
1101 dprintk(
"NFS: Unrecognized nfs status value: %u\n", status);
1102 return nfs_errtbl[
i].errno;
1105 #define PROC(proc, argtype, restype, timer) \
1106 [NFSPROC_##proc] = { \
1107 .p_proc = NFSPROC_##proc, \
1108 .p_encode = (kxdreproc_t)nfs2_xdr_enc_##argtype, \
1109 .p_decode = (kxdrdproc_t)nfs2_xdr_dec_##restype, \
1110 .p_arglen = NFS_##argtype##_sz, \
1111 .p_replen = NFS_##restype##_sz, \
1113 .p_statidx = NFSPROC_##proc, \
1117 PROC(GETATTR, fhandle, attrstat, 1),
1118 PROC(SETATTR, sattrargs, attrstat, 0),
1119 PROC(LOOKUP, diropargs, diropres, 2),
1120 PROC(READLINK, readlinkargs, readlinkres, 3),
1127 PROC(SYMLINK, symlinkargs,
stat, 0),
1128 PROC(MKDIR, createargs, diropres, 0),
1130 PROC(READDIR, readdirargs, readdirres, 3),
1131 PROC(STATFS, fhandle, statfsres, 0),
1137 .procs = nfs_procedures