]> git.proxmox.com Git - mirror_zfs.git/blame - include/os/linux/spl/rpc/xdr.h
xdr: header cleanup
[mirror_zfs.git] / include / os / linux / spl / rpc / xdr.h
CommitLineData
4b393c50 1/*
f48b6193 2 * Copyright (c) 2008 Sun Microsystems, Inc.
716154c5 3 * Written by Ricardo Correia <Ricardo.M.Correia@Sun.COM>
f48b6193 4 *
716154c5 5 * This file is part of the SPL, Solaris Porting Layer.
f48b6193 6 *
716154c5
BB
7 * The SPL is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * The SPL is distributed in the hope that it will be useful, but WITHOUT
f48b6193
RC
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
716154c5 18 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
4b393c50 19 */
f48b6193 20
dbb484ec 21#ifndef _SPL_RPC_XDR_H
5461eefe 22#define _SPL_RPC_XDR_H
dbb484ec 23
f48b6193 24#include <sys/types.h>
a9125891 25
f48b6193
RC
26/*
27 * XDR enums and types.
28 */
29enum xdr_op {
30 XDR_ENCODE,
31 XDR_DECODE
32};
33
34struct xdr_ops;
35
36typedef struct {
18168da7
AZ
37 const struct xdr_ops *x_ops;
38 /* Let caller know xdrmem_create() succeeds */
5461eefe
BB
39 caddr_t x_addr; /* Current buffer addr */
40 caddr_t x_addr_end; /* End of the buffer */
41 enum xdr_op x_op; /* Stream direction */
f48b6193
RC
42} XDR;
43
44typedef bool_t (*xdrproc_t)(XDR *xdrs, void *ptr);
45
46struct xdr_ops {
47 bool_t (*xdr_control)(XDR *, int, void *);
48
49 bool_t (*xdr_char)(XDR *, char *);
50 bool_t (*xdr_u_short)(XDR *, unsigned short *);
51 bool_t (*xdr_u_int)(XDR *, unsigned *);
52 bool_t (*xdr_u_longlong_t)(XDR *, u_longlong_t *);
53
54 bool_t (*xdr_opaque)(XDR *, caddr_t, const uint_t);
55 bool_t (*xdr_string)(XDR *, char **, const uint_t);
56 bool_t (*xdr_array)(XDR *, caddr_t *, uint_t *, const uint_t,
5461eefe 57 const uint_t, const xdrproc_t);
f48b6193
RC
58};
59
60/*
61 * XDR control operator.
62 */
5461eefe 63#define XDR_GET_BYTES_AVAIL 1
f48b6193
RC
64
65struct xdr_bytesrec {
66 bool_t xc_is_last_record;
67 size_t xc_num_avail;
68};
69
f48b6193
RC
70/*
71 * XDR functions.
72 */
73void xdrmem_create(XDR *xdrs, const caddr_t addr, const uint_t size,
74 const enum xdr_op op);
f48b6193 75
5461eefe
BB
76#define xdr_control(xdrs, req, info) \
77 (xdrs)->x_ops->xdr_control((xdrs), (req), (info))
f48b6193
RC
78
79/*
80 * For precaution, the following are defined as static inlines instead of macros
81 * to get some amount of type safety.
82 *
83 * Also, macros wouldn't work in the case where typecasting is done, because it
84 * must be possible to reference the functions' addresses by these names.
85 */
86static inline bool_t xdr_char(XDR *xdrs, char *cp)
87{
5461eefe 88 return (xdrs->x_ops->xdr_char(xdrs, cp));
f48b6193
RC
89}
90
91static inline bool_t xdr_u_short(XDR *xdrs, unsigned short *usp)
92{
5461eefe 93 return (xdrs->x_ops->xdr_u_short(xdrs, usp));
f48b6193
RC
94}
95
96static inline bool_t xdr_short(XDR *xdrs, short *sp)
97{
5461eefe
BB
98 BUILD_BUG_ON(sizeof (short) != 2);
99 return (xdrs->x_ops->xdr_u_short(xdrs, (unsigned short *) sp));
f48b6193
RC
100}
101
102static inline bool_t xdr_u_int(XDR *xdrs, unsigned *up)
103{
5461eefe 104 return (xdrs->x_ops->xdr_u_int(xdrs, up));
f48b6193
RC
105}
106
107static inline bool_t xdr_int(XDR *xdrs, int *ip)
108{
5461eefe
BB
109 BUILD_BUG_ON(sizeof (int) != 4);
110 return (xdrs->x_ops->xdr_u_int(xdrs, (unsigned *)ip));
f48b6193
RC
111}
112
113static inline bool_t xdr_u_longlong_t(XDR *xdrs, u_longlong_t *ullp)
114{
5461eefe 115 return (xdrs->x_ops->xdr_u_longlong_t(xdrs, ullp));
f48b6193
RC
116}
117
118static inline bool_t xdr_longlong_t(XDR *xdrs, longlong_t *llp)
119{
5461eefe
BB
120 BUILD_BUG_ON(sizeof (longlong_t) != 8);
121 return (xdrs->x_ops->xdr_u_longlong_t(xdrs, (u_longlong_t *)llp));
f48b6193
RC
122}
123
124/*
125 * Fixed-length opaque data.
126 */
127static inline bool_t xdr_opaque(XDR *xdrs, caddr_t cp, const uint_t cnt)
128{
5461eefe 129 return (xdrs->x_ops->xdr_opaque(xdrs, cp, cnt));
f48b6193
RC
130}
131
132/*
133 * Variable-length string.
134 * The *sp buffer must have (maxsize + 1) bytes.
135 */
136static inline bool_t xdr_string(XDR *xdrs, char **sp, const uint_t maxsize)
137{
5461eefe 138 return (xdrs->x_ops->xdr_string(xdrs, sp, maxsize));
f48b6193
RC
139}
140
141/*
142 * Variable-length arrays.
143 */
144static inline bool_t xdr_array(XDR *xdrs, caddr_t *arrp, uint_t *sizep,
145 const uint_t maxsize, const uint_t elsize, const xdrproc_t elproc)
146{
147 return xdrs->x_ops->xdr_array(xdrs, arrp, sizep, maxsize, elsize,
148 elproc);
149}
dbb484ec
BB
150
151#endif /* SPL_RPC_XDR_H */