xdr_subs.h revision 139823
1139823Simp/*- 21541Srgrimes * Copyright (c) 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * This code is derived from software contributed to Berkeley by 61541Srgrimes * Rick Macklem at The University of Guelph. 71541Srgrimes * 81541Srgrimes * Redistribution and use in source and binary forms, with or without 91541Srgrimes * modification, are permitted provided that the following conditions 101541Srgrimes * are met: 111541Srgrimes * 1. Redistributions of source code must retain the above copyright 121541Srgrimes * notice, this list of conditions and the following disclaimer. 131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer in the 151541Srgrimes * documentation and/or other materials provided with the distribution. 161541Srgrimes * 4. Neither the name of the University nor the names of its contributors 171541Srgrimes * may be used to endorse or promote products derived from this software 181541Srgrimes * without specific prior written permission. 191541Srgrimes * 201541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301541Srgrimes * SUCH DAMAGE. 311541Srgrimes * 3222521Sdyson * @(#)xdr_subs.h 8.3 (Berkeley) 3/30/95 3350477Speter * $FreeBSD: head/sys/nfs/xdr_subs.h 139823 2005-01-07 01:45:51Z imp $ 341541Srgrimes */ 351541Srgrimes 3622521Sdyson 372175Spaul#ifndef _NFS_XDR_SUBS_H_ 382175Spaul#define _NFS_XDR_SUBS_H_ 392175Spaul 401541Srgrimes/* 411541Srgrimes * Macros used for conversion to/from xdr representation by nfs... 421541Srgrimes * These use the MACHINE DEPENDENT routines ntohl, htonl 431541Srgrimes * As defined by "XDR: External Data Representation Standard" RFC1014 441541Srgrimes * 451541Srgrimes * To simplify the implementation, we use ntohl/htonl even on big-endian 461541Srgrimes * machines, and count on them being `#define'd away. Some of these 471541Srgrimes * might be slightly more efficient as quad_t copies on a big-endian, 481541Srgrimes * but we cannot count on their alignment anyway. 491541Srgrimes */ 501541Srgrimes 5136541Speter#define fxdr_unsigned(t, v) ((t)ntohl((int32_t)(v))) 5236541Speter#define txdr_unsigned(v) (htonl((int32_t)(v))) 531541Srgrimes 5450053Speter#define fxdr_nfsv2time(f, t) \ 5550053Speterdo { \ 5618397Snate (t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \ 579336Sdfr if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \ 5818397Snate (t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \ 595472Sdg else \ 6018397Snate (t)->tv_nsec = 0; \ 6150053Speter} while (0) 6250053Speter#define txdr_nfsv2time(f, t) \ 6350053Speterdo { \ 6418397Snate ((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->tv_sec); \ 6518397Snate if ((f)->tv_nsec != -1) \ 6618397Snate ((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->tv_nsec / 1000); \ 675472Sdg else \ 689336Sdfr ((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \ 6950053Speter} while (0) 701541Srgrimes 7150053Speter#define fxdr_nfsv3time(f, t) \ 7250053Speterdo { \ 7318397Snate (t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \ 7418397Snate (t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \ 7550053Speter} while (0) 7650053Speter#define txdr_nfsv3time(f, t) \ 7750053Speterdo { \ 7818397Snate ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \ 7918397Snate ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \ 8050053Speter} while (0) 811541Srgrimes 8247751Speter#define fxdr_hyper(f) \ 8347751Speter ((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) | \ 8447751Speter (u_quad_t)(ntohl(((u_int32_t *)(f))[1]))) 8550053Speter#define txdr_hyper(f, t) \ 8650053Speterdo { \ 8747751Speter ((u_int32_t *)(t))[0] = htonl((u_int32_t)((f) >> 32)); \ 8847751Speter ((u_int32_t *)(t))[1] = htonl((u_int32_t)((f) & 0xffffffff)); \ 8950053Speter} while (0) 902175Spaul 912175Spaul#endif 92