/*-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) do { \52(t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \53if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \54(t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \55else \56(t)->tv_nsec = 0; \57} while (0)5859#define txdr_nfsv2time(f, t) do { \60((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->tv_sec); \61if ((f)->tv_nsec != -1) \62((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->tv_nsec / 1000); \63else \64((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \65} while (0)6667#define fxdr_nfsv3time(f, t) do { \68(t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \69(t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \70} while (0)7172#define txdr_nfsv3time(f, t) do { \73((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \74((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \75} while (0)7677#define fxdr_nfsv4time(f, t) do { \78(t)->tv_sec = ntohl(((struct nfsv4_time *)(f))->nfsv4_sec); \79(t)->tv_nsec = (ntohl(((struct nfsv4_time *)(f))->nfsv4_nsec) % \801000000000); \81} while (0)8283#define txdr_nfsv4time(f, t) do { \84((struct nfsv4_time *)(t))->nfsv4_highsec = 0; \85((struct nfsv4_time *)(t))->nfsv4_sec = htonl((f)->tv_sec); \86((struct nfsv4_time *)(t))->nfsv4_nsec = htonl((f)->tv_nsec); \87} while (0)8889#define fxdr_hyper(f) \90((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) | \91(u_quad_t)(ntohl(((u_int32_t *)(f))[1])))9293static inline void94txdr_hyper(uint64_t f, uint32_t* t)95{96t[0] = htonl((u_int32_t)(f >> 32));97t[1] = htonl((u_int32_t)(f & 0xffffffff));98}99100#endif /* _NFS_XDR_SUBS_H_ */101102103