xref: /original-bsd/sys/nfs/xdr_subs.h (revision e031425c)
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.2 (Berkeley) 12/08/94
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 	register u_long _nsec; \
29 	(t)->ts_sec = ntohl(((struct nfsv2_time *)(f))->nfs_sec); \
30 	_nsec = ntohl(((struct nfsv2_time *)(f))->nfs_usec); \
31 	if (_nsec != VNOVAL) \
32 		_nsec *= 1000; \
33 	(t)->ts_nsec = _nsec; \
34 }
35 #define	txdr_nfstime(f, t) { \
36 	register u_long _nsec = (f)->ts_nsec; \
37 	((struct nfsv2_time *)(t))->nfs_sec = htonl((f)->ts_sec); \
38 	if (_nsec != VNOVAL) \
39 		_nsec /= 1000; \
40 	((struct nfsv2_time *)(t))->nfs_usec = htonl(_nsec); \
41 }
42 
43 #define	fxdr_nqtime(f, t) { \
44 	(t)->ts_sec = ntohl(((struct nqnfs_time *)(f))->nq_sec); \
45 	(t)->ts_nsec = ntohl(((struct nqnfs_time *)(f))->nq_nsec); \
46 }
47 #define	txdr_nqtime(f, t) { \
48 	((struct nqnfs_time *)(t))->nq_sec = htonl((f)->ts_sec); \
49 	((struct nqnfs_time *)(t))->nq_nsec = htonl((f)->ts_nsec); \
50 }
51 
52 #define	fxdr_hyper(f, t) { \
53 	((long *)(t))[_QUAD_HIGHWORD] = ntohl(((long *)(f))[0]); \
54 	((long *)(t))[_QUAD_LOWWORD] = ntohl(((long *)(f))[1]); \
55 }
56 #define	txdr_hyper(f, t) { \
57 	((long *)(t))[0] = htonl(((long *)(f))[_QUAD_HIGHWORD]); \
58 	((long *)(t))[1] = htonl(((long *)(f))[_QUAD_LOWWORD]); \
59 }
60