xref: /original-bsd/sys/nfs/xdr_subs.h (revision 58b1b499)
1 /*
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Rick Macklem at The University of Guelph.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)xdr_subs.h	8.3 (Berkeley) 03/30/95
11  */
12 
13 
14 #ifndef _NFS_XDR_SUBS_H_
15 #define _NFS_XDR_SUBS_H_
16 
17 /*
18  * Macros used for conversion to/from xdr representation by nfs...
19  * These use the MACHINE DEPENDENT routines ntohl, htonl
20  * As defined by "XDR: External Data Representation Standard" RFC1014
21  *
22  * To simplify the implementation, we use ntohl/htonl even on big-endian
23  * machines, and count on them being `#define'd away.  Some of these
24  * might be slightly more efficient as quad_t copies on a big-endian,
25  * but we cannot count on their alignment anyway.
26  */
27 
28 #define	fxdr_unsigned(t, v)	((t)ntohl((long)(v)))
29 #define	txdr_unsigned(v)	(htonl((long)(v)))
30 
31 #define	fxdr_nfsv2time(f, t) { \
32 	(t)->ts_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \
33 	if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \
34 		(t)->ts_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \
35 	else \
36 		(t)->ts_nsec = 0; \
37 }
38 #define	txdr_nfsv2time(f, t) { \
39 	((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->ts_sec); \
40 	if ((f)->ts_nsec != -1) \
41 		((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->ts_nsec / 1000); \
42 	else \
43 		((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \
44 }
45 
46 #define	fxdr_nfsv3time(f, t) { \
47 	(t)->ts_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \
48 	(t)->ts_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \
49 }
50 #define	txdr_nfsv3time(f, t) { \
51 	((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->ts_sec); \
52 	((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->ts_nsec); \
53 }
54 
55 #define	fxdr_hyper(f, t) { \
56 	((long *)(t))[_QUAD_HIGHWORD] = ntohl(((long *)(f))[0]); \
57 	((long *)(t))[_QUAD_LOWWORD] = ntohl(((long *)(f))[1]); \
58 }
59 #define	txdr_hyper(f, t) { \
60 	((long *)(t))[0] = htonl(((long *)(f))[_QUAD_HIGHWORD]); \
61 	((long *)(t))[1] = htonl(((long *)(f))[_QUAD_LOWWORD]); \
62 }
63 
64 #endif
65