xdr_subs.h revision 50477
11541Srgrimes/* 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 * 3. All advertising materials mentioning features or use of this software 171541Srgrimes * must display the following acknowledgement: 181541Srgrimes * This product includes software developed by the University of 191541Srgrimes * California, Berkeley and its contributors. 201541Srgrimes * 4. Neither the name of the University nor the names of its contributors 211541Srgrimes * may be used to endorse or promote products derived from this software 221541Srgrimes * without specific prior written permission. 231541Srgrimes * 241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341541Srgrimes * SUCH DAMAGE. 351541Srgrimes * 3622521Sdyson * @(#)xdr_subs.h 8.3 (Berkeley) 3/30/95 3750477Speter * $FreeBSD: head/sys/nfs/xdr_subs.h 50477 1999-08-28 01:08:13Z peter $ 381541Srgrimes */ 391541Srgrimes 4022521Sdyson 412175Spaul#ifndef _NFS_XDR_SUBS_H_ 422175Spaul#define _NFS_XDR_SUBS_H_ 432175Spaul 441541Srgrimes/* 451541Srgrimes * Macros used for conversion to/from xdr representation by nfs... 461541Srgrimes * These use the MACHINE DEPENDENT routines ntohl, htonl 471541Srgrimes * As defined by "XDR: External Data Representation Standard" RFC1014 481541Srgrimes * 491541Srgrimes * To simplify the implementation, we use ntohl/htonl even on big-endian 501541Srgrimes * machines, and count on them being `#define'd away. Some of these 511541Srgrimes * might be slightly more efficient as quad_t copies on a big-endian, 521541Srgrimes * but we cannot count on their alignment anyway. 531541Srgrimes */ 541541Srgrimes 5536541Speter#define fxdr_unsigned(t, v) ((t)ntohl((int32_t)(v))) 5636541Speter#define txdr_unsigned(v) (htonl((int32_t)(v))) 571541Srgrimes 5850053Speter#define fxdr_nfsv2time(f, t) \ 5950053Speterdo { \ 6018397Snate (t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \ 619336Sdfr if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \ 6218397Snate (t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \ 635472Sdg else \ 6418397Snate (t)->tv_nsec = 0; \ 6550053Speter} while (0) 6650053Speter#define txdr_nfsv2time(f, t) \ 6750053Speterdo { \ 6818397Snate ((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->tv_sec); \ 6918397Snate if ((f)->tv_nsec != -1) \ 7018397Snate ((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->tv_nsec / 1000); \ 715472Sdg else \ 729336Sdfr ((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \ 7350053Speter} while (0) 741541Srgrimes 7550053Speter#define fxdr_nfsv3time(f, t) \ 7650053Speterdo { \ 7718397Snate (t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \ 7818397Snate (t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \ 7950053Speter} while (0) 8050053Speter#define txdr_nfsv3time(f, t) \ 8150053Speterdo { \ 8218397Snate ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \ 8318397Snate ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \ 8450053Speter} while (0) 851541Srgrimes 8647751Speter#define fxdr_hyper(f) \ 8747751Speter ((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) | \ 8847751Speter (u_quad_t)(ntohl(((u_int32_t *)(f))[1]))) 8950053Speter#define txdr_hyper(f, t) \ 9050053Speterdo { \ 9147751Speter ((u_int32_t *)(t))[0] = htonl((u_int32_t)((f) >> 32)); \ 9247751Speter ((u_int32_t *)(t))[1] = htonl((u_int32_t)((f) & 0xffffffff)); \ 9350053Speter} while (0) 942175Spaul 952175Spaul#endif 96