2 * include/linux/sunrpc/xdr.h
4 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
12 #include <linux/uio.h>
17 #define XDR_QUADLEN(l) (((l) + 3) >> 2)
20 * Generic opaque `network object.' At the kernel level, this type
21 * is used only by lockd.
23 #define XDR_MAX_NETOBJ 1024
30 * This is the generic XDR function. rqstp is either a rpc_rqst (client
31 * side) or svc_rqst pointer (server side).
32 * Encode functions always assume there's enough room in the buffer.
34 typedef int (*kxdrproc_t
)(void *rqstp
, u32
*data
, void *obj
);
37 * Basic structure for transmission/reception of a client XDR message.
38 * Features a header (for a linear buffer containing RPC headers
39 * and the data payload for short messages), and then an array of
41 * The tail iovec allows you to append data after the page array. Its
42 * main interest is for appending padding to the pages in order to
43 * satisfy the int_32-alignment requirements in RFC1832.
45 * For the future, we might want to string several of these together
46 * in a list if anybody wants to make use of NFSv4 COMPOUND
47 * operations and/or has a need for scatter/gather involving pages.
50 struct iovec head
[1], /* RPC header + non-page data */
51 tail
[1]; /* Appended after page data */
53 struct page
** pages
; /* Array of contiguous pages */
54 unsigned int page_base
, /* Start of page data */
55 page_len
; /* Length of page data */
57 unsigned int len
; /* Total length of data */
65 #define xdr_zero __constant_htonl(0)
66 #define xdr_one __constant_htonl(1)
67 #define xdr_two __constant_htonl(2)
69 #define rpc_success __constant_htonl(RPC_SUCCESS)
70 #define rpc_prog_unavail __constant_htonl(RPC_PROG_UNAVAIL)
71 #define rpc_prog_mismatch __constant_htonl(RPC_PROG_MISMATCH)
72 #define rpc_proc_unavail __constant_htonl(RPC_PROC_UNAVAIL)
73 #define rpc_garbage_args __constant_htonl(RPC_GARBAGE_ARGS)
74 #define rpc_system_err __constant_htonl(RPC_SYSTEM_ERR)
76 #define rpc_auth_ok __constant_htonl(RPC_AUTH_OK)
77 #define rpc_autherr_badcred __constant_htonl(RPC_AUTH_BADCRED)
78 #define rpc_autherr_rejectedcred __constant_htonl(RPC_AUTH_REJECTEDCRED)
79 #define rpc_autherr_badverf __constant_htonl(RPC_AUTH_BADVERF)
80 #define rpc_autherr_rejectedverf __constant_htonl(RPC_AUTH_REJECTEDVERF)
81 #define rpc_autherr_tooweak __constant_htonl(RPC_AUTH_TOOWEAK)
85 * Miscellaneous XDR helper functions
87 u32
* xdr_encode_array(u32
*p
, const char *s
, unsigned int len
);
88 u32
* xdr_encode_string(u32
*p
, const char *s
);
89 u32
* xdr_decode_string(u32
*p
, char **sp
, int *lenp
, int maxlen
);
90 u32
* xdr_decode_string_inplace(u32
*p
, char **sp
, int *lenp
, int maxlen
);
91 u32
* xdr_encode_netobj(u32
*p
, const struct xdr_netobj
*);
92 u32
* xdr_decode_netobj(u32
*p
, struct xdr_netobj
*);
93 u32
* xdr_decode_netobj_fixed(u32
*p
, void *obj
, unsigned int len
);
95 void xdr_encode_pages(struct xdr_buf
*, struct page
**, unsigned int,
97 void xdr_inline_pages(struct xdr_buf
*, unsigned int,
98 struct page
**, unsigned int, unsigned int);
101 * Decode 64bit quantities (NFSv3 support)
104 xdr_encode_hyper(u32
*p
, __u64 val
)
106 *p
++ = htonl(val
>> 32);
107 *p
++ = htonl(val
& 0xFFFFFFFF);
112 xdr_decode_hyper(u32
*p
, __u64
*valp
)
114 *valp
= ((__u64
) ntohl(*p
++)) << 32;
115 *valp
|= ntohl(*p
++);
120 * Adjust iovec to reflect end of xdr'ed data (RPC client XDR)
123 xdr_adjust_iovec(struct iovec
*iov
, u32
*p
)
125 return iov
->iov_len
= ((u8
*) p
- (u8
*) iov
->iov_base
);
128 void xdr_shift_iovec(struct iovec
*, int, size_t);
129 void xdr_zero_iovec(struct iovec
*, int, size_t);
132 * Maximum number of iov's we use.
134 #define MAX_IOVEC (12)
137 * XDR buffer helper functions
139 extern int xdr_kmap(struct iovec
*, struct xdr_buf
*, unsigned int);
140 extern void xdr_kunmap(struct xdr_buf
*, unsigned int, int);
141 extern void xdr_shift_buf(struct xdr_buf
*, size_t);
144 * Helper structure for copying from an sk_buff.
153 typedef size_t (*skb_read_actor_t
)(skb_reader_t
*desc
, void *to
, size_t len
);
155 extern void xdr_partial_copy_from_skb(struct xdr_buf
*, unsigned int,
156 skb_reader_t
*, skb_read_actor_t
);
158 extern int xdr_copy_skb(struct xdr_buf
*xdr
, unsigned int base
,
159 struct sk_buff
*skb
, unsigned int offset
);
161 extern int xdr_copy_and_csum_skb(struct xdr_buf
*xdr
, unsigned int base
,
162 struct sk_buff
*skb
, unsigned int offset
, unsigned int csum
);
164 #endif /* __KERNEL__ */
166 #endif /* _SUNRPC_XDR_H_ */