]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - sys/cddl/contrib/opensolaris/uts/common/rpc/xdr.h
Copy head to stable/8 as part of 8.0 Release cycle.
[FreeBSD/stable/8.git] / sys / cddl / contrib / opensolaris / uts / common / rpc / xdr.h
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  *
21  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
22  * Use is subject to license terms.
23  */
24 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
25 /* All Rights Reserved */
26 /*
27  * Portions of this source code were derived from Berkeley
28  * 4.3 BSD under license from the Regents of the University of
29  * California.
30  */
31
32 /*
33  * xdr.h, External Data Representation Serialization Routines.
34  *
35  */
36
37 #ifndef _RPC_XDR_H
38 #define _RPC_XDR_H
39
40 #include <sys/byteorder.h>      /* For all ntoh* and hton*() kind of macros */
41 #include <rpc/types.h>  /* For all ntoh* and hton*() kind of macros */
42 #ifndef _KERNEL
43 #include <stdio.h> /* defines FILE *, used in ANSI C function prototypes */
44 #endif
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 /*
51  * XDR provides a conventional way for converting between C data
52  * types and an external bit-string representation.  Library supplied
53  * routines provide for the conversion on built-in C data types.  These
54  * routines and utility routines defined here are used to help implement
55  * a type encode/decode routine for each user-defined type.
56  *
57  * Each data type provides a single procedure which takes two arguments:
58  *
59  *      bool_t
60  *      xdrproc(xdrs, argresp)
61  *              XDR *xdrs;
62  *              <type> *argresp;
63  *
64  * xdrs is an instance of a XDR handle, to which or from which the data
65  * type is to be converted.  argresp is a pointer to the structure to be
66  * converted.  The XDR handle contains an operation field which indicates
67  * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
68  *
69  * XDR_DECODE may allocate space if the pointer argresp is null.  This
70  * data can be freed with the XDR_FREE operation.
71  *
72  * We write only one procedure per data type to make it easy
73  * to keep the encode and decode procedures for a data type consistent.
74  * In many cases the same code performs all operations on a user defined type,
75  * because all the hard work is done in the component type routines.
76  * decode as a series of calls on the nested data types.
77  */
78
79 /*
80  * Xdr operations.  XDR_ENCODE causes the type to be encoded into the
81  * stream.  XDR_DECODE causes the type to be extracted from the stream.
82  * XDR_FREE can be used to release the space allocated by an XDR_DECODE
83  * request.
84  */
85 enum xdr_op {
86         XDR_ENCODE = 0,
87         XDR_DECODE = 1,
88         XDR_FREE = 2
89 };
90
91 /*
92  * This is the number of bytes per unit of external data.
93  */
94 #define BYTES_PER_XDR_UNIT      (4)
95 #define RNDUP(x)  ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
96                     * BYTES_PER_XDR_UNIT)
97
98 /*
99  * The XDR handle.
100  * Contains operation which is being applied to the stream,
101  * an operations vector for the paticular implementation (e.g. see xdr_mem.c),
102  * and two private fields for the use of the particular impelementation.
103  *
104  * PSARC 2003/523 Contract Private Interface
105  * XDR
106  * Changes must be reviewed by Solaris File Sharing
107  * Changes must be communicated to contract-2003-523@sun.com
108  */
109 typedef struct XDR {
110         enum xdr_op     x_op;   /* operation; fast additional param */
111         struct xdr_ops *x_ops;
112         caddr_t         x_public; /* users' data */
113         caddr_t         x_private; /* pointer to private data */
114         caddr_t         x_base; /* private used for position info */
115         int             x_handy; /* extra private word */
116 } XDR;
117
118 /*
119  * PSARC 2003/523 Contract Private Interface
120  * xdr_ops
121  * Changes must be reviewed by Solaris File Sharing
122  * Changes must be communicated to contract-2003-523@sun.com
123  */
124 #ifndef __FreeBSD__     
125 struct xdr_ops {
126 #ifdef __STDC__
127 #if !defined(_KERNEL)
128                 bool_t  (*x_getlong)(struct XDR *, long *);
129                 /* get a long from underlying stream */
130                 bool_t  (*x_putlong)(struct XDR *, long *);
131                 /* put a long to " */
132 #endif /* KERNEL */
133                 bool_t  (*x_getbytes)(struct XDR *, caddr_t, int);
134                 /* get some bytes from " */
135                 bool_t  (*x_putbytes)(struct XDR *, caddr_t, int);
136                 /* put some bytes to " */
137                 uint_t  (*x_getpostn)(struct XDR *);
138                 /* returns bytes off from beginning */
139                 bool_t  (*x_setpostn)(struct XDR *, uint_t);
140                 /* lets you reposition the stream */
141                 rpc_inline_t *(*x_inline)(struct XDR *, int);
142                 /* buf quick ptr to buffered data */
143                 void    (*x_destroy)(struct XDR *);
144                 /* free privates of this xdr_stream */
145                 bool_t  (*x_control)(struct XDR *, int, void *);
146 #if defined(_LP64) || defined(_KERNEL)
147                 bool_t  (*x_getint32)(struct XDR *, int32_t *);
148                 /* get a int from underlying stream */
149                 bool_t  (*x_putint32)(struct XDR *, int32_t *);
150                 /* put an int to " */
151 #endif /* _LP64 || _KERNEL */
152 #else
153 #if !defined(_KERNEL)
154                 bool_t  (*x_getlong)(); /* get a long from underlying stream */
155                 bool_t  (*x_putlong)(); /* put a long to " */
156 #endif /* KERNEL */
157                 bool_t  (*x_getbytes)(); /* get some bytes from " */
158                 bool_t  (*x_putbytes)(); /* put some bytes to " */
159                 uint_t  (*x_getpostn)(); /* returns bytes off from beginning */
160                 bool_t  (*x_setpostn)(); /* lets you reposition the stream */
161                 rpc_inline_t *(*x_inline)();
162                                 /* buf quick ptr to buffered data */
163                 void    (*x_destroy)(); /* free privates of this xdr_stream */
164                 bool_t  (*x_control)();
165 #if defined(_LP64) || defined(_KERNEL)
166                 bool_t  (*x_getint32)();
167                 bool_t  (*x_putint32)();
168 #endif /* _LP64 || defined(_KERNEL) */
169 #endif
170 };
171
172 #else /* FreeBSD */
173 struct xdr_ops {
174         /* get a long from underlying stream */
175         bool_t  (*x_getint32)(struct XDR *, int32_t *);
176         /* put a long to " */
177         bool_t  (*x_putint32)(struct XDR *, const int32_t *);
178         /* get some bytes from " */
179         bool_t  (*x_getbytes)(struct XDR *, char *, u_int);
180         /* put some bytes to " */
181         bool_t  (*x_putbytes)(struct XDR *, const char *, u_int);
182         /* returns bytes off from beginning */
183         u_int   (*x_getpostn)(struct XDR *);
184         /* lets you reposition the stream */
185         bool_t  (*x_setpostn)(struct XDR *, u_int);
186         /* buf quick ptr to buffered data */
187         int32_t *(*x_inline)(struct XDR *, u_int);
188         /* free privates of this xdr_stream */
189         void    (*x_destroy)(struct XDR *);
190         bool_t  (*x_control)(struct XDR *, int, void *);
191 };
192 #endif
193         
194 /*
195  * Operations defined on a XDR handle
196  *
197  * XDR          *xdrs;
198  * long         *longp;
199  * caddr_t       addr;
200  * uint_t        len;
201  * uint_t        pos;
202  */
203 #if !defined(_KERNEL)
204 #define XDR_GETLONG(xdrs, longp)                        \
205         (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
206 #define xdr_getlong(xdrs, longp)                        \
207         (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
208
209 #define XDR_PUTLONG(xdrs, longp)                        \
210         (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
211 #define xdr_putlong(xdrs, longp)                        \
212         (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
213 #endif /* KERNEL */
214
215
216 #if !defined(_LP64) && !defined(_KERNEL)
217
218 /*
219  * For binary compatability on ILP32 we do not change the shape
220  * of the XDR structure and the GET/PUTINT32 functions just use
221  * the get/putlong vectors which operate on identically-sized
222  * units of data.
223  */
224
225 #define XDR_GETINT32(xdrs, int32p)                      \
226         (*(xdrs)->x_ops->x_getlong)(xdrs, (long *)int32p)
227 #define xdr_getint32(xdrs, int32p)                      \
228         (*(xdrs)->x_ops->x_getlong)(xdrs, (long *)int32p)
229
230 #define XDR_PUTINT32(xdrs, int32p)                      \
231         (*(xdrs)->x_ops->x_putlong)(xdrs, (long *)int32p)
232 #define xdr_putint32(xdrs, int32p)                      \
233         (*(xdrs)->x_ops->x_putlong)(xdrs, (long *)int32p)
234
235 #else /* !_LP64 && !_KERNEL */
236
237 #define XDR_GETINT32(xdrs, int32p)                      \
238         (*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
239 #define xdr_getint32(xdrs, int32p)                      \
240         (*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
241
242 #define XDR_PUTINT32(xdrs, int32p)                      \
243         (*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
244 #define xdr_putint32(xdrs, int32p)                      \
245         (*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
246
247 #endif /* !_LP64 && !_KERNEL */
248
249 #define XDR_GETBYTES(xdrs, addr, len)                   \
250         (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
251 #define xdr_getbytes(xdrs, addr, len)                   \
252         (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
253
254 #define XDR_PUTBYTES(xdrs, addr, len)                   \
255         (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
256 #define xdr_putbytes(xdrs, addr, len)                   \
257         (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
258
259 #define XDR_GETPOS(xdrs)                                \
260         (*(xdrs)->x_ops->x_getpostn)(xdrs)
261 #define xdr_getpos(xdrs)                                \
262         (*(xdrs)->x_ops->x_getpostn)(xdrs)
263
264 #define XDR_SETPOS(xdrs, pos)                           \
265         (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
266 #define xdr_setpos(xdrs, pos)                           \
267         (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
268
269 #define XDR_INLINE(xdrs, len)                           \
270         (*(xdrs)->x_ops->x_inline)(xdrs, len)
271 #define xdr_inline(xdrs, len)                           \
272         (*(xdrs)->x_ops->x_inline)(xdrs, len)
273
274 #define XDR_DESTROY(xdrs)                               \
275         (*(xdrs)->x_ops->x_destroy)(xdrs)
276 #define xdr_destroy(xdrs)                               \
277         (*(xdrs)->x_ops->x_destroy)(xdrs)
278
279 #define XDR_CONTROL(xdrs, req, op)                      \
280         (*(xdrs)->x_ops->x_control)(xdrs, req, op)
281 #define xdr_control(xdrs, req, op)                      \
282         (*(xdrs)->x_ops->x_control)(xdrs, req, op)
283
284 /*
285  * Support struct for discriminated unions.
286  * You create an array of xdrdiscrim structures, terminated with
287  * a entry with a null procedure pointer.  The xdr_union routine gets
288  * the discriminant value and then searches the array of structures
289  * for a matching value.  If a match is found the associated xdr routine
290  * is called to handle that part of the union.  If there is
291  * no match, then a default routine may be called.
292  * If there is no match and no default routine it is an error.
293  */
294
295
296 /*
297  * A xdrproc_t exists for each data type which is to be encoded or decoded.
298  *
299  * The second argument to the xdrproc_t is a pointer to an opaque pointer.
300  * The opaque pointer generally points to a structure of the data type
301  * to be decoded.  If this pointer is 0, then the type routines should
302  * allocate dynamic storage of the appropriate size and return it.
303  * bool_t       (*xdrproc_t)(XDR *, void *);
304  */
305 #ifdef __cplusplus
306 typedef bool_t (*xdrproc_t)(XDR *, void *);
307 #else
308 #ifdef __STDC__
309 typedef bool_t (*xdrproc_t)(); /* For Backward compatibility */
310 #else
311 typedef bool_t (*xdrproc_t)();
312 #endif
313 #endif
314
315 #define NULL_xdrproc_t ((xdrproc_t)0)
316
317 #if defined(_LP64) || defined(_I32LPx)
318 #define xdr_rpcvers(xdrs, versp)        xdr_u_int(xdrs, versp)
319 #define xdr_rpcprog(xdrs, progp)        xdr_u_int(xdrs, progp)
320 #define xdr_rpcproc(xdrs, procp)        xdr_u_int(xdrs, procp)
321 #define xdr_rpcprot(xdrs, protp)        xdr_u_int(xdrs, protp)
322 #define xdr_rpcport(xdrs, portp)        xdr_u_int(xdrs, portp)
323 #else
324 #define xdr_rpcvers(xdrs, versp)        xdr_u_long(xdrs, versp)
325 #define xdr_rpcprog(xdrs, progp)        xdr_u_long(xdrs, progp)
326 #define xdr_rpcproc(xdrs, procp)        xdr_u_long(xdrs, procp)
327 #define xdr_rpcprot(xdrs, protp)        xdr_u_long(xdrs, protp)
328 #define xdr_rpcport(xdrs, portp)        xdr_u_long(xdrs, portp)
329 #endif
330
331 struct xdr_discrim {
332         int     value;
333         xdrproc_t proc;
334 };
335
336 /*
337  * In-line routines for fast encode/decode of primitve data types.
338  * Caveat emptor: these use single memory cycles to get the
339  * data from the underlying buffer, and will fail to operate
340  * properly if the data is not aligned.  The standard way to use these
341  * is to say:
342  *      if ((buf = XDR_INLINE(xdrs, count)) == NULL)
343  *              return (FALSE);
344  *      <<< macro calls >>>
345  * where ``count'' is the number of bytes of data occupied
346  * by the primitive data types.
347  *
348  * N.B. and frozen for all time: each data type here uses 4 bytes
349  * of external representation.
350  */
351
352 #define IXDR_GET_INT32(buf)             ((int32_t)ntohl((uint32_t)*(buf)++))
353 #define IXDR_PUT_INT32(buf, v)          (*(buf)++ = (int32_t)htonl((uint32_t)v))
354 #define IXDR_GET_U_INT32(buf)           ((uint32_t)IXDR_GET_INT32(buf))
355 #define IXDR_PUT_U_INT32(buf, v)        IXDR_PUT_INT32((buf), ((int32_t)(v)))
356
357 #if !defined(_KERNEL) && !defined(_LP64)
358
359 #define IXDR_GET_LONG(buf)              ((long)ntohl((ulong_t)*(buf)++))
360 #define IXDR_PUT_LONG(buf, v)           (*(buf)++ = (long)htonl((ulong_t)v))
361 #define IXDR_GET_U_LONG(buf)            ((ulong_t)IXDR_GET_LONG(buf))
362 #define IXDR_PUT_U_LONG(buf, v)         IXDR_PUT_LONG((buf), ((long)(v)))
363
364 #define IXDR_GET_BOOL(buf)              ((bool_t)IXDR_GET_LONG(buf))
365 #define IXDR_GET_ENUM(buf, t)           ((t)IXDR_GET_LONG(buf))
366 #define IXDR_GET_SHORT(buf)             ((short)IXDR_GET_LONG(buf))
367 #define IXDR_GET_U_SHORT(buf)           ((ushort_t)IXDR_GET_LONG(buf))
368
369 #define IXDR_PUT_BOOL(buf, v)           IXDR_PUT_LONG((buf), ((long)(v)))
370 #define IXDR_PUT_ENUM(buf, v)           IXDR_PUT_LONG((buf), ((long)(v)))
371 #define IXDR_PUT_SHORT(buf, v)          IXDR_PUT_LONG((buf), ((long)(v)))
372 #define IXDR_PUT_U_SHORT(buf, v)        IXDR_PUT_LONG((buf), ((long)(v)))
373
374 #else
375
376 #define IXDR_GET_BOOL(buf)              ((bool_t)IXDR_GET_INT32(buf))
377 #define IXDR_GET_ENUM(buf, t)           ((t)IXDR_GET_INT32(buf))
378 #define IXDR_GET_SHORT(buf)             ((short)IXDR_GET_INT32(buf))
379 #define IXDR_GET_U_SHORT(buf)           ((ushort_t)IXDR_GET_INT32(buf))
380
381 #define IXDR_PUT_BOOL(buf, v)           IXDR_PUT_INT32((buf), ((int)(v)))
382 #define IXDR_PUT_ENUM(buf, v)           IXDR_PUT_INT32((buf), ((int)(v)))
383 #define IXDR_PUT_SHORT(buf, v)          IXDR_PUT_INT32((buf), ((int)(v)))
384 #define IXDR_PUT_U_SHORT(buf, v)        IXDR_PUT_INT32((buf), ((int)(v)))
385
386 #endif
387
388 #if BYTE_ORDER == _LITTLE_ENDIAN
389 #define IXDR_GET_HYPER(buf, v)  { \
390                         *((int32_t *)(&v)) = ntohl(*(uint32_t *)buf++); \
391                         *((int32_t *)(((char *)&v) + BYTES_PER_XDR_UNIT)) \
392                         = ntohl(*(uint32_t *)buf++); \
393                         }
394 #define IXDR_PUT_HYPER(buf, v)  { \
395                         *(buf)++ = (int32_t)htonl(*(uint32_t *) \
396                                 ((char *)&v)); \
397                         *(buf)++ = \
398                                 (int32_t)htonl(*(uint32_t *)(((char *)&v) \
399                                 + BYTES_PER_XDR_UNIT)); \
400                         }
401 #else
402
403 #define IXDR_GET_HYPER(buf, v)  { \
404                         *((int32_t *)(((char *)&v) + \
405                                 BYTES_PER_XDR_UNIT)) \
406                                 = ntohl(*(uint32_t *)buf++); \
407                         *((int32_t *)(&v)) = \
408                                 ntohl(*(uint32_t *)buf++); \
409                         }
410
411 #define IXDR_PUT_HYPER(buf, v)  { \
412                         *(buf)++ = \
413                                 (int32_t)htonl(*(uint32_t *)(((char *)&v) + \
414                                 BYTES_PER_XDR_UNIT)); \
415                         *(buf)++ = \
416                                 (int32_t)htonl(*(uint32_t *)((char *)&v)); \
417                         }
418 #endif
419 #define IXDR_GET_U_HYPER(buf, v)        IXDR_GET_HYPER(buf, v)
420 #define IXDR_PUT_U_HYPER(buf, v)        IXDR_PUT_HYPER(buf, v)
421
422
423 /*
424  * These are the "generic" xdr routines.
425  */
426 #ifdef __STDC__
427 extern bool_t   xdr_void(void);
428 extern bool_t   xdr_int(XDR *, int *);
429 extern bool_t   xdr_u_int(XDR *, uint_t *);
430 extern bool_t   xdr_long(XDR *, long *);
431 extern bool_t   xdr_u_long(XDR *, ulong_t *);
432 extern bool_t   xdr_short(XDR *, short *);
433 extern bool_t   xdr_u_short(XDR *, ushort_t *);
434 extern bool_t   xdr_bool(XDR *, bool_t *);
435 extern bool_t   xdr_enum(XDR *, enum_t *);
436 extern bool_t   xdr_array(XDR *, caddr_t *, uint_t *, const uint_t,
437                     const uint_t, const xdrproc_t);
438 extern bool_t   xdr_bytes(XDR *, char **, uint_t *, const uint_t);
439 extern bool_t   xdr_opaque(XDR *, caddr_t, const uint_t);
440 extern bool_t   xdr_string(XDR *, char **, const uint_t);
441 extern bool_t   xdr_union(XDR *, enum_t *, char *,
442                     const struct xdr_discrim *, const xdrproc_t);
443 extern unsigned int  xdr_sizeof(xdrproc_t, void *);
444
445 extern bool_t   xdr_hyper(XDR *, longlong_t *);
446 extern bool_t   xdr_longlong_t(XDR *, longlong_t *);
447 extern bool_t   xdr_u_hyper(XDR *, u_longlong_t *);
448 extern bool_t   xdr_u_longlong_t(XDR *, u_longlong_t *);
449
450 extern bool_t   xdr_char(XDR *, char *);
451 extern bool_t   xdr_wrapstring(XDR *, char **);
452 extern bool_t   xdr_reference(XDR *, caddr_t *, uint_t, const xdrproc_t);
453 extern bool_t   xdr_pointer(XDR *, char **, uint_t, const xdrproc_t);
454 extern void     xdr_free(xdrproc_t, char *);
455 extern bool_t   xdr_time_t(XDR *, time_t *);
456
457 extern bool_t   xdr_int8_t(XDR *, int8_t *);
458 extern bool_t   xdr_uint8_t(XDR *, uint8_t *);
459 extern bool_t   xdr_int16_t(XDR *, int16_t *);
460 extern bool_t   xdr_uint16_t(XDR *, uint16_t *);
461 extern bool_t   xdr_int32_t(XDR *, int32_t *);
462 extern bool_t   xdr_uint32_t(XDR *, uint32_t *);
463 #if defined(_INT64_TYPE)
464 extern bool_t   xdr_int64_t(XDR *, int64_t *);
465 extern bool_t   xdr_uint64_t(XDR *, uint64_t *);
466 #endif
467
468 #ifndef _KERNEL
469 extern bool_t   xdr_u_char(XDR *, uchar_t *);
470 extern bool_t   xdr_vector(XDR *, char *, const uint_t, const uint_t, const
471 xdrproc_t);
472 extern bool_t   xdr_float(XDR *, float *);
473 extern bool_t   xdr_double(XDR *, double *);
474 extern bool_t   xdr_quadruple(XDR *, long double *);
475 #endif /* !_KERNEL */
476 #else
477 extern bool_t   xdr_void();
478 extern bool_t   xdr_int();
479 extern bool_t   xdr_u_int();
480 extern bool_t   xdr_long();
481 extern bool_t   xdr_u_long();
482 extern bool_t   xdr_short();
483 extern bool_t   xdr_u_short();
484 extern bool_t   xdr_bool();
485 extern bool_t   xdr_enum();
486 extern bool_t   xdr_array();
487 extern bool_t   xdr_bytes();
488 extern bool_t   xdr_opaque();
489 extern bool_t   xdr_string();
490 extern bool_t   xdr_union();
491
492 extern bool_t   xdr_hyper();
493 extern bool_t   xdr_longlong_t();
494 extern bool_t   xdr_u_hyper();
495 extern bool_t   xdr_u_longlong_t();
496 extern bool_t   xdr_char();
497 extern bool_t   xdr_reference();
498 extern bool_t   xdr_pointer();
499 extern void     xdr_free();
500 extern bool_t   xdr_wrapstring();
501 extern bool_t   xdr_time_t();
502
503 extern bool_t   xdr_int8_t();
504 extern bool_t   xdr_uint8_t();
505 extern bool_t   xdr_int16_t();
506 extern bool_t   xdr_uint16_t();
507 extern bool_t   xdr_int32_t();
508 extern bool_t   xdr_uint32_t();
509 #if defined(_INT64_TYPE)
510 extern bool_t   xdr_int64_t();
511 extern bool_t   xdr_uint64_t();
512 #endif
513
514 #ifndef _KERNEL
515 extern bool_t   xdr_u_char();
516 extern bool_t   xdr_vector();
517 extern bool_t   xdr_float();
518 extern bool_t   xdr_double();
519 extern bool_t   xdr_quadruple();
520 #endif /* !_KERNEL */
521 #endif
522
523 /*
524  * Common opaque bytes objects used by many rpc protocols;
525  * declared here due to commonality.
526  */
527 #define MAX_NETOBJ_SZ 1024
528 struct netobj {
529         uint_t  n_len;
530         char    *n_bytes;
531 };
532 typedef struct netobj netobj;
533
534 #ifdef __STDC__
535 extern bool_t   xdr_netobj(XDR *, netobj *);
536 #else
537 extern bool_t   xdr_netobj();
538 #endif
539
540 /*
541  * These are XDR control operators
542  */
543
544 #define XDR_GET_BYTES_AVAIL 1
545
546 struct xdr_bytesrec {
547         bool_t xc_is_last_record;
548         size_t xc_num_avail;
549 };
550
551 typedef struct xdr_bytesrec xdr_bytesrec;
552
553 /*
554  * These are the request arguments to XDR_CONTROL.
555  *
556  * XDR_PEEK - returns the contents of the next XDR unit on the XDR stream.
557  * XDR_SKIPBYTES - skips the next N bytes in the XDR stream.
558  * XDR_RDMAGET - for xdr implementation over RDMA, gets private flags from
559  *               the XDR stream being moved over RDMA
560  * XDR_RDMANOCHUNK - for xdr implementaion over RDMA, sets private flags in
561  *                   the XDR stream moving over RDMA.
562  */
563 #ifdef _KERNEL
564 #define XDR_PEEK                2
565 #define XDR_SKIPBYTES           3
566 #define XDR_RDMA_GET_FLAGS      4
567 #define XDR_RDMA_SET_FLAGS      5
568 #define XDR_RDMA_ADD_CHUNK      6
569 #define XDR_RDMA_GET_CHUNK_LEN  7
570 #define XDR_RDMA_SET_WLIST      8
571 #define XDR_RDMA_GET_WLIST      9
572 #define XDR_RDMA_GET_WCINFO     10
573 #define XDR_RDMA_GET_RLIST      11
574 #endif
575
576 /*
577  * These are the public routines for the various implementations of
578  * xdr streams.
579  */
580 #ifndef _KERNEL
581 #ifdef __STDC__
582 extern void   xdrmem_create(XDR *, const caddr_t, const uint_t, const enum
583 xdr_op);
584         /* XDR using memory buffers */
585 extern void   xdrrec_create(XDR *, const uint_t, const uint_t, const caddr_t,
586 int (*) (void *, caddr_t, int), int (*) (void *, caddr_t, int));
587 /* XDR pseudo records for tcp */
588 extern bool_t xdrrec_endofrecord(XDR *, bool_t);
589 /* make end of xdr record */
590 extern bool_t xdrrec_skiprecord(XDR *);
591 /* move to beginning of next record */
592 extern bool_t xdrrec_eof(XDR *);
593 extern uint_t xdrrec_readbytes(XDR *, caddr_t, uint_t);
594 /* true if no more input */
595 #else
596 extern void   xdrmem_create();
597 extern void   xdrstdio_create();
598 extern void   xdrrec_create();
599 extern bool_t xdrrec_endofrecord();
600 extern bool_t xdrrec_skiprecord();
601 extern bool_t xdrrec_eof();
602 extern uint_t xdrrec_readbytes();
603 #endif
604 #else
605
606 extern void     xdrmem_create(XDR *, caddr_t, uint_t, enum xdr_op);
607 extern struct xdr_ops xdrmblk_ops;
608 extern struct xdr_ops xdrrdmablk_ops;
609 extern struct xdr_ops xdrrdma_ops;
610
611 struct rpc_msg;
612 extern bool_t   xdr_callmsg(XDR *, struct rpc_msg *);
613 extern bool_t   xdr_replymsg_body(XDR *, struct rpc_msg *);
614 extern bool_t   xdr_replymsg_hdr(XDR *, struct rpc_msg *);
615
616 #include <sys/malloc.h>
617 #ifdef  mem_alloc
618 #undef  mem_alloc
619 #define mem_alloc(size)         malloc((size), M_TEMP, M_WAITOK | M_ZERO)
620 #endif
621 #ifdef  mem_free
622 #undef  mem_free
623 #define mem_free(ptr, size)     free((ptr), M_TEMP)
624 #endif
625
626 #endif /* !_KERNEL */
627
628 #ifdef __cplusplus
629 }
630 #endif
631
632 #endif  /* !_RPC_XDR_H */