1
2
3
4
5
6
7
8
9
10#ifndef _SUNRPC_XDR_H_
11#define _SUNRPC_XDR_H_
12
13#ifdef __KERNEL__
14
15#include <linux/uio.h>
16#include <asm/byteorder.h>
17#include <asm/unaligned.h>
18#include <linux/scatterlist.h>
19
20
21
22
23#define XDR_QUADLEN(l) (((l) + 3) >> 2)
24
25
26
27
28
29#define XDR_MAX_NETOBJ 1024
30struct xdr_netobj {
31 unsigned int len;
32 u8 * data;
33};
34
35
36
37
38
39
40typedef int (*kxdrproc_t)(void *rqstp, __be32 *data, void *obj);
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55struct xdr_buf {
56 struct kvec head[1],
57 tail[1];
58
59 struct page ** pages;
60 unsigned int page_base,
61 page_len,
62 flags;
63#define XDRBUF_READ 0x01
64#define XDRBUF_WRITE 0x02
65
66 unsigned int buflen,
67 len;
68};
69
70
71
72
73
74#define xdr_zero cpu_to_be32(0)
75#define xdr_one cpu_to_be32(1)
76#define xdr_two cpu_to_be32(2)
77
78#define rpc_success cpu_to_be32(RPC_SUCCESS)
79#define rpc_prog_unavail cpu_to_be32(RPC_PROG_UNAVAIL)
80#define rpc_prog_mismatch cpu_to_be32(RPC_PROG_MISMATCH)
81#define rpc_proc_unavail cpu_to_be32(RPC_PROC_UNAVAIL)
82#define rpc_garbage_args cpu_to_be32(RPC_GARBAGE_ARGS)
83#define rpc_system_err cpu_to_be32(RPC_SYSTEM_ERR)
84#define rpc_drop_reply cpu_to_be32(RPC_DROP_REPLY)
85
86#define rpc_auth_ok cpu_to_be32(RPC_AUTH_OK)
87#define rpc_autherr_badcred cpu_to_be32(RPC_AUTH_BADCRED)
88#define rpc_autherr_rejectedcred cpu_to_be32(RPC_AUTH_REJECTEDCRED)
89#define rpc_autherr_badverf cpu_to_be32(RPC_AUTH_BADVERF)
90#define rpc_autherr_rejectedverf cpu_to_be32(RPC_AUTH_REJECTEDVERF)
91#define rpc_autherr_tooweak cpu_to_be32(RPC_AUTH_TOOWEAK)
92#define rpcsec_gsserr_credproblem cpu_to_be32(RPCSEC_GSS_CREDPROBLEM)
93#define rpcsec_gsserr_ctxproblem cpu_to_be32(RPCSEC_GSS_CTXPROBLEM)
94#define rpc_autherr_oldseqnum cpu_to_be32(101)
95
96
97
98
99__be32 *xdr_encode_opaque_fixed(__be32 *p, const void *ptr, unsigned int len);
100__be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int len);
101__be32 *xdr_encode_string(__be32 *p, const char *s);
102__be32 *xdr_decode_string_inplace(__be32 *p, char **sp, unsigned int *lenp,
103 unsigned int maxlen);
104__be32 *xdr_encode_netobj(__be32 *p, const struct xdr_netobj *);
105__be32 *xdr_decode_netobj(__be32 *p, struct xdr_netobj *);
106
107void xdr_inline_pages(struct xdr_buf *, unsigned int,
108 struct page **, unsigned int, unsigned int);
109void xdr_terminate_string(struct xdr_buf *, const u32);
110
111static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int len)
112{
113 return xdr_encode_opaque(p, s, len);
114}
115
116
117
118
119static inline __be32 *
120xdr_encode_hyper(__be32 *p, __u64 val)
121{
122 put_unaligned_be64(val, p);
123 return p + 2;
124}
125
126static inline __be32 *
127xdr_decode_hyper(__be32 *p, __u64 *valp)
128{
129 *valp = get_unaligned_be64(p);
130 return p + 2;
131}
132
133static inline __be32 *
134xdr_decode_opaque_fixed(__be32 *p, void *ptr, unsigned int len)
135{
136 memcpy(ptr, p, len);
137 return p + XDR_QUADLEN(len);
138}
139
140
141
142
143static inline int
144xdr_adjust_iovec(struct kvec *iov, __be32 *p)
145{
146 return iov->iov_len = ((u8 *) p - (u8 *) iov->iov_base);
147}
148
149
150
151
152extern void xdr_shift_buf(struct xdr_buf *, size_t);
153extern void xdr_buf_from_iov(struct kvec *, struct xdr_buf *);
154extern int xdr_buf_subsegment(struct xdr_buf *, struct xdr_buf *, unsigned int, unsigned int);
155extern int xdr_buf_read_netobj(struct xdr_buf *, struct xdr_netobj *, unsigned int);
156extern int read_bytes_from_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
157extern int write_bytes_to_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
158
159
160
161
162struct xdr_skb_reader {
163 struct sk_buff *skb;
164 unsigned int offset;
165 size_t count;
166 __wsum csum;
167};
168
169typedef size_t (*xdr_skb_read_actor)(struct xdr_skb_reader *desc, void *to, size_t len);
170
171size_t xdr_skb_read_bits(struct xdr_skb_reader *desc, void *to, size_t len);
172extern int csum_partial_copy_to_xdr(struct xdr_buf *, struct sk_buff *);
173extern ssize_t xdr_partial_copy_from_skb(struct xdr_buf *, unsigned int,
174 struct xdr_skb_reader *, xdr_skb_read_actor);
175
176extern int xdr_encode_word(struct xdr_buf *, unsigned int, u32);
177extern int xdr_decode_word(struct xdr_buf *, unsigned int, u32 *);
178
179struct xdr_array2_desc;
180typedef int (*xdr_xcode_elem_t)(struct xdr_array2_desc *desc, void *elem);
181struct xdr_array2_desc {
182 unsigned int elem_size;
183 unsigned int array_len;
184 unsigned int array_maxlen;
185 xdr_xcode_elem_t xcode;
186};
187
188extern int xdr_decode_array2(struct xdr_buf *buf, unsigned int base,
189 struct xdr_array2_desc *desc);
190extern int xdr_encode_array2(struct xdr_buf *buf, unsigned int base,
191 struct xdr_array2_desc *desc);
192extern void _copy_from_pages(char *p, struct page **pages, size_t pgbase,
193 size_t len);
194
195
196
197
198struct xdr_stream {
199 __be32 *p;
200 struct xdr_buf *buf;
201
202 __be32 *end;
203 struct kvec *iov;
204 struct kvec scratch;
205 struct page **page_ptr;
206 unsigned int nwords;
207};
208
209
210
211
212typedef void (*kxdreproc_t)(void *rqstp, struct xdr_stream *xdr, void *obj);
213typedef int (*kxdrdproc_t)(void *rqstp, struct xdr_stream *xdr, void *obj);
214
215extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p);
216extern __be32 *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes);
217extern void xdr_write_pages(struct xdr_stream *xdr, struct page **pages,
218 unsigned int base, unsigned int len);
219extern unsigned int xdr_stream_pos(const struct xdr_stream *xdr);
220extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p);
221extern void xdr_init_decode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
222 struct page **pages, unsigned int len);
223extern void xdr_set_scratch_buffer(struct xdr_stream *xdr, void *buf, size_t buflen);
224extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
225extern unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
226extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
227extern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data);
228
229#endif
230
231#endif
232