xref: /original-bsd/sys/nfs/xdr_subs.h (revision 3705696b)
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.1 (Berkeley) 06/10/93
11  */
12 
13 /*
14  * Macros used for conversion to/from xdr representation by nfs...
15  * These use the MACHINE DEPENDENT routines ntohl, htonl
16  * As defined by "XDR: External Data Representation Standard" RFC1014
17  *
18  * To simplify the implementation, we use ntohl/htonl even on big-endian
19  * machines, and count on them being `#define'd away.  Some of these
20  * might be slightly more efficient as quad_t copies on a big-endian,
21  * but we cannot count on their alignment anyway.
22  */
23 
24 #define	fxdr_unsigned(t, v)	((t)ntohl((long)(v)))
25 #define	txdr_unsigned(v)	(htonl((long)(v)))
26 
27 #define	fxdr_nfstime(f, t) { \
28 	(t)->ts_sec = ntohl(((struct nfsv2_time *)(f))->nfs_sec); \
29 	(t)->ts_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfs_usec); \
30 }
31 #define	txdr_nfstime(f, t) { \
32 	((struct nfsv2_time *)(t))->nfs_sec = htonl((f)->ts_sec); \
33 	((struct nfsv2_time *)(t))->nfs_usec = htonl((f)->ts_nsec) / 1000; \
34 }
35 
36 #define	fxdr_nqtime(f, t) { \
37 	(t)->ts_sec = ntohl(((struct nqnfs_time *)(f))->nq_sec); \
38 	(t)->ts_nsec = ntohl(((struct nqnfs_time *)(f))->nq_nsec); \
39 }
40 #define	txdr_nqtime(f, t) { \
41 	((struct nqnfs_time *)(t))->nq_sec = htonl((f)->ts_sec); \
42 	((struct nqnfs_time *)(t))->nq_nsec = htonl((f)->ts_nsec); \
43 }
44 
45 #define	fxdr_hyper(f, t) { \
46 	((long *)(t))[_QUAD_HIGHWORD] = ntohl(((long *)(f))[0]); \
47 	((long *)(t))[_QUAD_LOWWORD] = ntohl(((long *)(f))[1]); \
48 }
49 #define	txdr_hyper(f, t) { \
50 	((long *)(t))[0] = htonl(((long *)(f))[_QUAD_HIGHWORD]); \
51 	((long *)(t))[1] = htonl(((long *)(f))[_QUAD_LOWWORD]); \
52 }
53