/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1989, 19934* The Regents of the University of California. All rights reserved.5*6* This code is derived from software contributed to Berkeley by7* Rick Macklem at The University of Guelph.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12* 1. Redistributions of source code must retain the above copyright13* notice, this list of conditions and the following disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17* 3. Neither the name of the University nor the names of its contributors18* may be used to endorse or promote products derived from this software19* without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*/3334#ifndef _NFS_XDR_SUBS_H_35#define _NFS_XDR_SUBS_H_3637/*38* Macros used for conversion to/from xdr representation by nfs...39* These use the MACHINE DEPENDENT routines ntohl, htonl40* As defined by "XDR: External Data Representation Standard" RFC101441*42* To simplify the implementation, we use ntohl/htonl even on big-endian43* machines, and count on them being `#define'd away. Some of these44* might be slightly more efficient as quad_t copies on a big-endian,45* but we cannot count on their alignment anyway.46*/4748#define fxdr_unsigned(t, v) ((t)ntohl((int32_t)(v)))49#define txdr_unsigned(v) (htonl((int32_t)(v)))5051#define fxdr_nfsv2time(f, t) \52do { \53(t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \54if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \55(t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \56else \57(t)->tv_nsec = 0; \58} while (0)59#define txdr_nfsv2time(f, t) \60do { \61((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->tv_sec); \62if ((f)->tv_nsec != -1) \63((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->tv_nsec / 1000); \64else \65((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \66} while (0)6768#define fxdr_nfsv3time(f, t) \69do { \70(t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \71(t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \72} while (0)73#define txdr_nfsv3time(f, t) \74do { \75((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \76((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \77} while (0)7879#define fxdr_hyper(f) \80((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) | \81(u_quad_t)(ntohl(((u_int32_t *)(f))[1])))8283static inline void84txdr_hyper(uint64_t f, uint32_t* t)85{86t[0] = htonl((u_int32_t)(f >> 32));87t[1] = htonl((u_int32_t)(f & 0xffffffff));88}8990#endif919293