Commit | Line | Data |
---|---|---|
a2907882 KM |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Rick Macklem at The University of Guelph. | |
7 | * | |
dbf0c423 | 8 | * %sccs.include.redist.c% |
a2907882 | 9 | * |
3c5bfa22 | 10 | * @(#)xdr_subs.h 7.6 (Berkeley) %G% |
a2907882 KM |
11 | */ |
12 | ||
13 | /* | |
14 | * Macros used for conversion to/from xdr representation by nfs... | |
15 | * These use the MACHINE DEPENDENT routines ntohl, htonl | |
66435314 | 16 | * As defined by "XDR: External Data Representation Standard" RFC1014 |
a2907882 | 17 | */ |
2c5b44a2 | 18 | #if BYTE_ORDER == LITTLE_ENDIAN |
a2907882 | 19 | #define fxdr_unsigned(t, v) ((t)ntohl((long)(v))) |
41f343df KM |
20 | #define fxdr_nfstime(f, t) { \ |
21 | (t)->ts_sec = \ | |
22 | ntohl(((struct nfsv2_time *)(f))->nfs_sec); \ | |
23 | (t)->ts_nsec = 1000 * \ | |
24 | ntohl(((struct nfsv2_time *)(f))->nfs_usec); \ | |
25 | } | |
26 | ||
27 | #define fxdr_nqtime(f, t) { \ | |
28 | (t)->ts_sec = \ | |
29 | ntohl(((struct nqnfs_time *)(f))->nq_sec); \ | |
30 | (t)->ts_nsec = \ | |
31 | ntohl(((struct nqnfs_time *)(f))->nq_nsec); \ | |
2c5b44a2 KM |
32 | } |
33 | ||
34 | /* | |
35 | * To handle quad conversions, define a struct of two longs and use | |
36 | * ntohl and htonl. Maybe someday there should be ntohq and htonq? | |
37 | */ | |
38 | union _hq { | |
39 | quad_t hq; | |
40 | struct { | |
41 | long val[2]; | |
42 | } lq; | |
43 | }; | |
44 | #define fxdr_hyper(f, t) { \ | |
45 | ((union _hq *)(t))->lq.val[1] = ntohl(((union _hq *)(f))->lq.val[0]); \ | |
46 | ((union _hq *)(t))->lq.val[0] = ntohl(((union _hq *)(f))->lq.val[1]); \ | |
47 | } | |
48 | #define txdr_hyper(f, t) { \ | |
49 | ((union _hq *)(t))->lq.val[0] = htonl(((union _hq *)(f))->lq.val[1]); \ | |
50 | ((union _hq *)(t))->lq.val[1] = htonl(((union _hq *)(f))->lq.val[0]); \ | |
51 | } | |
a2907882 | 52 | |
a2907882 | 53 | #define txdr_unsigned(v) (htonl((long)(v))) |
41f343df KM |
54 | #define txdr_nqtime(f, t) { \ |
55 | ((struct nqnfs_time *)(t))->nq_sec = \ | |
56 | htonl((f)->ts_sec); \ | |
57 | ((struct nqnfs_time *)(t))->nq_nsec = \ | |
58 | htonl((f)->ts_nsec); \ | |
59 | } | |
60 | #define txdr_nfstime(f, t) { \ | |
61 | ((struct nfsv2_time *)(t))->nfs_sec = \ | |
62 | htonl((f)->ts_sec); \ | |
63 | ((struct nfsv2_time *)(t))->nfs_usec = \ | |
64 | htonl((f)->ts_nsec) / 1000; \ | |
2c5b44a2 KM |
65 | } |
66 | #else /* BIG_ENDIAN */ | |
67 | #define fxdr_unsigned(t, v) ((t)(v)) | |
41f343df KM |
68 | #define fxdr_nqtime(f, t) \ |
69 | *(t) = *((struct timespec *)(f)) | |
70 | #define fxdr_nfstime(f, t) { \ | |
71 | (t)->ts_sec = ((struct nfsv2_time *)(f))->nfs_sec; \ | |
72 | (t)->ts_nsec = ((struct nfsv2_time *)(f))->nfs_usec * 1000; \ | |
73 | } | |
2c5b44a2 KM |
74 | #define fxdr_hyper(f, t) \ |
75 | *((quad_t *)(t)) = *((quad_t *)(f)) | |
a2907882 | 76 | |
2c5b44a2 | 77 | #define txdr_unsigned(v) ((long)(v)) |
41f343df | 78 | #define txdr_nqtime(f, t) \ |
3c5bfa22 | 79 | *(t) = *((struct nqnfs_time *)(f)) |
41f343df KM |
80 | #define txdr_nfstime(f, t) { \ |
81 | ((struct nfsv2_time *)(t))->nfs_sec = (f)->ts_sec; \ | |
82 | ((struct nfsv2_time *)(t))->nfs_usec = (f)->ts_nsec / 1000; \ | |
83 | } | |
2c5b44a2 KM |
84 | #define txdr_hyper(f, t) \ |
85 | *((quad_t *)(t)) = *((quad_t *)(f)) | |
86 | #endif /* ENDIAN */ |