Home | History | Annotate | Line # | Download | only in nfs
xdr_subs.h revision 1.14
      1  1.14      agc /*	$NetBSD: xdr_subs.h,v 1.14 2003/08/07 16:33:58 agc Exp $	*/
      2   1.7      cgd 
      3   1.1      cgd /*
      4   1.6  mycroft  * Copyright (c) 1989, 1993
      5   1.6  mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1      cgd  *
      7   1.1      cgd  * This code is derived from software contributed to Berkeley by
      8   1.1      cgd  * Rick Macklem at The University of Guelph.
      9   1.1      cgd  *
     10   1.1      cgd  * Redistribution and use in source and binary forms, with or without
     11   1.1      cgd  * modification, are permitted provided that the following conditions
     12   1.1      cgd  * are met:
     13   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     14   1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     15   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     18  1.14      agc  * 3. Neither the name of the University nor the names of its contributors
     19   1.1      cgd  *    may be used to endorse or promote products derived from this software
     20   1.1      cgd  *    without specific prior written permission.
     21   1.1      cgd  *
     22   1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23   1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26   1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.1      cgd  * SUCH DAMAGE.
     33   1.1      cgd  *
     34  1.11     fvdl  *	@(#)xdr_subs.h	8.3 (Berkeley) 3/30/95
     35   1.1      cgd  */
     36   1.1      cgd 
     37  1.11     fvdl 
     38  1.11     fvdl #ifndef _NFS_XDR_SUBS_H_
     39  1.11     fvdl #define _NFS_XDR_SUBS_H_
     40  1.11     fvdl 
     41   1.1      cgd /*
     42   1.1      cgd  * Macros used for conversion to/from xdr representation by nfs...
     43   1.1      cgd  * These use the MACHINE DEPENDENT routines ntohl, htonl
     44   1.1      cgd  * As defined by "XDR: External Data Representation Standard" RFC1014
     45   1.6  mycroft  *
     46   1.6  mycroft  * To simplify the implementation, we use ntohl/htonl even on big-endian
     47   1.6  mycroft  * machines, and count on them being `#define'd away.  Some of these
     48   1.6  mycroft  * might be slightly more efficient as quad_t copies on a big-endian,
     49   1.6  mycroft  * but we cannot count on their alignment anyway.
     50   1.1      cgd  */
     51   1.1      cgd 
     52   1.9      cgd #define	fxdr_unsigned(t, v)	((t)ntohl((int32_t)(v)))
     53   1.9      cgd #define	txdr_unsigned(v)	(htonl((int32_t)(v)))
     54  1.12     fvdl 
     55  1.12     fvdl /*
     56  1.12     fvdl  * Directory cookies shouldn't really be XDR-ed, these functions
     57  1.12     fvdl  * are just here to attempt to keep information within 32 bits. And
     58  1.12     fvdl  * make things look better. See nfs_cookieheuristic.
     59  1.12     fvdl  */
     60  1.12     fvdl #define fxdr_cookie3(v) (((off_t)((v)[0]) << 32) | ((off_t) (v)[1]))
     61  1.12     fvdl #define fxdr_swapcookie3(v) (((off_t)((v)[1]) << 32) | ((off_t) (v)[0]))
     62  1.12     fvdl 
     63  1.12     fvdl #define txdr_cookie3(f, v) { \
     64  1.12     fvdl 	(v)[1] = (u_int32_t)((f) & 0xffffffffLL); \
     65  1.12     fvdl 	(v)[0] = (u_int32_t)((f) >> 32); \
     66  1.12     fvdl }
     67  1.12     fvdl #define txdr_swapcookie3(f, v) { \
     68  1.12     fvdl 	(v)[0] = (u_int32_t)((f) & 0xffffffffLL); \
     69  1.12     fvdl 	(v)[1] = (u_int32_t)((f) >> 32); \
     70  1.12     fvdl }
     71   1.1      cgd 
     72  1.11     fvdl #define	fxdr_nfsv2time(f, t) { \
     73  1.11     fvdl 	(t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \
     74  1.11     fvdl 	if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \
     75  1.11     fvdl 		(t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \
     76   1.8  mycroft 	else \
     77  1.10      jtc 		(t)->tv_nsec = 0; \
     78   1.6  mycroft }
     79  1.11     fvdl #define	txdr_nfsv2time(f, t) { \
     80  1.11     fvdl 	((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->tv_sec); \
     81  1.11     fvdl 	if ((f)->tv_nsec != -1) \
     82  1.11     fvdl 		((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->tv_nsec / 1000); \
     83  1.11     fvdl 	else \
     84  1.11     fvdl 		((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \
     85   1.6  mycroft }
     86   1.6  mycroft 
     87  1.11     fvdl #define	fxdr_nfsv3time(f, t) { \
     88  1.11     fvdl 	(t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \
     89  1.11     fvdl 	(t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \
     90  1.11     fvdl }
     91  1.11     fvdl #define	txdr_nfsv3time(f, t) { \
     92  1.11     fvdl 	((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \
     93  1.11     fvdl 	((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \
     94   1.6  mycroft }
     95   1.6  mycroft 
     96  1.13     fair #define	fxdr_hyper(f) 						\
     97  1.13     fair         ((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) |	\
     98  1.13     fair 	 (u_quad_t)(ntohl(((u_int32_t *)(f))[1])))
     99  1.13     fair 
    100  1.13     fair 
    101  1.13     fair #define	txdr_hyper(f, t) {						\
    102  1.13     fair 	((u_int32_t *)(t))[0] = htonl((u_int32_t)((f) >> 32));		\
    103  1.13     fair 	((u_int32_t *)(t))[1] = htonl((u_int32_t)((f) & 0xffffffff));	\
    104   1.6  mycroft }
    105  1.11     fvdl 
    106  1.11     fvdl #endif
    107