2 * Copyright (c) 2008 Sun Microsystems, Inc.
3 * Written by Ricardo Correia <Ricardo.M.Correia@Sun.COM>
5 * This file is part of the SPL, Solaris Porting Layer.
6 * For details, see <http://zfsonlinux.org/>.
8 * The SPL is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
13 * The SPL is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * You should have received a copy of the GNU General Public License along
19 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef _SPL_RPC_XDR_H
23 #define _SPL_RPC_XDR_H
25 #include <sys/types.h>
30 * XDR enums and types.
40 struct xdr_ops *x_ops; /* Let caller know xdrmem_create() succeeds */
41 caddr_t x_addr; /* Current buffer addr */
42 caddr_t x_addr_end; /* End of the buffer */
43 enum xdr_op x_op; /* Stream direction */
46 typedef bool_t (*xdrproc_t)(XDR *xdrs, void *ptr);
49 bool_t (*xdr_control)(XDR *, int, void *);
51 bool_t (*xdr_char)(XDR *, char *);
52 bool_t (*xdr_u_short)(XDR *, unsigned short *);
53 bool_t (*xdr_u_int)(XDR *, unsigned *);
54 bool_t (*xdr_u_longlong_t)(XDR *, u_longlong_t *);
56 bool_t (*xdr_opaque)(XDR *, caddr_t, const uint_t);
57 bool_t (*xdr_string)(XDR *, char **, const uint_t);
58 bool_t (*xdr_array)(XDR *, caddr_t *, uint_t *, const uint_t,
59 const uint_t, const xdrproc_t);
63 * XDR control operator.
65 #define XDR_GET_BYTES_AVAIL 1
68 bool_t xc_is_last_record;
75 void xdrmem_create(XDR *xdrs, const caddr_t addr, const uint_t size,
76 const enum xdr_op op);
78 /* Currently not needed. If needed later, we'll add it to struct xdr_ops */
79 #define xdr_destroy(xdrs) ((void) 0)
81 #define xdr_control(xdrs, req, info) \
82 (xdrs)->x_ops->xdr_control((xdrs), (req), (info))
85 * For precaution, the following are defined as static inlines instead of macros
86 * to get some amount of type safety.
88 * Also, macros wouldn't work in the case where typecasting is done, because it
89 * must be possible to reference the functions' addresses by these names.
91 static inline bool_t xdr_char(XDR *xdrs, char *cp)
93 return (xdrs->x_ops->xdr_char(xdrs, cp));
96 static inline bool_t xdr_u_short(XDR *xdrs, unsigned short *usp)
98 return (xdrs->x_ops->xdr_u_short(xdrs, usp));
101 static inline bool_t xdr_short(XDR *xdrs, short *sp)
103 BUILD_BUG_ON(sizeof (short) != 2);
104 return (xdrs->x_ops->xdr_u_short(xdrs, (unsigned short *) sp));
107 static inline bool_t xdr_u_int(XDR *xdrs, unsigned *up)
109 return (xdrs->x_ops->xdr_u_int(xdrs, up));
112 static inline bool_t xdr_int(XDR *xdrs, int *ip)
114 BUILD_BUG_ON(sizeof (int) != 4);
115 return (xdrs->x_ops->xdr_u_int(xdrs, (unsigned *)ip));
118 static inline bool_t xdr_u_longlong_t(XDR *xdrs, u_longlong_t *ullp)
120 return (xdrs->x_ops->xdr_u_longlong_t(xdrs, ullp));
123 static inline bool_t xdr_longlong_t(XDR *xdrs, longlong_t *llp)
125 BUILD_BUG_ON(sizeof (longlong_t) != 8);
126 return (xdrs->x_ops->xdr_u_longlong_t(xdrs, (u_longlong_t *)llp));
130 * Fixed-length opaque data.
132 static inline bool_t xdr_opaque(XDR *xdrs, caddr_t cp, const uint_t cnt)
134 return (xdrs->x_ops->xdr_opaque(xdrs, cp, cnt));
138 * Variable-length string.
139 * The *sp buffer must have (maxsize + 1) bytes.
141 static inline bool_t xdr_string(XDR *xdrs, char **sp, const uint_t maxsize)
143 return (xdrs->x_ops->xdr_string(xdrs, sp, maxsize));
147 * Variable-length arrays.
149 static inline bool_t xdr_array(XDR *xdrs, caddr_t *arrp, uint_t *sizep,
150 const uint_t maxsize, const uint_t elsize, const xdrproc_t elproc)
152 return xdrs->x_ops->xdr_array(xdrs, arrp, sizep, maxsize, elsize,
156 #endif /* SPL_RPC_XDR_H */