Home | History | Annotate | Line # | Download | only in nfs
      1  1.16  riastrad /*	$NetBSD: xdr_subs.h,v 1.16 2024/12/07 02:05:55 riastradh 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 #ifndef _NFS_XDR_SUBS_H_
     38  1.11      fvdl #define _NFS_XDR_SUBS_H_
     39  1.11      fvdl 
     40   1.1       cgd /*
     41   1.1       cgd  * Macros used for conversion to/from xdr representation by nfs...
     42   1.1       cgd  * These use the MACHINE DEPENDENT routines ntohl, htonl
     43   1.1       cgd  * As defined by "XDR: External Data Representation Standard" RFC1014
     44   1.6   mycroft  *
     45   1.6   mycroft  * To simplify the implementation, we use ntohl/htonl even on big-endian
     46   1.6   mycroft  * machines, and count on them being `#define'd away.  Some of these
     47   1.6   mycroft  * might be slightly more efficient as quad_t copies on a big-endian,
     48   1.6   mycroft  * but we cannot count on their alignment anyway.
     49   1.1       cgd  */
     50   1.1       cgd 
     51   1.9       cgd #define	fxdr_unsigned(t, v)	((t)ntohl((int32_t)(v)))
     52   1.9       cgd #define	txdr_unsigned(v)	(htonl((int32_t)(v)))
     53  1.12      fvdl 
     54  1.12      fvdl /*
     55  1.12      fvdl  * Directory cookies shouldn't really be XDR-ed, these functions
     56  1.12      fvdl  * are just here to attempt to keep information within 32 bits. And
     57  1.12      fvdl  * make things look better. See nfs_cookieheuristic.
     58  1.12      fvdl  */
     59  1.12      fvdl #define fxdr_cookie3(v) (((off_t)((v)[0]) << 32) | ((off_t) (v)[1]))
     60  1.12      fvdl #define fxdr_swapcookie3(v) (((off_t)((v)[1]) << 32) | ((off_t) (v)[0]))
     61  1.12      fvdl 
     62  1.12      fvdl #define txdr_cookie3(f, v) { \
     63  1.12      fvdl 	(v)[1] = (u_int32_t)((f) & 0xffffffffLL); \
     64  1.12      fvdl 	(v)[0] = (u_int32_t)((f) >> 32); \
     65  1.12      fvdl }
     66  1.12      fvdl #define txdr_swapcookie3(f, v) { \
     67  1.12      fvdl 	(v)[0] = (u_int32_t)((f) & 0xffffffffLL); \
     68  1.12      fvdl 	(v)[1] = (u_int32_t)((f) >> 32); \
     69  1.12      fvdl }
     70   1.1       cgd 
     71  1.11      fvdl #define	fxdr_nfsv2time(f, t) { \
     72  1.11      fvdl 	(t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \
     73  1.11      fvdl 	if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \
     74  1.16  riastrad 		(t)->tv_nsec = 1000 * \
     75  1.16  riastrad 		    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.16  riastrad 		((struct nfsv2_time *)(t))->nfsv2_usec = \
     83  1.16  riastrad 		    htonl((f)->tv_nsec / 1000); \
     84  1.11      fvdl 	else \
     85  1.11      fvdl 		((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \
     86   1.6   mycroft }
     87   1.6   mycroft 
     88  1.11      fvdl #define	fxdr_nfsv3time(f, t) { \
     89  1.11      fvdl 	(t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \
     90  1.11      fvdl 	(t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \
     91  1.11      fvdl }
     92  1.11      fvdl #define	txdr_nfsv3time(f, t) { \
     93  1.11      fvdl 	((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \
     94  1.11      fvdl 	((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \
     95   1.6   mycroft }
     96   1.6   mycroft 
     97  1.13      fair #define	fxdr_hyper(f) 						\
     98  1.13      fair         ((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) |	\
     99  1.13      fair 	 (u_quad_t)(ntohl(((u_int32_t *)(f))[1])))
    100  1.13      fair 
    101  1.13      fair 
    102  1.13      fair #define	txdr_hyper(f, t) {						\
    103  1.13      fair 	((u_int32_t *)(t))[0] = htonl((u_int32_t)((f) >> 32));		\
    104  1.13      fair 	((u_int32_t *)(t))[1] = htonl((u_int32_t)((f) & 0xffffffff));	\
    105   1.6   mycroft }
    106  1.11      fvdl 
    107  1.16  riastrad #endif	/* _NFS_XDR_SUBS_H_ */
    108