xdr_subs.h revision 2175
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1989, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * This code is derived from software contributed to Berkeley by
61541Srgrimes * Rick Macklem at The University of Guelph.
71541Srgrimes *
81541Srgrimes * Redistribution and use in source and binary forms, with or without
91541Srgrimes * modification, are permitted provided that the following conditions
101541Srgrimes * are met:
111541Srgrimes * 1. Redistributions of source code must retain the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer.
131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer in the
151541Srgrimes *    documentation and/or other materials provided with the distribution.
161541Srgrimes * 3. All advertising materials mentioning features or use of this software
171541Srgrimes *    must display the following acknowledgement:
181541Srgrimes *	This product includes software developed by the University of
191541Srgrimes *	California, Berkeley and its contributors.
201541Srgrimes * 4. Neither the name of the University nor the names of its contributors
211541Srgrimes *    may be used to endorse or promote products derived from this software
221541Srgrimes *    without specific prior written permission.
231541Srgrimes *
241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341541Srgrimes * SUCH DAMAGE.
351541Srgrimes *
361541Srgrimes *	@(#)xdr_subs.h	8.1 (Berkeley) 6/10/93
372175Spaul * $Id: xdr_subs.h,v 1.2 1994/08/02 07:52:30 davidg Exp $
381541Srgrimes */
391541Srgrimes
402175Spaul#ifndef _NFS_XDR_SUBS_H_
412175Spaul#define _NFS_XDR_SUBS_H_
422175Spaul
431541Srgrimes/*
441541Srgrimes * Macros used for conversion to/from xdr representation by nfs...
451541Srgrimes * These use the MACHINE DEPENDENT routines ntohl, htonl
461541Srgrimes * As defined by "XDR: External Data Representation Standard" RFC1014
471541Srgrimes *
481541Srgrimes * To simplify the implementation, we use ntohl/htonl even on big-endian
491541Srgrimes * machines, and count on them being `#define'd away.  Some of these
501541Srgrimes * might be slightly more efficient as quad_t copies on a big-endian,
511541Srgrimes * but we cannot count on their alignment anyway.
521541Srgrimes */
531541Srgrimes
541541Srgrimes#define	fxdr_unsigned(t, v)	((t)ntohl((long)(v)))
551541Srgrimes#define	txdr_unsigned(v)	(htonl((long)(v)))
561541Srgrimes
571541Srgrimes#define	fxdr_nfstime(f, t) { \
581541Srgrimes	(t)->ts_sec = ntohl(((struct nfsv2_time *)(f))->nfs_sec); \
591541Srgrimes	(t)->ts_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfs_usec); \
601541Srgrimes}
611541Srgrimes#define	txdr_nfstime(f, t) { \
621541Srgrimes	((struct nfsv2_time *)(t))->nfs_sec = htonl((f)->ts_sec); \
631541Srgrimes	((struct nfsv2_time *)(t))->nfs_usec = htonl((f)->ts_nsec) / 1000; \
641541Srgrimes}
651541Srgrimes
661541Srgrimes#define	fxdr_nqtime(f, t) { \
671541Srgrimes	(t)->ts_sec = ntohl(((struct nqnfs_time *)(f))->nq_sec); \
681541Srgrimes	(t)->ts_nsec = ntohl(((struct nqnfs_time *)(f))->nq_nsec); \
691541Srgrimes}
701541Srgrimes#define	txdr_nqtime(f, t) { \
711541Srgrimes	((struct nqnfs_time *)(t))->nq_sec = htonl((f)->ts_sec); \
721541Srgrimes	((struct nqnfs_time *)(t))->nq_nsec = htonl((f)->ts_nsec); \
731541Srgrimes}
741541Srgrimes
751541Srgrimes#define	fxdr_hyper(f, t) { \
761541Srgrimes	((long *)(t))[_QUAD_HIGHWORD] = ntohl(((long *)(f))[0]); \
771541Srgrimes	((long *)(t))[_QUAD_LOWWORD] = ntohl(((long *)(f))[1]); \
781541Srgrimes}
791541Srgrimes#define	txdr_hyper(f, t) { \
801541Srgrimes	((long *)(t))[0] = htonl(((long *)(f))[_QUAD_HIGHWORD]); \
811541Srgrimes	((long *)(t))[1] = htonl(((long *)(f))[_QUAD_LOWWORD]); \
821541Srgrimes}
832175Spaul
842175Spaul#endif
85