Date: Mon, 11 May 2009 12:23:38 -0700 From: Kip Macy <kmacy@freebsd.org> To: Doug Rabson <dfr@rabson.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r191984 - in head/sys: cddl/contrib/opensolaris/uts/common/rpc modules/zfs Message-ID: <3c1674c90905111223u74ec12ch9f40772940a42396@mail.gmail.com> In-Reply-To: <0E48393C-F519-42A1-AD3C-3EC31EE2AE06@rabson.org> References: <200905110418.n4B4IxPC077484@svn.freebsd.org> <0E48393C-F519-42A1-AD3C-3EC31EE2AE06@rabson.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, May 11, 2009 at 11:21 AM, Doug Rabson <dfr@rabson.org> wrote: > The XDR support code that is in the main kernel should have a very simila= r > API to the opensolaris bits, possibly identical. Perhaps the opensolaris > compat could use the main kernel's XDR implementation? I tried that. The label reads end up failing when ZFS uses the libkern implementation. Somewhere in there, there is a behavioral difference between the two implementations. At some point I'll track down the offending function. -Kip > > On 11 May 2009, at 05:18, Kip Macy wrote: > >> Author: kmacy >> Date: Mon May 11 04:18:58 2009 >> New Revision: 191984 >> URL: http://svn.freebsd.org/changeset/base/191984 >> >> Log: >> =A0rename xdr support files to avoid conflicts when linking in to the ke= rnel >> >> Added: >> =A0head/sys/cddl/contrib/opensolaris/uts/common/rpc/opensolaris_xdr.c >> (props changed) >> =A0 =A0- copied unchanged from r191983, >> head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr.c >> =A0head/sys/cddl/contrib/opensolaris/uts/common/rpc/opensolaris_xdr_arra= y.c >> =A0 (props changed) >> =A0 =A0- copied unchanged from r191983, >> head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr_array.c >> =A0head/sys/cddl/contrib/opensolaris/uts/common/rpc/opensolaris_xdr_mem.= c >> (props changed) >> =A0 =A0- copied unchanged from r191983, >> head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr_mem.c >> Deleted: >> =A0head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr.c >> =A0head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr_array.c >> =A0head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr_mem.c >> Modified: >> =A0head/sys/modules/zfs/Makefile >> >> Copied: head/sys/cddl/contrib/opensolaris/uts/common/rpc/opensolaris_xdr= .c >> (from r191983, head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr.c) >> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >> --- /dev/null =A0 00:00:00 1970 =A0 (empty, because file is newly added) >> +++ head/sys/cddl/contrib/opensolaris/uts/common/rpc/opensolaris_xdr.c >> =A0 Mon May 11 04:18:58 2009 =A0 =A0 =A0 =A0(r191984, copy of r191983, >> head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr.c) >> @@ -0,0 +1,621 @@ >> +/* >> + * CDDL HEADER START >> + * >> + * The contents of this file are subject to the terms of the >> + * Common Development and Distribution License (the "License"). >> + * You may not use this file except in compliance with the License. >> + * >> + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE >> + * or http://www.opensolaris.org/os/licensing. >> + * See the License for the specific language governing permissions >> + * and limitations under the License. >> + * >> + * When distributing Covered Code, include this CDDL HEADER in each >> + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. >> + * If applicable, add the following below this CDDL HEADER, with the >> + * fields enclosed by brackets "[]" replaced with your own identifying >> + * information: Portions Copyright [yyyy] [name of copyright owner] >> + * >> + * CDDL HEADER END >> + */ >> +/* >> + * Copyright 2008 Sun Microsystems, Inc. =A0All rights reserved. >> + * Use is subject to license terms. >> + */ >> + >> +/* =A0 =A0 Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T = =A0 =A0 */ >> +/* =A0 =A0 =A0 All Rights Reserved =A0 */ >> + >> +/* >> + * Portions of this source code were derived from Berkeley 4.3 BSD >> + * under license from the Regents of the University of California. >> + */ >> + >> +/* >> + * xdr.c, generic XDR routines implementation. >> + * These are the "generic" xdr routines used to serialize and >> de-serialize >> + * most common data items. =A0See xdr.h for more info on the interface = to >> + * xdr. >> + */ >> + >> +#include <sys/param.h> >> +#include <sys/cmn_err.h> >> +#include <sys/types.h> >> +#include <sys/systm.h> >> + >> +#include <rpc/types.h> >> +#include <rpc/xdr.h> >> + >> +#pragma weak xdr_int32_t =3D xdr_int >> +#pragma weak xdr_uint32_t =3D xdr_u_int >> +#pragma weak xdr_int64_t =3D xdr_longlong_t >> +#pragma weak xdr_uint64_t =3D xdr_u_longlong_t >> + >> +#if defined(sun) >> +#if !defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) >> +#error "Exactly one of _BIG_ENDIAN or _LITTLE_ENDIAN must be defined" >> +#elif defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) >> +#error "Only one of _BIG_ENDIAN or _LITTLE_ENDIAN may be defined" >> +#endif >> +#endif >> + >> +/* >> + * constants specific to the xdr "protocol" >> + */ >> +#define =A0 =A0 =A0 =A0XDR_FALSE =A0 =A0 =A0 ((int32_t)0) >> +#define =A0 =A0 =A0 =A0XDR_TRUE =A0 =A0 =A0 =A0((int32_t)1) >> +#define =A0 =A0 =A0 =A0LASTUNSIGNED =A0 =A0((uint_t)0-1) >> + >> +/* >> + * for unit alignment >> + */ >> +static char xdr_zero[BYTES_PER_XDR_UNIT] =3D { 0, 0, 0, 0 }; >> + >> +/* >> + * Free a data structure using XDR >> + * Not a filter, but a convenient utility nonetheless >> + */ >> +void >> +xdr_free(xdrproc_t proc, char *objp) >> +{ >> + =A0 =A0 =A0 XDR x; >> + >> + =A0 =A0 =A0 x.x_op =3D XDR_FREE; >> + =A0 =A0 =A0 (*proc)(&x, objp); >> +} >> + >> +/* >> + * XDR nothing >> + */ >> +bool_t >> +xdr_void(void) >> +{ >> + =A0 =A0 =A0 return (TRUE); >> +} >> + >> +/* >> + * XDR integers >> + * >> + * PSARC 2003/523 Contract Private Interface >> + * xdr_int >> + * Changes must be reviewed by Solaris File Sharing >> + * Changes must be communicated to contract-2003-523@sun.com >> + */ >> +bool_t >> +xdr_int(XDR *xdrs, int *ip) >> +{ >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_ENCODE) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_PUTINT32(xdrs, ip)); >> + >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_DECODE) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_GETINT32(xdrs, ip)); >> + >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_FREE) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 return (FALSE); >> +} >> + >> +/* >> + * XDR unsigned integers >> + * >> + * PSARC 2003/523 Contract Private Interface >> + * xdr_u_int >> + * Changes must be reviewed by Solaris File Sharing >> + * Changes must be communicated to contract-2003-523@sun.com >> + */ >> +bool_t >> +xdr_u_int(XDR *xdrs, uint_t *up) >> +{ >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_ENCODE) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_PUTINT32(xdrs, (int32_t *)up))= ; >> + >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_DECODE) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_GETINT32(xdrs, (int32_t *)up))= ; >> + >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_FREE) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 return (FALSE); >> +} >> + >> + >> +#if defined(_ILP32) >> +/* >> + * xdr_long and xdr_u_long for binary compatability on ILP32 kernels. >> + * >> + * No prototypes since new code should not be using these interfaces. >> + */ >> +bool_t >> +xdr_long(XDR *xdrs, long *ip) >> +{ >> + =A0 =A0 =A0 return (xdr_int(xdrs, (int *)ip)); >> +} >> + >> +bool_t >> +xdr_u_long(XDR *xdrs, unsigned long *up) >> +{ >> + =A0 =A0 =A0 return (xdr_u_int(xdrs, (uint_t *)up)); >> +} >> +#endif /* _ILP32 */ >> + >> + >> +/* >> + * XDR long long integers >> + */ >> +bool_t >> +xdr_longlong_t(XDR *xdrs, longlong_t *hp) >> +{ >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_ENCODE) { >> +#if BYTE_ORDER =3D=3D _LITTLE_ENDIAN >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (XDR_PUTINT32(xdrs, (int32_t *)((char *= )hp + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BYTES_PER_XDR_UNIT)) =3D=3D TRUE) = { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_PUTINT32(xdrs,= (int32_t *)hp)); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> +#else >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (XDR_PUTINT32(xdrs, (int32_t *)hp) =3D= =3D TRUE) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_PUTINT32(xdrs,= (int32_t *)((char *)hp >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BYTES_PER_XDR_UNIT= ))); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> +#endif >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_DECODE) { >> +#if BYTE_ORDER =3D=3D _LITTLE_ENDIAN >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (XDR_GETINT32(xdrs, (int32_t *)((char *= )hp + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BYTES_PER_XDR_UNIT)) =3D=3D TRUE) = { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_GETINT32(xdrs,= (int32_t *)hp)); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> +#else >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (XDR_GETINT32(xdrs, (int32_t *)hp) =3D= =3D TRUE) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_GETINT32(xdrs,= (int32_t *)((char *)hp >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BYTES_PER_XDR_UNIT= ))); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> +#endif >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (TRUE); >> +} >> + >> +/* >> + * XDR unsigned long long integers >> + */ >> +bool_t >> +xdr_u_longlong_t(XDR *xdrs, u_longlong_t *hp) >> +{ >> + >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_ENCODE) { >> +#if BYTE_ORDER =3D=3D _LITTLE_ENDIAN >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (XDR_PUTINT32(xdrs, (int32_t *)((char *= )hp + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BYTES_PER_XDR_UNIT)) =3D=3D TRUE) = { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_PUTINT32(xdrs,= (int32_t *)hp)); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> +#else >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (XDR_PUTINT32(xdrs, (int32_t *)hp) =3D= =3D TRUE) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_PUTINT32(xdrs,= (int32_t *)((char *)hp >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BYTES_PER_XDR_UNIT= ))); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> +#endif >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_DECODE) { >> +#if BYTE_ORDER =3D=3D _LITTLE_ENDIAN >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (XDR_GETINT32(xdrs, (int32_t *)((char *= )hp + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BYTES_PER_XDR_UNIT)) =3D=3D TRUE) = { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_GETINT32(xdrs,= (int32_t *)hp)); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> +#else >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (XDR_GETINT32(xdrs, (int32_t *)hp) =3D= =3D TRUE) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_GETINT32(xdrs,= (int32_t *)((char *)hp >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BYTES_PER_XDR_UNIT= ))); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> +#endif >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (TRUE); >> +} >> + >> +/* >> + * XDR short integers >> + */ >> +bool_t >> +xdr_short(XDR *xdrs, short *sp) >> +{ >> + =A0 =A0 =A0 int32_t l; >> + >> + =A0 =A0 =A0 switch (xdrs->x_op) { >> + >> + =A0 =A0 =A0 case XDR_ENCODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 l =3D (int32_t)*sp; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_PUTINT32(xdrs, &l)); >> + >> + =A0 =A0 =A0 case XDR_DECODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!XDR_GETINT32(xdrs, &l)) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *sp =3D (short)l; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 case XDR_FREE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (FALSE); >> +} >> + >> +/* >> + * XDR unsigned short integers >> + */ >> +bool_t >> +xdr_u_short(XDR *xdrs, ushort_t *usp) >> +{ >> + =A0 =A0 =A0 uint32_t l; >> + >> + =A0 =A0 =A0 switch (xdrs->x_op) { >> + >> + =A0 =A0 =A0 case XDR_ENCODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 l =3D (uint32_t)*usp; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_PUTINT32(xdrs, (int32_t *)&l))= ; >> + >> + =A0 =A0 =A0 case XDR_DECODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!XDR_GETINT32(xdrs, (int32_t *)&l)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *usp =3D (ushort_t)l; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 case XDR_FREE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (FALSE); >> +} >> + >> + >> +/* >> + * XDR a char >> + */ >> +bool_t >> +xdr_char(XDR *xdrs, char *cp) >> +{ >> + =A0 =A0 =A0 int i; >> + >> + =A0 =A0 =A0 i =3D (*cp); >> + =A0 =A0 =A0 if (!xdr_int(xdrs, &i)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 *cp =3D (char)i; >> + =A0 =A0 =A0 return (TRUE); >> +} >> + >> +/* >> + * XDR booleans >> + * >> + * PSARC 2003/523 Contract Private Interface >> + * xdr_bool >> + * Changes must be reviewed by Solaris File Sharing >> + * Changes must be communicated to contract-2003-523@sun.com >> + */ >> +bool_t >> +xdr_bool(XDR *xdrs, bool_t *bp) >> +{ >> + =A0 =A0 =A0 int32_t i32b; >> + >> + =A0 =A0 =A0 switch (xdrs->x_op) { >> + >> + =A0 =A0 =A0 case XDR_ENCODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 i32b =3D *bp ? XDR_TRUE : XDR_FALSE; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_PUTINT32(xdrs, &i32b)); >> + >> + =A0 =A0 =A0 case XDR_DECODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!XDR_GETINT32(xdrs, &i32b)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *bp =3D (i32b =3D=3D XDR_FALSE) ? FALSE : = TRUE; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 case XDR_FREE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (FALSE); >> +} >> + >> +/* >> + * XDR enumerations >> + * >> + * PSARC 2003/523 Contract Private Interface >> + * xdr_enum >> + * Changes must be reviewed by Solaris File Sharing >> + * Changes must be communicated to contract-2003-523@sun.com >> + */ >> +#ifndef lint >> +enum sizecheck { SIZEVAL } sizecheckvar; =A0 =A0 =A0 /* used to find th= e size >> of */ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 /* an enum */ >> +#endif >> +bool_t >> +xdr_enum(XDR *xdrs, enum_t *ep) >> +{ >> +#ifndef lint >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* enums are treated as ints >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 if (sizeof (sizecheckvar) =3D=3D sizeof (int32_t)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (xdr_int(xdrs, (int32_t *)ep)); >> + =A0 =A0 =A0 } else if (sizeof (sizecheckvar) =3D=3D sizeof (short)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (xdr_short(xdrs, (short *)ep)); >> + =A0 =A0 =A0 } else { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> +#else >> + =A0 =A0 =A0 (void) (xdr_short(xdrs, (short *)ep)); >> + =A0 =A0 =A0 return (xdr_int(xdrs, (int32_t *)ep)); >> +#endif >> +} >> + >> +/* >> + * XDR opaque data >> + * Allows the specification of a fixed size sequence of opaque bytes. >> + * cp points to the opaque object and cnt gives the byte length. >> + * >> + * PSARC 2003/523 Contract Private Interface >> + * xdr_opaque >> + * Changes must be reviewed by Solaris File Sharing >> + * Changes must be communicated to contract-2003-523@sun.com >> + */ >> +bool_t >> +xdr_opaque(XDR *xdrs, caddr_t cp, const uint_t cnt) >> +{ >> + =A0 =A0 =A0 uint_t rndup; >> + =A0 =A0 =A0 static char crud[BYTES_PER_XDR_UNIT]; >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* if no data we are done >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 if (cnt =3D=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* round byte count to full xdr units >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 rndup =3D cnt % BYTES_PER_XDR_UNIT; >> + =A0 =A0 =A0 if (rndup !=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rndup =3D BYTES_PER_XDR_UNIT - rndup; >> + >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_DECODE) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!XDR_GETBYTES(xdrs, cp, cnt)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (rndup =3D=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_GETBYTES(xdrs, (caddr_t)crud, = rndup)); >> + =A0 =A0 =A0 } >> + >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_ENCODE) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!XDR_PUTBYTES(xdrs, cp, cnt)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (rndup =3D=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (XDR_PUTBYTES(xdrs, xdr_zero, rndup= )); >> + =A0 =A0 =A0 } >> + >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_FREE) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 return (FALSE); >> +} >> + >> +/* >> + * XDR counted bytes >> + * *cpp is a pointer to the bytes, *sizep is the count. >> + * If *cpp is NULL maxsize bytes are allocated >> + * >> + * PSARC 2003/523 Contract Private Interface >> + * xdr_bytes >> + * Changes must be reviewed by Solaris File Sharing >> + * Changes must be communicated to contract-2003-523@sun.com >> + */ >> +bool_t >> +xdr_bytes(XDR *xdrs, char **cpp, uint_t *sizep, const uint_t maxsize) >> +{ >> + =A0 =A0 =A0 char *sp =3D *cpp; =A0/* sp is the actual string pointer *= / >> + =A0 =A0 =A0 uint_t nodesize; >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* first deal with the length since xdr bytes are counte= d >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 if (!xdr_u_int(xdrs, sizep)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 nodesize =3D *sizep; >> + =A0 =A0 =A0 if ((nodesize > maxsize) && (xdrs->x_op !=3D XDR_FREE)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* now deal with the actual bytes >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 switch (xdrs->x_op) { >> + =A0 =A0 =A0 case XDR_DECODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (nodesize =3D=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (sp =3D=3D NULL) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *cpp =3D sp =3D (char *)me= m_alloc(nodesize); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* FALLTHROUGH */ >> + >> + =A0 =A0 =A0 case XDR_ENCODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (xdr_opaque(xdrs, sp, nodesize)); >> + >> + =A0 =A0 =A0 case XDR_FREE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (sp !=3D NULL) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mem_free(sp, nodesize); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *cpp =3D NULL; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (FALSE); >> +} >> + >> +/* >> + * Implemented here due to commonality of the object. >> + */ >> +bool_t >> +xdr_netobj(XDR *xdrs, struct netobj *np) >> +{ >> + =A0 =A0 =A0 return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETO= BJ_SZ)); >> +} >> + >> +/* >> + * XDR a descriminated union >> + * Support routine for discriminated unions. >> + * You create an array of xdrdiscrim structures, terminated with >> + * an entry with a null procedure pointer. =A0The routine gets >> + * the discriminant value and then searches the array of xdrdiscrims >> + * looking for that value. =A0It calls the procedure given in the >> xdrdiscrim >> + * to handle the discriminant. =A0If there is no specific routine a def= ault >> + * routine may be called. >> + * If there is no specific or default routine an error is returned. >> + */ >> +bool_t >> +xdr_union(XDR *xdrs, enum_t *dscmp, char *unp, >> + =A0 =A0 =A0 const struct xdr_discrim *choices, const xdrproc_t dfault) >> +{ >> + =A0 =A0 =A0 enum_t dscm; >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* we deal with the discriminator; =A0it's an enum >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 if (!xdr_enum(xdrs, dscmp)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 dscm =3D *dscmp; >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* search choices for a value that matches the discrimin= ator. >> + =A0 =A0 =A0 =A0* if we find one, execute the xdr routine for that valu= e. >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 for (; choices->proc !=3D NULL_xdrproc_t; choices++) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (choices->value =3D=3D dscm) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ((*(choices->proc))= (xdrs, unp, >> LASTUNSIGNED)); >> + =A0 =A0 =A0 } >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* no match - execute the default xdr routine if there i= s one >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 return ((dfault =3D=3D NULL_xdrproc_t) ? FALSE : >> + =A0 =A0 =A0 =A0 =A0 (*dfault)(xdrs, unp, LASTUNSIGNED)); >> +} >> + >> + >> +/* >> + * Non-portable xdr primitives. >> + * Care should be taken when moving these routines to new architectures= . >> + */ >> + >> + >> +/* >> + * XDR null terminated ASCII strings >> + * xdr_string deals with "C strings" - arrays of bytes that are >> + * terminated by a NULL character. =A0The parameter cpp references a >> + * pointer to storage; If the pointer is null, then the necessary >> + * storage is allocated. =A0The last parameter is the max allowed lengt= h >> + * of the string as specified by a protocol. >> + */ >> +bool_t >> +xdr_string(XDR *xdrs, char **cpp, const uint_t maxsize) >> +{ >> + =A0 =A0 =A0 char *sp =3D *cpp; =A0/* sp is the actual string pointer *= / >> + =A0 =A0 =A0 uint_t size; >> + =A0 =A0 =A0 uint_t nodesize; >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* first deal with the length since xdr strings are >> counted-strings >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 switch (xdrs->x_op) { >> + =A0 =A0 =A0 case XDR_FREE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (sp =3D=3D NULL) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); =A0/* alrea= dy free */ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* FALLTHROUGH */ >> + =A0 =A0 =A0 case XDR_ENCODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 size =3D (sp !=3D NULL) ? (uint_t)strlen(s= p) : 0; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> + =A0 =A0 =A0 case XDR_DECODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 if (!xdr_u_int(xdrs, &size)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 if (size > maxsize) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 nodesize =3D size + 1; >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* now deal with the actual bytes >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 switch (xdrs->x_op) { >> + =A0 =A0 =A0 case XDR_DECODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (nodesize =3D=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (sp =3D=3D NULL) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sp =3D (char *)mem_alloc(n= odesize); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sp[size] =3D 0; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!xdr_opaque(xdrs, sp, size)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* free up memory if all= ocated here >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (*cpp =3D=3D NULL) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mem_free(s= p, nodesize); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (strlen(sp) !=3D size) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (*cpp =3D=3D NULL) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mem_free(s= p, nodesize); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *cpp =3D sp; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 case XDR_ENCODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (xdr_opaque(xdrs, sp, size)); >> + >> + =A0 =A0 =A0 case XDR_FREE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mem_free(sp, nodesize); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *cpp =3D NULL; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (FALSE); >> +} >> + >> +/* >> + * Wrapper for xdr_string that can be called directly from >> + * routines like clnt_call >> + */ >> +bool_t >> +xdr_wrapstring(XDR *xdrs, char **cpp) >> +{ >> + =A0 =A0 =A0 if (xdr_string(xdrs, cpp, LASTUNSIGNED)) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + =A0 =A0 =A0 return (FALSE); >> +} >> >> Copied: >> head/sys/cddl/contrib/opensolaris/uts/common/rpc/opensolaris_xdr_array.c >> (from r191983, head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr_arra= y.c) >> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >> --- /dev/null =A0 00:00:00 1970 =A0 (empty, because file is newly added) >> +++ >> head/sys/cddl/contrib/opensolaris/uts/common/rpc/opensolaris_xdr_array.c= Mon >> May 11 04:18:58 2009 =A0 =A0 =A0 =A0(r191984, copy of r191983, >> head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr_array.c) >> @@ -0,0 +1,114 @@ >> +/* >> + * CDDL HEADER START >> + * >> + * The contents of this file are subject to the terms of the >> + * Common Development and Distribution License (the "License"). >> + * You may not use this file except in compliance with the License. >> + * >> + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE >> + * or http://www.opensolaris.org/os/licensing. >> + * See the License for the specific language governing permissions >> + * and limitations under the License. >> + * >> + * When distributing Covered Code, include this CDDL HEADER in each >> + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. >> + * If applicable, add the following below this CDDL HEADER, with the >> + * fields enclosed by brackets "[]" replaced with your own identifying >> + * information: Portions Copyright [yyyy] [name of copyright owner] >> + * >> + * CDDL HEADER END >> + */ >> +/* >> + * Copyright 2008 Sun Microsystems, Inc. =A0All rights reserved. >> + * Use is subject to license terms. >> + */ >> + >> +/* =A0 =A0 Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T = =A0 =A0 */ >> +/* =A0 =A0 =A0 All Rights Reserved =A0 */ >> + >> +/* >> + * Portions of this source code were derived from Berkeley 4.3 BSD >> + * under license from the Regents of the University of California. >> + */ >> + >> +/* >> + * xdr_array.c, Generic XDR routines impelmentation. >> + * These are the "non-trivial" xdr primitives used to serialize and >> de-serialize >> + * arrays. =A0See xdr.h for more info on the interface to xdr. >> + */ >> + >> +#include <sys/param.h> >> +#include <sys/cmn_err.h> >> +#include <sys/types.h> >> +#include <sys/systm.h> >> + >> +#include <rpc/types.h> >> +#include <rpc/xdr.h> >> + >> +#define =A0 =A0 =A0 =A0LASTUNSIGNED =A0 =A0((uint_t)0-1) >> + >> +/* >> + * XDR an array of arbitrary elements >> + * *addrp is a pointer to the array, *sizep is the number of elements. >> + * If addrp is NULL (*sizep * elsize) bytes are allocated. >> + * elsize is the size (in bytes) of each element, and elproc is the >> + * xdr procedure to call to handle each element of the array. >> + */ >> +bool_t >> +xdr_array(XDR *xdrs, caddr_t *addrp, uint_t *sizep, const uint_t maxsiz= e, >> + =A0 =A0 =A0 const uint_t elsize, const xdrproc_t elproc) >> +{ >> + =A0 =A0 =A0 uint_t i; >> + =A0 =A0 =A0 caddr_t target =3D *addrp; >> + =A0 =A0 =A0 uint_t c; =A0/* the actual element count */ >> + =A0 =A0 =A0 bool_t stat =3D TRUE; >> + =A0 =A0 =A0 uint_t nodesize; >> + >> + =A0 =A0 =A0 /* like strings, arrays are really counted arrays */ >> + =A0 =A0 =A0 if (!xdr_u_int(xdrs, sizep)) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 c =3D *sizep; >> + =A0 =A0 =A0 if ((c > maxsize || LASTUNSIGNED / elsize < c) && >> + =A0 =A0 =A0 =A0 =A0 xdrs->x_op !=3D XDR_FREE) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 nodesize =3D c * elsize; >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* if we are deserializing, we may need to allocate an a= rray. >> + =A0 =A0 =A0 =A0* We also save time by checking for a null array if we = are >> freeing. >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 if (target =3D=3D NULL) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 switch (xdrs->x_op) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 case XDR_DECODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (c =3D=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TR= UE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *addrp =3D target =3D (cha= r *)mem_alloc(nodesize); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bzero(target, nodesize); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 case XDR_FREE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 case XDR_ENCODE: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* now we xdr each element of array >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 for (i =3D 0; (i < c) && stat; i++) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 stat =3D (*elproc)(xdrs, target, LASTUNSIG= NED); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 target +=3D elsize; >> + =A0 =A0 =A0 } >> + >> + =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0* the array may need freeing >> + =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 if (xdrs->x_op =3D=3D XDR_FREE) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mem_free(*addrp, nodesize); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *addrp =3D NULL; >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (stat); >> +} >> >> Copied: >> head/sys/cddl/contrib/opensolaris/uts/common/rpc/opensolaris_xdr_mem.c (= from >> r191983, head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr_mem.c) >> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >> --- /dev/null =A0 00:00:00 1970 =A0 (empty, because file is newly added) >> +++ head/sys/cddl/contrib/opensolaris/uts/common/rpc/opensolaris_xdr_mem= .c >> =A0 Mon May 11 04:18:58 2009 =A0 =A0 =A0 =A0(r191984, copy of r191983, >> head/sys/cddl/contrib/opensolaris/uts/common/rpc/xdr_mem.c) >> @@ -0,0 +1,209 @@ >> +/* >> + * CDDL HEADER START >> + * >> + * The contents of this file are subject to the terms of the >> + * Common Development and Distribution License, Version 1.0 only >> + * (the "License"). =A0You may not use this file except in compliance >> + * with the License. >> + * >> + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE >> + * or http://www.opensolaris.org/os/licensing. >> + * See the License for the specific language governing permissions >> + * and limitations under the License. >> + * >> + * When distributing Covered Code, include this CDDL HEADER in each >> + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. >> + * If applicable, add the following below this CDDL HEADER, with the >> + * fields enclosed by brackets "[]" replaced with your own identifying >> + * information: Portions Copyright [yyyy] [name of copyright owner] >> + * >> + * CDDL HEADER END >> + */ >> +/* >> + * Copyright 2005 Sun Microsystems, Inc. =A0All rights reserved. >> + * Use is subject to license terms. >> + */ >> + >> +/* =A0 =A0 Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T = =A0 =A0 */ >> +/* =A0 =A0 =A0 All Rights Reserved =A0 */ >> + >> +/* >> + * Portions of this source code were derived from Berkeley 4.3 BSD >> + * under license from the Regents of the University of California. >> + */ >> + >> +#pragma ident =A0"%Z%%M% %I% =A0 =A0 %E% SMI" >> + >> +/* >> + * xdr_mem.c, XDR implementation using memory buffers. >> + * >> + * If you have some data to be interpreted as external data >> representation >> + * or to be converted to external data representation in a memory buffe= r, >> + * then this is the package for you. >> + */ >> + >> +#include <sys/param.h> >> +#include <sys/types.h> >> +#include <sys/systm.h> >> + >> +#include <rpc/types.h> >> +#include <rpc/xdr.h> >> + >> +static struct xdr_ops *xdrmem_ops(void); >> + >> +/* >> + * The procedure xdrmem_create initializes a stream descriptor for a >> + * memory buffer. >> + */ >> +void >> +xdrmem_create(XDR *xdrs, caddr_t addr, uint_t size, enum xdr_op op) >> +{ >> + =A0 =A0 =A0 xdrs->x_op =3D op; >> + =A0 =A0 =A0 xdrs->x_ops =3D xdrmem_ops(); >> + =A0 =A0 =A0 xdrs->x_private =3D xdrs->x_base =3D addr; >> + =A0 =A0 =A0 xdrs->x_handy =3D size; >> + =A0 =A0 =A0 xdrs->x_public =3D NULL; >> +} >> + >> +/* ARGSUSED */ >> +static void >> +xdrmem_destroy(XDR *xdrs) >> +{ >> +} >> + >> +static bool_t >> +xdrmem_getint32(XDR *xdrs, int32_t *int32p) >> +{ >> + =A0 =A0 =A0 if ((xdrs->x_handy -=3D (int)sizeof (int32_t)) < 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 /* LINTED pointer alignment */ >> + =A0 =A0 =A0 *int32p =3D (int32_t)ntohl((uint32_t)(*((int32_t >> *)(xdrs->x_private)))); >> + =A0 =A0 =A0 xdrs->x_private +=3D sizeof (int32_t); >> + =A0 =A0 =A0 return (TRUE); >> +} >> + >> +static bool_t >> +xdrmem_putint32(XDR *xdrs, int32_t *int32p) >> +{ >> + =A0 =A0 =A0 if ((xdrs->x_handy -=3D (int)sizeof (int32_t)) < 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 /* LINTED pointer alignment */ >> + =A0 =A0 =A0 *(int32_t *)xdrs->x_private =3D (int32_t)htonl((uint32_t)(= *int32p)); >> + =A0 =A0 =A0 xdrs->x_private +=3D sizeof (int32_t); >> + =A0 =A0 =A0 return (TRUE); >> +} >> + >> +static bool_t >> +xdrmem_getbytes(XDR *xdrs, caddr_t addr, int len) >> +{ >> + =A0 =A0 =A0 if ((xdrs->x_handy -=3D len) < 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 bcopy(xdrs->x_private, addr, len); >> + =A0 =A0 =A0 xdrs->x_private +=3D len; >> + =A0 =A0 =A0 return (TRUE); >> +} >> + >> +static bool_t >> +xdrmem_putbytes(XDR *xdrs, caddr_t addr, int len) >> +{ >> + =A0 =A0 =A0 if ((xdrs->x_handy -=3D len) < 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 bcopy(addr, xdrs->x_private, len); >> + =A0 =A0 =A0 xdrs->x_private +=3D len; >> + =A0 =A0 =A0 return (TRUE); >> +} >> + >> +static uint_t >> +xdrmem_getpos(XDR *xdrs) >> +{ >> + =A0 =A0 =A0 return ((uint_t)((uintptr_t)xdrs->x_private - >> (uintptr_t)xdrs->x_base)); >> +} >> + >> +static bool_t >> +xdrmem_setpos(XDR *xdrs, uint_t pos) >> +{ >> + =A0 =A0 =A0 caddr_t newaddr =3D xdrs->x_base + pos; >> + =A0 =A0 =A0 caddr_t lastaddr =3D xdrs->x_private + xdrs->x_handy; >> + =A0 =A0 =A0 ptrdiff_t diff; >> + >> + =A0 =A0 =A0 if (newaddr > lastaddr) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 xdrs->x_private =3D newaddr; >> + =A0 =A0 =A0 diff =3D lastaddr - newaddr; >> + =A0 =A0 =A0 xdrs->x_handy =3D (int)diff; >> + =A0 =A0 =A0 return (TRUE); >> +} >> + >> +static rpc_inline_t * >> +xdrmem_inline(XDR *xdrs, int len) >> +{ >> + =A0 =A0 =A0 rpc_inline_t *buf =3D NULL; >> + >> + =A0 =A0 =A0 if (xdrs->x_handy >=3D len) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 xdrs->x_handy -=3D len; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* LINTED pointer alignment */ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf =3D (rpc_inline_t *)xdrs->x_private; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 xdrs->x_private +=3D len; >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (buf); >> +} >> + >> +static bool_t >> +xdrmem_control(XDR *xdrs, int request, void *info) >> +{ >> + =A0 =A0 =A0 xdr_bytesrec *xptr; >> + =A0 =A0 =A0 int32_t *int32p; >> + =A0 =A0 =A0 int len; >> + >> + =A0 =A0 =A0 switch (request) { >> + >> + =A0 =A0 =A0 case XDR_GET_BYTES_AVAIL: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 xptr =3D (xdr_bytesrec *)info; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 xptr->xc_is_last_record =3D TRUE; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 xptr->xc_num_avail =3D xdrs->x_handy; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 case XDR_PEEK: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Return the next 4 byte unit in the XD= R stream. >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (xdrs->x_handy < sizeof (int32_t)) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 int32p =3D (int32_t *)info; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *int32p =3D (int32_t)ntohl((uint32_t) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (*((int32_t *)(xdrs->x_private))))= ; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 case XDR_SKIPBYTES: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Skip the next N bytes in the XDR stre= am. >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 int32p =3D (int32_t *)info; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 len =3D RNDUP((int)(*int32p)); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ((xdrs->x_handy -=3D len) < 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (FALSE); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 xdrs->x_private +=3D len; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (TRUE); >> + >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (FALSE); >> +} >> + >> +static struct xdr_ops * >> +xdrmem_ops(void) >> +{ >> + =A0 =A0 =A0 static struct xdr_ops ops; >> + >> + =A0 =A0 =A0 if (ops.x_getint32 =3D=3D NULL) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ops.x_getbytes =3D xdrmem_getbytes; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ops.x_putbytes =3D xdrmem_putbytes; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ops.x_getpostn =3D xdrmem_getpos; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ops.x_setpostn =3D xdrmem_setpos; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ops.x_inline =3D xdrmem_inline; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ops.x_destroy =3D xdrmem_destroy; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ops.x_control =3D xdrmem_control; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ops.x_getint32 =3D xdrmem_getint32; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ops.x_putint32 =3D xdrmem_putint32; >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 return (&ops); >> +} >> >> Modified: head/sys/modules/zfs/Makefile >> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >> --- head/sys/modules/zfs/Makefile =A0 =A0 =A0 Mon May 11 02:39:49 2009 >> =A0(r191983) >> +++ head/sys/modules/zfs/Makefile =A0 =A0 =A0 Mon May 11 04:18:58 2009 >> =A0(r191984) >> @@ -44,9 +44,9 @@ SRCS+=3D =A0 =A0 =A0 =A0nvpair_alloc_system.c >> SRCS+=3D =A0taskq.c >> >> .PATH: =A0${SUNW}/uts/common/rpc >> -SRCS+=3D xdr.c >> -SRCS+=3D xdr_array.c >> -SRCS+=3D xdr_mem.c >> +SRCS+=3D opensolaris_xdr.c >> +SRCS+=3D opensolaris_xdr_array.c >> +SRCS+=3D opensolaris_xdr_mem.c >> >> .PATH: =A0${SUNW}/uts/common/zmod >> SRCS+=3D =A0adler32.c > > --=20 When bad men combine, the good must associate; else they will fall one by one, an unpitied sacrifice in a contemptible struggle. Edmund Burke
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3c1674c90905111223u74ec12ch9f40772940a42396>