2017-10-04 19:33:43 +03:00
|
|
|
/*
|
2009-03-10 22:51:45 +03:00
|
|
|
* Copyright (c) 2008 Sun Microsystems, Inc.
|
2010-05-18 02:18:00 +04:00
|
|
|
* Written by Ricardo Correia <Ricardo.M.Correia@Sun.COM>
|
2009-03-10 22:51:45 +03:00
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
2009-03-10 22:51:45 +03:00
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2009-03-10 22:51:45 +03:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-18 02:18:00 +04:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
2017-10-04 19:33:43 +03:00
|
|
|
*/
|
2009-03-10 22:51:45 +03:00
|
|
|
|
2008-03-01 21:30:12 +03:00
|
|
|
#ifndef _SPL_RPC_XDR_H
|
2018-02-07 22:49:38 +03:00
|
|
|
#define _SPL_RPC_XDR_H
|
2008-03-01 21:30:12 +03:00
|
|
|
|
2009-03-10 22:51:45 +03:00
|
|
|
#include <sys/types.h>
|
2018-02-15 04:01:15 +03:00
|
|
|
|
|
|
|
typedef int bool_t;
|
2009-03-10 22:51:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XDR enums and types.
|
|
|
|
*/
|
|
|
|
enum xdr_op {
|
|
|
|
XDR_ENCODE,
|
|
|
|
XDR_DECODE
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xdr_ops;
|
|
|
|
|
|
|
|
typedef struct {
|
2022-01-15 02:37:55 +03:00
|
|
|
const struct xdr_ops *x_ops;
|
|
|
|
/* Let caller know xdrmem_create() succeeds */
|
2018-02-07 22:49:38 +03:00
|
|
|
caddr_t x_addr; /* Current buffer addr */
|
|
|
|
caddr_t x_addr_end; /* End of the buffer */
|
|
|
|
enum xdr_op x_op; /* Stream direction */
|
2009-03-10 22:51:45 +03:00
|
|
|
} XDR;
|
|
|
|
|
|
|
|
typedef bool_t (*xdrproc_t)(XDR *xdrs, void *ptr);
|
|
|
|
|
|
|
|
struct xdr_ops {
|
|
|
|
bool_t (*xdr_control)(XDR *, int, void *);
|
|
|
|
|
|
|
|
bool_t (*xdr_char)(XDR *, char *);
|
|
|
|
bool_t (*xdr_u_short)(XDR *, unsigned short *);
|
|
|
|
bool_t (*xdr_u_int)(XDR *, unsigned *);
|
|
|
|
bool_t (*xdr_u_longlong_t)(XDR *, u_longlong_t *);
|
|
|
|
|
|
|
|
bool_t (*xdr_opaque)(XDR *, caddr_t, const uint_t);
|
|
|
|
bool_t (*xdr_string)(XDR *, char **, const uint_t);
|
|
|
|
bool_t (*xdr_array)(XDR *, caddr_t *, uint_t *, const uint_t,
|
2018-02-07 22:49:38 +03:00
|
|
|
const uint_t, const xdrproc_t);
|
2009-03-10 22:51:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XDR control operator.
|
|
|
|
*/
|
2018-02-07 22:49:38 +03:00
|
|
|
#define XDR_GET_BYTES_AVAIL 1
|
2009-03-10 22:51:45 +03:00
|
|
|
|
|
|
|
struct xdr_bytesrec {
|
|
|
|
bool_t xc_is_last_record;
|
|
|
|
size_t xc_num_avail;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XDR functions.
|
|
|
|
*/
|
|
|
|
void xdrmem_create(XDR *xdrs, const caddr_t addr, const uint_t size,
|
|
|
|
const enum xdr_op op);
|
|
|
|
|
2018-02-07 22:49:38 +03:00
|
|
|
/* Currently not needed. If needed later, we'll add it to struct xdr_ops */
|
|
|
|
#define xdr_destroy(xdrs) ((void) 0)
|
|
|
|
|
|
|
|
#define xdr_control(xdrs, req, info) \
|
|
|
|
(xdrs)->x_ops->xdr_control((xdrs), (req), (info))
|
2009-03-10 22:51:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For precaution, the following are defined as static inlines instead of macros
|
|
|
|
* to get some amount of type safety.
|
|
|
|
*
|
|
|
|
* Also, macros wouldn't work in the case where typecasting is done, because it
|
|
|
|
* must be possible to reference the functions' addresses by these names.
|
|
|
|
*/
|
|
|
|
static inline bool_t xdr_char(XDR *xdrs, char *cp)
|
|
|
|
{
|
2018-02-07 22:49:38 +03:00
|
|
|
return (xdrs->x_ops->xdr_char(xdrs, cp));
|
2009-03-10 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool_t xdr_u_short(XDR *xdrs, unsigned short *usp)
|
|
|
|
{
|
2018-02-07 22:49:38 +03:00
|
|
|
return (xdrs->x_ops->xdr_u_short(xdrs, usp));
|
2009-03-10 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool_t xdr_short(XDR *xdrs, short *sp)
|
|
|
|
{
|
2018-02-07 22:49:38 +03:00
|
|
|
BUILD_BUG_ON(sizeof (short) != 2);
|
|
|
|
return (xdrs->x_ops->xdr_u_short(xdrs, (unsigned short *) sp));
|
2009-03-10 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool_t xdr_u_int(XDR *xdrs, unsigned *up)
|
|
|
|
{
|
2018-02-07 22:49:38 +03:00
|
|
|
return (xdrs->x_ops->xdr_u_int(xdrs, up));
|
2009-03-10 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool_t xdr_int(XDR *xdrs, int *ip)
|
|
|
|
{
|
2018-02-07 22:49:38 +03:00
|
|
|
BUILD_BUG_ON(sizeof (int) != 4);
|
|
|
|
return (xdrs->x_ops->xdr_u_int(xdrs, (unsigned *)ip));
|
2009-03-10 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool_t xdr_u_longlong_t(XDR *xdrs, u_longlong_t *ullp)
|
|
|
|
{
|
2018-02-07 22:49:38 +03:00
|
|
|
return (xdrs->x_ops->xdr_u_longlong_t(xdrs, ullp));
|
2009-03-10 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool_t xdr_longlong_t(XDR *xdrs, longlong_t *llp)
|
|
|
|
{
|
2018-02-07 22:49:38 +03:00
|
|
|
BUILD_BUG_ON(sizeof (longlong_t) != 8);
|
|
|
|
return (xdrs->x_ops->xdr_u_longlong_t(xdrs, (u_longlong_t *)llp));
|
2009-03-10 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fixed-length opaque data.
|
|
|
|
*/
|
|
|
|
static inline bool_t xdr_opaque(XDR *xdrs, caddr_t cp, const uint_t cnt)
|
|
|
|
{
|
2018-02-07 22:49:38 +03:00
|
|
|
return (xdrs->x_ops->xdr_opaque(xdrs, cp, cnt));
|
2009-03-10 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variable-length string.
|
|
|
|
* The *sp buffer must have (maxsize + 1) bytes.
|
|
|
|
*/
|
|
|
|
static inline bool_t xdr_string(XDR *xdrs, char **sp, const uint_t maxsize)
|
|
|
|
{
|
2018-02-07 22:49:38 +03:00
|
|
|
return (xdrs->x_ops->xdr_string(xdrs, sp, maxsize));
|
2009-03-10 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variable-length arrays.
|
|
|
|
*/
|
|
|
|
static inline bool_t xdr_array(XDR *xdrs, caddr_t *arrp, uint_t *sizep,
|
|
|
|
const uint_t maxsize, const uint_t elsize, const xdrproc_t elproc)
|
|
|
|
{
|
|
|
|
return xdrs->x_ops->xdr_array(xdrs, arrp, sizep, maxsize, elsize,
|
|
|
|
elproc);
|
|
|
|
}
|
2008-03-01 21:30:12 +03:00
|
|
|
|
|
|
|
#endif /* SPL_RPC_XDR_H */
|