2 * XDR standard data types and function declarations
4 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
7 * RFC 4506 "XDR: External Data Representation Standard", May 2006
10 #ifndef _SUNRPC_XDR_H_
11 #define _SUNRPC_XDR_H_
15 #include <linux/uio.h>
16 #include <asm/byteorder.h>
17 #include <asm/unaligned.h>
18 #include <linux/scatterlist.h>
23 #define XDR_QUADLEN(l) (((l) + 3) >> 2)
26 * Generic opaque `network object.' At the kernel level, this type
27 * is used only by lockd.
29 #define XDR_MAX_NETOBJ 1024
36 * This is the generic XDR function. rqstp is either a rpc_rqst (client
37 * side) or svc_rqst pointer (server side).
38 * Encode functions always assume there's enough room in the buffer.
40 typedef int (*kxdrproc_t
)(void *rqstp
, __be32
*data
, void *obj
);
43 * Basic structure for transmission/reception of a client XDR message.
44 * Features a header (for a linear buffer containing RPC headers
45 * and the data payload for short messages), and then an array of
47 * The tail iovec allows you to append data after the page array. Its
48 * main interest is for appending padding to the pages in order to
49 * satisfy the int_32-alignment requirements in RFC1832.
51 * For the future, we might want to string several of these together
52 * in a list if anybody wants to make use of NFSv4 COMPOUND
53 * operations and/or has a need for scatter/gather involving pages.
56 struct kvec head
[1], /* RPC header + non-page data */
57 tail
[1]; /* Appended after page data */
59 struct page
** pages
; /* Array of contiguous pages */
60 unsigned int page_base
, /* Start of page data */
61 page_len
, /* Length of page data */
62 flags
; /* Flags for data disposition */
63 #define XDRBUF_READ 0x01 /* target of file read */
64 #define XDRBUF_WRITE 0x02 /* source of file write */
66 unsigned int buflen
, /* Total length of storage buffer */
67 len
; /* Length of XDR encoded message */
74 #define xdr_zero cpu_to_be32(0)
75 #define xdr_one cpu_to_be32(1)
76 #define xdr_two cpu_to_be32(2)
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)
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)
97 * Miscellaneous XDR helper functions
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
*);
107 void xdr_encode_pages(struct xdr_buf
*, struct page
**, unsigned int,
109 void xdr_inline_pages(struct xdr_buf
*, unsigned int,
110 struct page
**, unsigned int, unsigned int);
111 void xdr_terminate_string(struct xdr_buf
*, const u32
);
113 static inline __be32
*xdr_encode_array(__be32
*p
, const void *s
, unsigned int len
)
115 return xdr_encode_opaque(p
, s
, len
);
119 * Decode 64bit quantities (NFSv3 support)
121 static inline __be32
*
122 xdr_encode_hyper(__be32
*p
, __u64 val
)
124 put_unaligned_be64(val
, p
);
128 static inline __be32
*
129 xdr_decode_hyper(__be32
*p
, __u64
*valp
)
131 *valp
= get_unaligned_be64(p
);
135 static inline __be32
*
136 xdr_decode_opaque_fixed(__be32
*p
, void *ptr
, unsigned int len
)
139 return p
+ XDR_QUADLEN(len
);
143 * Adjust kvec to reflect end of xdr'ed data (RPC client XDR)
146 xdr_adjust_iovec(struct kvec
*iov
, __be32
*p
)
148 return iov
->iov_len
= ((u8
*) p
- (u8
*) iov
->iov_base
);
152 * XDR buffer helper functions
154 extern void xdr_shift_buf(struct xdr_buf
*, size_t);
155 extern void xdr_buf_from_iov(struct kvec
*, struct xdr_buf
*);
156 extern int xdr_buf_subsegment(struct xdr_buf
*, struct xdr_buf
*, unsigned int, unsigned int);
157 extern int xdr_buf_read_netobj(struct xdr_buf
*, struct xdr_netobj
*, unsigned int);
158 extern int read_bytes_from_xdr_buf(struct xdr_buf
*, unsigned int, void *, unsigned int);
159 extern int write_bytes_to_xdr_buf(struct xdr_buf
*, unsigned int, void *, unsigned int);
162 * Helper structure for copying from an sk_buff.
164 struct xdr_skb_reader
{
171 typedef size_t (*xdr_skb_read_actor
)(struct xdr_skb_reader
*desc
, void *to
, size_t len
);
173 size_t xdr_skb_read_bits(struct xdr_skb_reader
*desc
, void *to
, size_t len
);
174 extern int csum_partial_copy_to_xdr(struct xdr_buf
*, struct sk_buff
*);
175 extern ssize_t
xdr_partial_copy_from_skb(struct xdr_buf
*, unsigned int,
176 struct xdr_skb_reader
*, xdr_skb_read_actor
);
178 extern int xdr_encode_word(struct xdr_buf
*, unsigned int, u32
);
179 extern int xdr_decode_word(struct xdr_buf
*, unsigned int, u32
*);
181 struct xdr_array2_desc
;
182 typedef int (*xdr_xcode_elem_t
)(struct xdr_array2_desc
*desc
, void *elem
);
183 struct xdr_array2_desc
{
184 unsigned int elem_size
;
185 unsigned int array_len
;
186 unsigned int array_maxlen
;
187 xdr_xcode_elem_t xcode
;
190 extern int xdr_decode_array2(struct xdr_buf
*buf
, unsigned int base
,
191 struct xdr_array2_desc
*desc
);
192 extern int xdr_encode_array2(struct xdr_buf
*buf
, unsigned int base
,
193 struct xdr_array2_desc
*desc
);
196 * Provide some simple tools for XDR buffer overflow-checking etc.
199 __be32
*p
; /* start of available buffer */
200 struct xdr_buf
*buf
; /* XDR buffer to read/write */
202 __be32
*end
; /* end of available buffer space */
203 struct kvec
*iov
; /* pointer to the current kvec */
204 struct kvec scratch
; /* Scratch buffer */
205 struct page
**page_ptr
; /* pointer to the current page */
208 extern void xdr_init_encode(struct xdr_stream
*xdr
, struct xdr_buf
*buf
, __be32
*p
);
209 extern __be32
*xdr_reserve_space(struct xdr_stream
*xdr
, size_t nbytes
);
210 extern void xdr_write_pages(struct xdr_stream
*xdr
, struct page
**pages
,
211 unsigned int base
, unsigned int len
);
212 extern void xdr_init_decode(struct xdr_stream
*xdr
, struct xdr_buf
*buf
, __be32
*p
);
213 extern void xdr_set_scratch_buffer(struct xdr_stream
*xdr
, void *buf
, size_t buflen
);
214 extern __be32
*xdr_inline_decode(struct xdr_stream
*xdr
, size_t nbytes
);
215 extern void xdr_read_pages(struct xdr_stream
*xdr
, unsigned int len
);
216 extern void xdr_enter_page(struct xdr_stream
*xdr
, unsigned int len
);
217 extern int xdr_process_buf(struct xdr_buf
*buf
, unsigned int offset
, unsigned int len
, int (*actor
)(struct scatterlist
*, void *), void *data
);
219 #endif /* __KERNEL__ */
221 #endif /* _SUNRPC_XDR_H_ */