11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
29605a069f83d999e60cd57dc8010708fe08291c0Chuck Lever * XDR standard data types and function declarations
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
59605a069f83d999e60cd57dc8010708fe08291c0Chuck Lever *
69605a069f83d999e60cd57dc8010708fe08291c0Chuck Lever * Based on:
79605a069f83d999e60cd57dc8010708fe08291c0Chuck Lever *   RFC 4506 "XDR: External Data Representation Standard", May 2006
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef _SUNRPC_XDR_H_
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _SUNRPC_XDR_H_
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef __KERNEL__
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/uio.h>
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/byteorder.h>
1797363c6a4f93a20380b4a9e11f35e27fed68a517Benny Halevy#include <asm/unaligned.h>
1837a4e6cb0391f2293ba3d59e3a63ec0e56ed720dOlga Kornievskaia#include <linux/scatterlist.h>
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Buffer adjustment
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define XDR_QUADLEN(l)		(((l) + 3) >> 2)
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Generic opaque `network object.' At the kernel level, this type
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * is used only by lockd.
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define XDR_MAX_NETOBJ		1024
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct xdr_netobj {
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int		len;
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u8 *			data;
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
369f06c719f474be7003763284a990bed6377bb0d4Chuck Lever * This is the legacy generic XDR function. rqstp is either a rpc_rqst
379f06c719f474be7003763284a990bed6377bb0d4Chuck Lever * (client side) or svc_rqst pointer (server side).
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Encode functions always assume there's enough room in the buffer.
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
40d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyantypedef int	(*kxdrproc_t)(void *rqstp, __be32 *data, void *obj);
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Basic structure for transmission/reception of a client XDR message.
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Features a header (for a linear buffer containing RPC headers
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and the data payload for short messages), and then an array of
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * pages.
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The tail iovec allows you to append data after the page array. Its
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * main interest is for appending padding to the pages in order to
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * satisfy the int_32-alignment requirements in RFC1832.
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * For the future, we might want to string several of these together
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * in a list if anybody wants to make use of NFSv4 COMPOUND
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * operations and/or has a need for scatter/gather involving pages.
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct xdr_buf {
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct kvec	head[1],	/* RPC header + non-page data */
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			tail[1];	/* Appended after page data */
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
59de0b65ca55dc62b6b477f6e02088df2281da7b51Jeff Layton	struct page **	pages;		/* Array of pages */
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int	page_base,	/* Start of page data */
614f22ccc3460ef65e9899ec271d36fc4ef795c68d\"Talpey, Thomas\			page_len,	/* Length of page data */
624f22ccc3460ef65e9899ec271d36fc4ef795c68d\"Talpey, Thomas\			flags;		/* Flags for data disposition */
634f22ccc3460ef65e9899ec271d36fc4ef795c68d\"Talpey, Thomas\#define XDRBUF_READ		0x01		/* target of file read */
644f22ccc3460ef65e9899ec271d36fc4ef795c68d\"Talpey, Thomas\#define XDRBUF_WRITE		0x02		/* source of file write */
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int	buflen,		/* Total length of storage buffer */
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			len;		/* Length of XDR encoded message */
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * pre-xdr'ed macros.
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7477f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	xdr_zero	cpu_to_be32(0)
7577f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	xdr_one		cpu_to_be32(1)
7677f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	xdr_two		cpu_to_be32(2)
7777f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison
7877f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_success		cpu_to_be32(RPC_SUCCESS)
7977f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_prog_unavail	cpu_to_be32(RPC_PROG_UNAVAIL)
8077f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_prog_mismatch	cpu_to_be32(RPC_PROG_MISMATCH)
8177f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_proc_unavail	cpu_to_be32(RPC_PROC_UNAVAIL)
8277f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_garbage_args	cpu_to_be32(RPC_GARBAGE_ARGS)
8377f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_system_err		cpu_to_be32(RPC_SYSTEM_ERR)
8477f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_drop_reply		cpu_to_be32(RPC_DROP_REPLY)
8577f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison
8677f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_auth_ok		cpu_to_be32(RPC_AUTH_OK)
8777f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_autherr_badcred	cpu_to_be32(RPC_AUTH_BADCRED)
8877f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_autherr_rejectedcred cpu_to_be32(RPC_AUTH_REJECTEDCRED)
8977f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_autherr_badverf	cpu_to_be32(RPC_AUTH_BADVERF)
9077f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_autherr_rejectedverf cpu_to_be32(RPC_AUTH_REJECTEDVERF)
9177f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_autherr_tooweak	cpu_to_be32(RPC_AUTH_TOOWEAK)
9277f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpcsec_gsserr_credproblem	cpu_to_be32(RPCSEC_GSS_CREDPROBLEM)
9377f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpcsec_gsserr_ctxproblem	cpu_to_be32(RPCSEC_GSS_CTXPROBLEM)
9477f18f5e4ebdea35ec3d92343b0ed7546dc87637Harvey Harrison#define	rpc_autherr_oldseqnum	cpu_to_be32(101)
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Miscellaneous XDR helper functions
981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
99d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan__be32 *xdr_encode_opaque_fixed(__be32 *p, const void *ptr, unsigned int len);
100d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan__be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int len);
101d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan__be32 *xdr_encode_string(__be32 *p, const char *s);
102e5cff482c78a35b9f149a06aa777a1bd693864fbChuck Lever__be32 *xdr_decode_string_inplace(__be32 *p, char **sp, unsigned int *lenp,
103e5cff482c78a35b9f149a06aa777a1bd693864fbChuck Lever			unsigned int maxlen);
104d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan__be32 *xdr_encode_netobj(__be32 *p, const struct xdr_netobj *);
105d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan__be32 *xdr_decode_netobj(__be32 *p, struct xdr_netobj *);
1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid	xdr_inline_pages(struct xdr_buf *, unsigned int,
1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 struct page **, unsigned int, unsigned int);
109b4687da7fc5f741af7fee9b0248a2cf2ad9c4478Chuck Levervoid	xdr_terminate_string(struct xdr_buf *, const u32);
1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
111d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanstatic inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int len)
1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return xdr_encode_opaque(p, s, len);
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Decode 64bit quantities (NFSv3 support)
1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
119d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanstatic inline __be32 *
120d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanxdr_encode_hyper(__be32 *p, __u64 val)
1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
12297363c6a4f93a20380b4a9e11f35e27fed68a517Benny Halevy	put_unaligned_be64(val, p);
1239f162d2a810b4db48f7b8d7e734d0932c81ec2a1Benny Halevy	return p + 2;
1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
126d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanstatic inline __be32 *
127d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanxdr_decode_hyper(__be32 *p, __u64 *valp)
1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
12997363c6a4f93a20380b4a9e11f35e27fed68a517Benny Halevy	*valp = get_unaligned_be64(p);
13098866b5abe1513cdacc011874ca045d40002eccdBenny Halevy	return p + 2;
1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
13335b61e63323ccf5fdcdd74b11751b58392c9cce1Benny Halevystatic inline __be32 *
13435b61e63323ccf5fdcdd74b11751b58392c9cce1Benny Halevyxdr_decode_opaque_fixed(__be32 *p, void *ptr, unsigned int len)
13535b61e63323ccf5fdcdd74b11751b58392c9cce1Benny Halevy{
13635b61e63323ccf5fdcdd74b11751b58392c9cce1Benny Halevy	memcpy(ptr, p, len);
13735b61e63323ccf5fdcdd74b11751b58392c9cce1Benny Halevy	return p + XDR_QUADLEN(len);
13835b61e63323ccf5fdcdd74b11751b58392c9cce1Benny Halevy}
13935b61e63323ccf5fdcdd74b11751b58392c9cce1Benny Halevy
1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Adjust kvec to reflect end of xdr'ed data (RPC client XDR)
1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int
144d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanxdr_adjust_iovec(struct kvec *iov, __be32 *p)
1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return iov->iov_len = ((u8 *) p - (u8 *) iov->iov_base);
1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * XDR buffer helper functions
1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void xdr_shift_buf(struct xdr_buf *, size_t);
1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void xdr_buf_from_iov(struct kvec *, struct xdr_buf *);
1541e78957e0a8f882df6a3660b62f9aae441f54891Trond Myklebustextern int xdr_buf_subsegment(struct xdr_buf *, struct xdr_buf *, unsigned int, unsigned int);
1554c190e2f913f038c9c91ee63b59cd037260ba353Jeff Laytonextern void xdr_buf_trim(struct xdr_buf *, unsigned int);
1561e78957e0a8f882df6a3660b62f9aae441f54891Trond Myklebustextern int xdr_buf_read_netobj(struct xdr_buf *, struct xdr_netobj *, unsigned int);
1571e78957e0a8f882df6a3660b62f9aae441f54891Trond Myklebustextern int read_bytes_from_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
1581e78957e0a8f882df6a3660b62f9aae441f54891Trond Myklebustextern int write_bytes_to_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Helper structure for copying from an sk_buff.
1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
163dd4564715eae2c4136f278da9ae1c3bb5af3e509Chuck Leverstruct xdr_skb_reader {
1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct sk_buff	*skb;
1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int	offset;
1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	size_t		count;
16744bb93633f57a55979f3c2589b10fd6a2bfc7c08Al Viro	__wsum		csum;
168dd4564715eae2c4136f278da9ae1c3bb5af3e509Chuck Lever};
1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
170dd4564715eae2c4136f278da9ae1c3bb5af3e509Chuck Levertypedef size_t (*xdr_skb_read_actor)(struct xdr_skb_reader *desc, void *to, size_t len);
1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
172dd4564715eae2c4136f278da9ae1c3bb5af3e509Chuck Leversize_t xdr_skb_read_bits(struct xdr_skb_reader *desc, void *to, size_t len);
173094bb20b9fcab3a1652a77741caba6b78097d622Chuck Leverextern int csum_partial_copy_to_xdr(struct xdr_buf *, struct sk_buff *);
1747e06b53d796a3740307b54aa2799077f8a0c84e7Trond Myklebustextern ssize_t xdr_partial_copy_from_skb(struct xdr_buf *, unsigned int,
175dd4564715eae2c4136f278da9ae1c3bb5af3e509Chuck Lever		struct xdr_skb_reader *, xdr_skb_read_actor);
1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1771e78957e0a8f882df6a3660b62f9aae441f54891Trond Myklebustextern int xdr_encode_word(struct xdr_buf *, unsigned int, u32);
1781e78957e0a8f882df6a3660b62f9aae441f54891Trond Myklebustextern int xdr_decode_word(struct xdr_buf *, unsigned int, u32 *);
179bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacher
180bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacherstruct xdr_array2_desc;
181bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbachertypedef int (*xdr_xcode_elem_t)(struct xdr_array2_desc *desc, void *elem);
182bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacherstruct xdr_array2_desc {
183bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacher	unsigned int elem_size;
184bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacher	unsigned int array_len;
18558fcb8df0bf663bb6b8f46cd3010bfe8d13d97cfTrond Myklebust	unsigned int array_maxlen;
186bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacher	xdr_xcode_elem_t xcode;
187bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacher};
188bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacher
189bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacherextern int xdr_decode_array2(struct xdr_buf *buf, unsigned int base,
1909605a069f83d999e60cd57dc8010708fe08291c0Chuck Lever			     struct xdr_array2_desc *desc);
191bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacherextern int xdr_encode_array2(struct xdr_buf *buf, unsigned int base,
192bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacher			     struct xdr_array2_desc *desc);
193bf118a342f10dafe44b14451a1392c3254629a1fAndy Adamsonextern void _copy_from_pages(char *p, struct page **pages, size_t pgbase,
194bf118a342f10dafe44b14451a1392c3254629a1fAndy Adamson			     size_t len);
195bd8100e7eda87507649c6ba4cb32173b34e49986Andreas Gruenbacher
1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Provide some simple tools for XDR buffer overflow-checking etc.
1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct xdr_stream {
200d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan	__be32 *p;		/* start of available buffer */
2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct xdr_buf *buf;	/* XDR buffer to read/write */
2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
203d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan	__be32 *end;		/* end of available buffer space */
2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct kvec *iov;	/* pointer to the current kvec */
2056650239a4b01077e80d5a4468562756d77afaa59Trond Myklebust	struct kvec scratch;	/* Scratch buffer */
2066650239a4b01077e80d5a4468562756d77afaa59Trond Myklebust	struct page **page_ptr;	/* pointer to the current page */
207bfeea1dc1c9238f9e5a17a265489ecd0d19f66bbTrond Myklebust	unsigned int nwords;	/* Remaining decode buffer length */
2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2109f06c719f474be7003763284a990bed6377bb0d4Chuck Lever/*
211bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever * These are the xdr_stream style generic XDR encode and decode functions.
2129f06c719f474be7003763284a990bed6377bb0d4Chuck Lever */
2139f06c719f474be7003763284a990bed6377bb0d4Chuck Levertypedef void	(*kxdreproc_t)(void *rqstp, struct xdr_stream *xdr, void *obj);
214bf2695516db982e90a22fc94f93491b481796bb1Chuck Levertypedef int	(*kxdrdproc_t)(void *rqstp, struct xdr_stream *xdr, void *obj);
2159f06c719f474be7003763284a990bed6377bb0d4Chuck Lever
216d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanextern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p);
217d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanextern __be32 *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes);
2182825a7f90753012babe7ee292f4a1eadd3706f92J. Bruce Fieldsextern void xdr_commit_encode(struct xdr_stream *xdr);
2193e19ce762b537dd9aeefdd0849ba5f2f01ff83cfJ. Bruce Fieldsextern void xdr_truncate_encode(struct xdr_stream *xdr, size_t len);
220db3f58a95beea6752d90fed03f9f198d282a3913J. Bruce Fieldsextern int xdr_restrict_buflen(struct xdr_stream *xdr, int newbuflen);
2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void xdr_write_pages(struct xdr_stream *xdr, struct page **pages,
2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		unsigned int base, unsigned int len);
2234517d526c8aa31b5c14165ef180cc19518ff0a35Trond Myklebustextern unsigned int xdr_stream_pos(const struct xdr_stream *xdr);
224d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanextern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p);
225f7da7a129d57bfe0f74573dc03531c63e1360faeBenny Halevyextern void xdr_init_decode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
226f7da7a129d57bfe0f74573dc03531c63e1360faeBenny Halevy		struct page **pages, unsigned int len);
2276650239a4b01077e80d5a4468562756d77afaa59Trond Myklebustextern void xdr_set_scratch_buffer(struct xdr_stream *xdr, void *buf, size_t buflen);
228d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanextern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
229c337d3655ce85e12c7c476cb81406521926cacd2Trond Myklebustextern unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
2308b23ea7bedb8b45a5bb56745fa3ff11018acf04eTrond Myklebustextern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
23137a4e6cb0391f2293ba3d59e3a63ec0e56ed720dOlga Kornievskaiaextern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data);
2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* __KERNEL__ */
2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* _SUNRPC_XDR_H_ */
236