1191783Srmacklem/*- 2191783Srmacklem * Copyright (c) 1989, 1993 3191783Srmacklem * The Regents of the University of California. All rights reserved. 4191783Srmacklem * 5191783Srmacklem * This code is derived from software contributed to Berkeley by 6191783Srmacklem * Rick Macklem at The University of Guelph. 7191783Srmacklem * 8191783Srmacklem * Redistribution and use in source and binary forms, with or without 9191783Srmacklem * modification, are permitted provided that the following conditions 10191783Srmacklem * are met: 11191783Srmacklem * 1. Redistributions of source code must retain the above copyright 12191783Srmacklem * notice, this list of conditions and the following disclaimer. 13191783Srmacklem * 2. Redistributions in binary form must reproduce the above copyright 14191783Srmacklem * notice, this list of conditions and the following disclaimer in the 15191783Srmacklem * documentation and/or other materials provided with the distribution. 16191783Srmacklem * 4. Neither the name of the University nor the names of its contributors 17191783Srmacklem * may be used to endorse or promote products derived from this software 18191783Srmacklem * without specific prior written permission. 19191783Srmacklem * 20191783Srmacklem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21191783Srmacklem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22191783Srmacklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23191783Srmacklem * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24191783Srmacklem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25191783Srmacklem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26191783Srmacklem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27191783Srmacklem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28191783Srmacklem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29191783Srmacklem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30191783Srmacklem * SUCH DAMAGE. 31191783Srmacklem * 32191783Srmacklem * $FreeBSD: releng/11.0/sys/fs/nfs/xdr_subs.h 191783 2009-05-04 15:23:58Z rmacklem $ 33191783Srmacklem */ 34191783Srmacklem 35191783Srmacklem#ifndef _NFS_XDR_SUBS_H_ 36191783Srmacklem#define _NFS_XDR_SUBS_H_ 37191783Srmacklem 38191783Srmacklem/* 39191783Srmacklem * Macros used for conversion to/from xdr representation by nfs... 40191783Srmacklem * These use the MACHINE DEPENDENT routines ntohl, htonl 41191783Srmacklem * As defined by "XDR: External Data Representation Standard" RFC1014 42191783Srmacklem * 43191783Srmacklem * To simplify the implementation, we use ntohl/htonl even on big-endian 44191783Srmacklem * machines, and count on them being `#define'd away. Some of these 45191783Srmacklem * might be slightly more efficient as quad_t copies on a big-endian, 46191783Srmacklem * but we cannot count on their alignment anyway. 47191783Srmacklem */ 48191783Srmacklem 49191783Srmacklem#define fxdr_unsigned(t, v) ((t)ntohl((int32_t)(v))) 50191783Srmacklem#define txdr_unsigned(v) (htonl((int32_t)(v))) 51191783Srmacklem 52191783Srmacklem#define fxdr_nfsv2time(f, t) do { \ 53191783Srmacklem (t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \ 54191783Srmacklem if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \ 55191783Srmacklem (t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \ 56191783Srmacklem else \ 57191783Srmacklem (t)->tv_nsec = 0; \ 58191783Srmacklem } while (0) 59191783Srmacklem 60191783Srmacklem#define txdr_nfsv2time(f, t) do { \ 61191783Srmacklem ((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->tv_sec); \ 62191783Srmacklem if ((f)->tv_nsec != -1) \ 63191783Srmacklem ((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->tv_nsec / 1000); \ 64191783Srmacklem else \ 65191783Srmacklem ((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \ 66191783Srmacklem } while (0) 67191783Srmacklem 68191783Srmacklem#define fxdr_nfsv3time(f, t) do { \ 69191783Srmacklem (t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \ 70191783Srmacklem (t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \ 71191783Srmacklem } while (0) 72191783Srmacklem 73191783Srmacklem#define txdr_nfsv3time(f, t) do { \ 74191783Srmacklem ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \ 75191783Srmacklem ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \ 76191783Srmacklem } while (0) 77191783Srmacklem 78191783Srmacklem#define fxdr_nfsv4time(f, t) do { \ 79191783Srmacklem (t)->tv_sec = ntohl(((struct nfsv4_time *)(f))->nfsv4_sec); \ 80191783Srmacklem (t)->tv_nsec = (ntohl(((struct nfsv4_time *)(f))->nfsv4_nsec) % \ 81191783Srmacklem 1000000000); \ 82191783Srmacklem } while (0) 83191783Srmacklem 84191783Srmacklem#define txdr_nfsv4time(f, t) do { \ 85191783Srmacklem ((struct nfsv4_time *)(t))->nfsv4_highsec = 0; \ 86191783Srmacklem ((struct nfsv4_time *)(t))->nfsv4_sec = htonl((f)->tv_sec); \ 87191783Srmacklem ((struct nfsv4_time *)(t))->nfsv4_nsec = htonl((f)->tv_nsec); \ 88191783Srmacklem } while (0) 89191783Srmacklem 90191783Srmacklem#define fxdr_hyper(f) \ 91191783Srmacklem ((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) | \ 92191783Srmacklem (u_quad_t)(ntohl(((u_int32_t *)(f))[1]))) 93191783Srmacklem 94191783Srmacklem#define txdr_hyper(f, t) do { \ 95191783Srmacklem ((u_int32_t *)(t))[0] = htonl((u_int32_t)((f) >> 32)); \ 96191783Srmacklem ((u_int32_t *)(t))[1] = htonl((u_int32_t)((f) & 0xffffffff)); \ 97191783Srmacklem } while (0) 98191783Srmacklem 99191783Srmacklem#endif /* _NFS_XDR_SUBS_H_ */ 100