initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / linux / sunrpc / xdr.h
blob112738cca4e19d5da0d003bb7fc9e9c509c17938
1 /*
2 * include/linux/sunrpc/xdr.h
4 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
5 */
7 #ifndef _SUNRPC_XDR_H_
8 #define _SUNRPC_XDR_H_
10 #ifdef __KERNEL__
12 #include <linux/uio.h>
13 #include <asm/byteorder.h>
16 * Buffer adjustment
18 #define XDR_QUADLEN(l) (((l) + 3) >> 2)
21 * Generic opaque `network object.' At the kernel level, this type
22 * is used only by lockd.
24 #define XDR_MAX_NETOBJ 1024
25 struct xdr_netobj {
26 unsigned int len;
27 u8 * data;
31 * This is the generic XDR function. rqstp is either a rpc_rqst (client
32 * side) or svc_rqst pointer (server side).
33 * Encode functions always assume there's enough room in the buffer.
35 typedef int (*kxdrproc_t)(void *rqstp, u32 *data, void *obj);
38 * Basic structure for transmission/reception of a client XDR message.
39 * Features a header (for a linear buffer containing RPC headers
40 * and the data payload for short messages), and then an array of
41 * pages.
42 * The tail iovec allows you to append data after the page array. Its
43 * main interest is for appending padding to the pages in order to
44 * satisfy the int_32-alignment requirements in RFC1832.
46 * For the future, we might want to string several of these together
47 * in a list if anybody wants to make use of NFSv4 COMPOUND
48 * operations and/or has a need for scatter/gather involving pages.
50 struct xdr_buf {
51 struct kvec head[1], /* RPC header + non-page data */
52 tail[1]; /* Appended after page data */
54 struct page ** pages; /* Array of contiguous pages */
55 unsigned int page_base, /* Start of page data */
56 page_len; /* Length of page data */
58 unsigned int buflen, /* Total length of storage buffer */
59 len; /* Length of XDR encoded message */
64 * pre-xdr'ed macros.
67 #define xdr_zero __constant_htonl(0)
68 #define xdr_one __constant_htonl(1)
69 #define xdr_two __constant_htonl(2)
71 #define rpc_success __constant_htonl(RPC_SUCCESS)
72 #define rpc_prog_unavail __constant_htonl(RPC_PROG_UNAVAIL)
73 #define rpc_prog_mismatch __constant_htonl(RPC_PROG_MISMATCH)
74 #define rpc_proc_unavail __constant_htonl(RPC_PROC_UNAVAIL)
75 #define rpc_garbage_args __constant_htonl(RPC_GARBAGE_ARGS)
76 #define rpc_system_err __constant_htonl(RPC_SYSTEM_ERR)
78 #define rpc_auth_ok __constant_htonl(RPC_AUTH_OK)
79 #define rpc_autherr_badcred __constant_htonl(RPC_AUTH_BADCRED)
80 #define rpc_autherr_rejectedcred __constant_htonl(RPC_AUTH_REJECTEDCRED)
81 #define rpc_autherr_badverf __constant_htonl(RPC_AUTH_BADVERF)
82 #define rpc_autherr_rejectedverf __constant_htonl(RPC_AUTH_REJECTEDVERF)
83 #define rpc_autherr_tooweak __constant_htonl(RPC_AUTH_TOOWEAK)
84 #define rpcsec_gsserr_credproblem __constant_htonl(RPCSEC_GSS_CREDPROBLEM)
85 #define rpcsec_gsserr_ctxproblem __constant_htonl(RPCSEC_GSS_CTXPROBLEM)
86 #define rpc_autherr_oldseqnum __constant_htonl(101)
89 * Miscellaneous XDR helper functions
91 u32 * xdr_encode_opaque_fixed(u32 *p, const void *ptr, unsigned int len);
92 u32 * xdr_encode_opaque(u32 *p, const void *ptr, unsigned int len);
93 u32 * xdr_encode_string(u32 *p, const char *s);
94 u32 * xdr_decode_string(u32 *p, char **sp, int *lenp, int maxlen);
95 u32 * xdr_decode_string_inplace(u32 *p, char **sp, int *lenp, int maxlen);
96 u32 * xdr_encode_netobj(u32 *p, const struct xdr_netobj *);
97 u32 * xdr_decode_netobj(u32 *p, struct xdr_netobj *);
98 u32 * xdr_decode_netobj_fixed(u32 *p, void *obj, unsigned int len);
100 void xdr_encode_pages(struct xdr_buf *, struct page **, unsigned int,
101 unsigned int);
102 void xdr_inline_pages(struct xdr_buf *, unsigned int,
103 struct page **, unsigned int, unsigned int);
105 static inline u32 *xdr_encode_array(u32 *p, const void *s, unsigned int len)
107 return xdr_encode_opaque(p, s, len);
111 * Decode 64bit quantities (NFSv3 support)
113 static inline u32 *
114 xdr_encode_hyper(u32 *p, __u64 val)
116 *p++ = htonl(val >> 32);
117 *p++ = htonl(val & 0xFFFFFFFF);
118 return p;
121 static inline u32 *
122 xdr_decode_hyper(u32 *p, __u64 *valp)
124 *valp = ((__u64) ntohl(*p++)) << 32;
125 *valp |= ntohl(*p++);
126 return p;
130 * Adjust kvec to reflect end of xdr'ed data (RPC client XDR)
132 static inline int
133 xdr_adjust_iovec(struct kvec *iov, u32 *p)
135 return iov->iov_len = ((u8 *) p - (u8 *) iov->iov_base);
138 void xdr_shift_iovec(struct kvec *, int, size_t);
141 * Maximum number of iov's we use.
143 #define MAX_IOVEC (12)
146 * XDR buffer helper functions
148 extern int xdr_kmap(struct kvec *, struct xdr_buf *, size_t);
149 extern void xdr_kunmap(struct xdr_buf *, size_t);
150 extern void xdr_shift_buf(struct xdr_buf *, size_t);
151 extern void _copy_from_pages(char *, struct page **, size_t, size_t);
152 extern void xdr_buf_from_iov(struct kvec *, struct xdr_buf *);
153 extern int xdr_buf_subsegment(struct xdr_buf *, struct xdr_buf *, int, int);
154 extern int xdr_buf_read_netobj(struct xdr_buf *, struct xdr_netobj *, int);
155 extern int read_bytes_from_xdr_buf(struct xdr_buf *buf, int base, void *obj, int len);
158 * Helper structure for copying from an sk_buff.
160 typedef struct {
161 struct sk_buff *skb;
162 unsigned int offset;
163 size_t count;
164 unsigned int csum;
165 } skb_reader_t;
167 typedef size_t (*skb_read_actor_t)(skb_reader_t *desc, void *to, size_t len);
169 extern void xdr_partial_copy_from_skb(struct xdr_buf *, unsigned int,
170 skb_reader_t *, skb_read_actor_t);
172 struct socket;
173 struct sockaddr;
174 extern int xdr_sendpages(struct socket *, struct sockaddr *, int,
175 struct xdr_buf *, unsigned int, int);
178 * Provide some simple tools for XDR buffer overflow-checking etc.
180 struct xdr_stream {
181 uint32_t *p; /* start of available buffer */
182 struct xdr_buf *buf; /* XDR buffer to read/write */
184 uint32_t *end; /* end of available buffer space */
185 struct kvec *iov; /* pointer to the current kvec */
188 extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, uint32_t *p);
189 extern uint32_t *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes);
190 extern void xdr_write_pages(struct xdr_stream *xdr, struct page **pages,
191 unsigned int base, unsigned int len);
192 extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, uint32_t *p);
193 extern uint32_t *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
194 extern void xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
196 #endif /* __KERNEL__ */
198 #endif /* _SUNRPC_XDR_H_ */