config/dracut/90zfs: handle cases where hostid(1) returns all zeros
[zfs.git] / include / os / linux / spl / rpc / xdr.h
blobc62080a1178a824d157820d6bc6f21412a167bee
1 /*
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.
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.
12 * The SPL is distributed in the hope that it will be useful, but WITHOUT
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.
17 * You should have received a copy of the GNU General Public License along
18 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef _SPL_RPC_XDR_H
22 #define _SPL_RPC_XDR_H
24 #include <sys/types.h>
26 typedef int bool_t;
29 * XDR enums and types.
31 enum xdr_op {
32 XDR_ENCODE,
33 XDR_DECODE
36 struct xdr_ops;
38 typedef struct {
39 struct xdr_ops *x_ops; /* Let caller know xdrmem_create() succeeds */
40 caddr_t x_addr; /* Current buffer addr */
41 caddr_t x_addr_end; /* End of the buffer */
42 enum xdr_op x_op; /* Stream direction */
43 } XDR;
45 typedef bool_t (*xdrproc_t)(XDR *xdrs, void *ptr);
47 struct xdr_ops {
48 bool_t (*xdr_control)(XDR *, int, void *);
50 bool_t (*xdr_char)(XDR *, char *);
51 bool_t (*xdr_u_short)(XDR *, unsigned short *);
52 bool_t (*xdr_u_int)(XDR *, unsigned *);
53 bool_t (*xdr_u_longlong_t)(XDR *, u_longlong_t *);
55 bool_t (*xdr_opaque)(XDR *, caddr_t, const uint_t);
56 bool_t (*xdr_string)(XDR *, char **, const uint_t);
57 bool_t (*xdr_array)(XDR *, caddr_t *, uint_t *, const uint_t,
58 const uint_t, const xdrproc_t);
62 * XDR control operator.
64 #define XDR_GET_BYTES_AVAIL 1
66 struct xdr_bytesrec {
67 bool_t xc_is_last_record;
68 size_t xc_num_avail;
72 * XDR functions.
74 void xdrmem_create(XDR *xdrs, const caddr_t addr, const uint_t size,
75 const enum xdr_op op);
77 /* Currently not needed. If needed later, we'll add it to struct xdr_ops */
78 #define xdr_destroy(xdrs) ((void) 0)
80 #define xdr_control(xdrs, req, info) \
81 (xdrs)->x_ops->xdr_control((xdrs), (req), (info))
84 * For precaution, the following are defined as static inlines instead of macros
85 * to get some amount of type safety.
87 * Also, macros wouldn't work in the case where typecasting is done, because it
88 * must be possible to reference the functions' addresses by these names.
90 static inline bool_t xdr_char(XDR *xdrs, char *cp)
92 return (xdrs->x_ops->xdr_char(xdrs, cp));
95 static inline bool_t xdr_u_short(XDR *xdrs, unsigned short *usp)
97 return (xdrs->x_ops->xdr_u_short(xdrs, usp));
100 static inline bool_t xdr_short(XDR *xdrs, short *sp)
102 BUILD_BUG_ON(sizeof (short) != 2);
103 return (xdrs->x_ops->xdr_u_short(xdrs, (unsigned short *) sp));
106 static inline bool_t xdr_u_int(XDR *xdrs, unsigned *up)
108 return (xdrs->x_ops->xdr_u_int(xdrs, up));
111 static inline bool_t xdr_int(XDR *xdrs, int *ip)
113 BUILD_BUG_ON(sizeof (int) != 4);
114 return (xdrs->x_ops->xdr_u_int(xdrs, (unsigned *)ip));
117 static inline bool_t xdr_u_longlong_t(XDR *xdrs, u_longlong_t *ullp)
119 return (xdrs->x_ops->xdr_u_longlong_t(xdrs, ullp));
122 static inline bool_t xdr_longlong_t(XDR *xdrs, longlong_t *llp)
124 BUILD_BUG_ON(sizeof (longlong_t) != 8);
125 return (xdrs->x_ops->xdr_u_longlong_t(xdrs, (u_longlong_t *)llp));
129 * Fixed-length opaque data.
131 static inline bool_t xdr_opaque(XDR *xdrs, caddr_t cp, const uint_t cnt)
133 return (xdrs->x_ops->xdr_opaque(xdrs, cp, cnt));
137 * Variable-length string.
138 * The *sp buffer must have (maxsize + 1) bytes.
140 static inline bool_t xdr_string(XDR *xdrs, char **sp, const uint_t maxsize)
142 return (xdrs->x_ops->xdr_string(xdrs, sp, maxsize));
146 * Variable-length arrays.
148 static inline bool_t xdr_array(XDR *xdrs, caddr_t *arrp, uint_t *sizep,
149 const uint_t maxsize, const uint_t elsize, const xdrproc_t elproc)
151 return xdrs->x_ops->xdr_array(xdrs, arrp, sizep, maxsize, elsize,
152 elproc);
155 #endif /* SPL_RPC_XDR_H */