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 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)xdr_subs.h 7.6 (Berkeley) 09/16/92 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 #if BYTE_ORDER == LITTLE_ENDIAN 19 #define fxdr_unsigned(t, v) ((t)ntohl((long)(v))) 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); \ 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 } 52 53 #define txdr_unsigned(v) (htonl((long)(v))) 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; \ 65 } 66 #else /* BIG_ENDIAN */ 67 #define fxdr_unsigned(t, v) ((t)(v)) 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 } 74 #define fxdr_hyper(f, t) \ 75 *((quad_t *)(t)) = *((quad_t *)(f)) 76 77 #define txdr_unsigned(v) ((long)(v)) 78 #define txdr_nqtime(f, t) \ 79 *(t) = *((struct nqnfs_time *)(f)) 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 } 84 #define txdr_hyper(f, t) \ 85 *((quad_t *)(t)) = *((quad_t *)(f)) 86 #endif /* ENDIAN */ 87