a06aab278fe0104464e71f77c1803362f778ae56
2 * include/linux/sunrpc/xdr.h
4 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
12 #include <linux/uio.h>
13 #include <asm/byteorder.h>
14 #include <linux/scatterlist.h>
19 #define XDR_QUADLEN(l) (((l) + 3) >> 2)
22 * Generic opaque `network object.' At the kernel level, this type
23 * is used only by lockd.
25 #define XDR_MAX_NETOBJ 1024
32 * This is the generic XDR function. rqstp is either a rpc_rqst (client
33 * side) or svc_rqst pointer (server side).
34 * Encode functions always assume there's enough room in the buffer.
36 typedef int (*kxdrproc_t
)(void *rqstp
, __be32
*data
, void *obj
);
39 * Basic structure for transmission/reception of a client XDR message.
40 * Features a header (for a linear buffer containing RPC headers
41 * and the data payload for short messages), and then an array of
43 * The tail iovec allows you to append data after the page array. Its
44 * main interest is for appending padding to the pages in order to
45 * satisfy the int_32-alignment requirements in RFC1832.
47 * For the future, we might want to string several of these together
48 * in a list if anybody wants to make use of NFSv4 COMPOUND
49 * operations and/or has a need for scatter/gather involving pages.
52 struct kvec head
[1], /* RPC header + non-page data */
53 tail
[1]; /* Appended after page data */
55 struct page
** pages
; /* Array of contiguous pages */
56 unsigned int page_base
, /* Start of page data */
57 page_len
; /* Length of page data */
59 unsigned int buflen
, /* Total length of storage buffer */
60 len
; /* Length of XDR encoded message */
68 #define xdr_zero __constant_htonl(0)
69 #define xdr_one __constant_htonl(1)
70 #define xdr_two __constant_htonl(2)
72 #define rpc_success __constant_htonl(RPC_SUCCESS)
73 #define rpc_prog_unavail __constant_htonl(RPC_PROG_UNAVAIL)
74 #define rpc_prog_mismatch __constant_htonl(RPC_PROG_MISMATCH)
75 #define rpc_proc_unavail __constant_htonl(RPC_PROC_UNAVAIL)
76 #define rpc_garbage_args __constant_htonl(RPC_GARBAGE_ARGS)
77 #define rpc_system_err __constant_htonl(RPC_SYSTEM_ERR)
78 #define rpc_drop_reply __constant_htonl(RPC_DROP_REPLY)
80 #define rpc_auth_ok __constant_htonl(RPC_AUTH_OK)
81 #define rpc_autherr_badcred __constant_htonl(RPC_AUTH_BADCRED)
82 #define rpc_autherr_rejectedcred __constant_htonl(RPC_AUTH_REJECTEDCRED)
83 #define rpc_autherr_badverf __constant_htonl(RPC_AUTH_BADVERF)
84 #define rpc_autherr_rejectedverf __constant_htonl(RPC_AUTH_REJECTEDVERF)
85 #define rpc_autherr_tooweak __constant_htonl(RPC_AUTH_TOOWEAK)
86 #define rpcsec_gsserr_credproblem __constant_htonl(RPCSEC_GSS_CREDPROBLEM)
87 #define rpcsec_gsserr_ctxproblem __constant_htonl(RPCSEC_GSS_CTXPROBLEM)
88 #define rpc_autherr_oldseqnum __constant_htonl(101)
91 * Miscellaneous XDR helper functions
93 __be32
*xdr_encode_opaque_fixed(__be32
*p
, const void *ptr
, unsigned int len
);
94 __be32
*xdr_encode_opaque(__be32
*p
, const void *ptr
, unsigned int len
);
95 __be32
*xdr_encode_string(__be32
*p
, const char *s
);
96 __be32
*xdr_decode_string_inplace(__be32
*p
, char **sp
, int *lenp
, int maxlen
);
97 __be32
*xdr_encode_netobj(__be32
*p
, const struct xdr_netobj
*);
98 __be32
*xdr_decode_netobj(__be32
*p
, struct xdr_netobj
*);
100 void xdr_encode_pages(struct xdr_buf
*, struct page
**, unsigned int,
102 void xdr_inline_pages(struct xdr_buf
*, unsigned int,
103 struct page
**, unsigned int, unsigned int);
105 static inline __be32
*xdr_encode_array(__be32
*p
, const void *s
, unsigned int len
)
107 return xdr_encode_opaque(p
, s
, len
);
111 * Decode 64bit quantities (NFSv3 support)
113 static inline __be32
*
114 xdr_encode_hyper(__be32
*p
, __u64 val
)
116 *p
++ = htonl(val
>> 32);
117 *p
++ = htonl(val
& 0xFFFFFFFF);
121 static inline __be32
*
122 xdr_decode_hyper(__be32
*p
, __u64
*valp
)
124 *valp
= ((__u64
) ntohl(*p
++)) << 32;
125 *valp
|= ntohl(*p
++);
130 * Adjust kvec to reflect end of xdr'ed data (RPC client XDR)
133 xdr_adjust_iovec(struct kvec
*iov
, __be32
*p
)
135 return iov
->iov_len
= ((u8
*) p
- (u8
*) iov
->iov_base
);
139 * XDR buffer helper functions
141 extern void xdr_shift_buf(struct xdr_buf
*, size_t);
142 extern void xdr_buf_from_iov(struct kvec
*, struct xdr_buf
*);
143 extern int xdr_buf_subsegment(struct xdr_buf
*, struct xdr_buf
*, unsigned int, unsigned int);
144 extern int xdr_buf_read_netobj(struct xdr_buf
*, struct xdr_netobj
*, unsigned int);
145 extern int read_bytes_from_xdr_buf(struct xdr_buf
*, unsigned int, void *, unsigned int);
146 extern int write_bytes_to_xdr_buf(struct xdr_buf
*, unsigned int, void *, unsigned int);
149 * Helper structure for copying from an sk_buff.
158 typedef size_t (*skb_read_actor_t
)(skb_reader_t
*desc
, void *to
, size_t len
);
160 size_t xdr_skb_read_bits(skb_reader_t
*desc
, void *to
, size_t len
);
161 extern int csum_partial_copy_to_xdr(struct xdr_buf
*, struct sk_buff
*);
162 extern ssize_t
xdr_partial_copy_from_skb(struct xdr_buf
*, unsigned int,
163 skb_reader_t
*, skb_read_actor_t
);
165 extern int xdr_encode_word(struct xdr_buf
*, unsigned int, u32
);
166 extern int xdr_decode_word(struct xdr_buf
*, unsigned int, u32
*);
168 struct xdr_array2_desc
;
169 typedef int (*xdr_xcode_elem_t
)(struct xdr_array2_desc
*desc
, void *elem
);
170 struct xdr_array2_desc
{
171 unsigned int elem_size
;
172 unsigned int array_len
;
173 unsigned int array_maxlen
;
174 xdr_xcode_elem_t xcode
;
177 extern int xdr_decode_array2(struct xdr_buf
*buf
, unsigned int base
,
178 struct xdr_array2_desc
*desc
);
179 extern int xdr_encode_array2(struct xdr_buf
*buf
, unsigned int base
,
180 struct xdr_array2_desc
*desc
);
183 * Provide some simple tools for XDR buffer overflow-checking etc.
186 __be32
*p
; /* start of available buffer */
187 struct xdr_buf
*buf
; /* XDR buffer to read/write */
189 __be32
*end
; /* end of available buffer space */
190 struct kvec
*iov
; /* pointer to the current kvec */
193 extern void xdr_init_encode(struct xdr_stream
*xdr
, struct xdr_buf
*buf
, __be32
*p
);
194 extern __be32
*xdr_reserve_space(struct xdr_stream
*xdr
, size_t nbytes
);
195 extern void xdr_write_pages(struct xdr_stream
*xdr
, struct page
**pages
,
196 unsigned int base
, unsigned int len
);
197 extern void xdr_init_decode(struct xdr_stream
*xdr
, struct xdr_buf
*buf
, __be32
*p
);
198 extern __be32
*xdr_inline_decode(struct xdr_stream
*xdr
, size_t nbytes
);
199 extern void xdr_read_pages(struct xdr_stream
*xdr
, unsigned int len
);
200 extern void xdr_enter_page(struct xdr_stream
*xdr
, unsigned int len
);
201 extern int xdr_process_buf(struct xdr_buf
*buf
, unsigned int offset
, unsigned int len
, int (*actor
)(struct scatterlist
*, void *), void *data
);
203 #endif /* __KERNEL__ */
205 #endif /* _SUNRPC_XDR_H_ */