138414Smckusick /* 263236Sbostic * Copyright (c) 1989, 1993 363236Sbostic * The Regents of the University of California. All rights reserved. 438414Smckusick * 538414Smckusick * This code is derived from software contributed to Berkeley by 638414Smckusick * Rick Macklem at The University of Guelph. 738414Smckusick * 844515Sbostic * %sccs.include.redist.c% 938414Smckusick * 10*68653Smckusick * @(#)xdr_subs.h 8.3 (Berkeley) 03/30/95 1138414Smckusick */ 1238414Smckusick 13*68653Smckusick 14*68653Smckusick #ifndef _NFS_XDR_SUBS_H_ 15*68653Smckusick #define _NFS_XDR_SUBS_H_ 16*68653Smckusick 1738414Smckusick /* 1838414Smckusick * Macros used for conversion to/from xdr representation by nfs... 1938414Smckusick * These use the MACHINE DEPENDENT routines ntohl, htonl 2039748Smckusick * As defined by "XDR: External Data Representation Standard" RFC1014 2160106Smckusick * 2260106Smckusick * To simplify the implementation, we use ntohl/htonl even on big-endian 2360106Smckusick * machines, and count on them being `#define'd away. Some of these 2460106Smckusick * might be slightly more efficient as quad_t copies on a big-endian, 2560106Smckusick * but we cannot count on their alignment anyway. 2638414Smckusick */ 2760106Smckusick 2860106Smckusick #define fxdr_unsigned(t, v) ((t)ntohl((long)(v))) 2960106Smckusick #define txdr_unsigned(v) (htonl((long)(v))) 3060106Smckusick 31*68653Smckusick #define fxdr_nfsv2time(f, t) { \ 32*68653Smckusick (t)->ts_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \ 33*68653Smckusick if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \ 34*68653Smckusick (t)->ts_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \ 35*68653Smckusick else \ 36*68653Smckusick (t)->ts_nsec = 0; \ 3752196Smckusick } 38*68653Smckusick #define txdr_nfsv2time(f, t) { \ 39*68653Smckusick ((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->ts_sec); \ 40*68653Smckusick if ((f)->ts_nsec != -1) \ 41*68653Smckusick ((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->ts_nsec / 1000); \ 42*68653Smckusick else \ 43*68653Smckusick ((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \ 4460106Smckusick } 4538414Smckusick 46*68653Smckusick #define fxdr_nfsv3time(f, t) { \ 47*68653Smckusick (t)->ts_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \ 48*68653Smckusick (t)->ts_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \ 4956281Smckusick } 50*68653Smckusick #define txdr_nfsv3time(f, t) { \ 51*68653Smckusick ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->ts_sec); \ 52*68653Smckusick ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->ts_nsec); \ 5360106Smckusick } 5456281Smckusick 5552196Smckusick #define fxdr_hyper(f, t) { \ 5660106Smckusick ((long *)(t))[_QUAD_HIGHWORD] = ntohl(((long *)(f))[0]); \ 5760106Smckusick ((long *)(t))[_QUAD_LOWWORD] = ntohl(((long *)(f))[1]); \ 5852196Smckusick } 5952196Smckusick #define txdr_hyper(f, t) { \ 6060106Smckusick ((long *)(t))[0] = htonl(((long *)(f))[_QUAD_HIGHWORD]); \ 6160106Smckusick ((long *)(t))[1] = htonl(((long *)(f))[_QUAD_LOWWORD]); \ 6252196Smckusick } 63*68653Smckusick 64*68653Smckusick #endif 65