1 /**************************************************************************** 2 * fs/nfs/xdr_subs.h 3 * Definitions for Sun RPC Version 2, from 4 * "RPC: Remote Procedure Call Protocol Specification" RFC1057 5 * 6 * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 * Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved. 8 * Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com> 9 * Gregory Nutt <gnutt@nuttx.org> 10 * 11 * Leveraged from OpenBSD: 12 * 13 * Copyright (c) 1989, 1993 14 * The Regents of the University of California. All rights reserved. 15 * 16 * This code is derived from software contributed to Berkeley by 17 * Rick Macklem at The University of Guelph. 18 * 19 * Redistribution and use in source and binary forms, with or without 20 * modification, are permitted provided that the following conditions 21 * are met: 22 * 23 * 1. Redistributions of source code must retain the above copyright 24 * notice, this list of conditions and the following disclaimer. 25 * 2. Redistributions in binary form must reproduce the above copyright 26 * notice, this list of conditions and the following disclaimer in the 27 * documentation and/or other materials provided with the distribution. 28 * 3. Neither the name of the University nor the names of its contributors 29 * may be used to endorse or promote products derived from this software 30 * without specific prior written permission. 31 * 32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 42 * SUCH DAMAGE. 43 * 44 ****************************************************************************/ 45 46 #ifndef __FS_NFS_XDR_SUBS_H 47 #define __FS_NFS_XDR_SUBS_H 48 49 /**************************************************************************** 50 * Included Files 51 ****************************************************************************/ 52 53 #include "lwip/sockets.h" 54 55 #ifdef __cplusplus 56 #if __cplusplus 57 extern "C" { 58 #endif /* __cplusplus */ 59 #endif /* __cplusplus */ 60 61 /**************************************************************************** 62 * Pre-processor Definitions 63 ****************************************************************************/ 64 65 /* Macros used for conversion to/from xdr representation by nfs... 66 * These use the MACHINE DEPENDENT routines ntohl, htonl 67 * As defined by "XDR: External Data Representation Standard" RFC1014 68 * 69 * To simplify the implementation, we use ntohl/htonl even on big-endian 70 * machines, and count on them being `#define'd away. Some of these 71 * might be slightly more efficient as int64_t copies on a big-endian, 72 * but we cannot count on their alignment anyway. 73 */ 74 75 #define fxdr_unsigned(t, v) ((t)ntohl(v)) 76 #define txdr_unsigned(v) (htonl(v)) 77 78 #define fxdr_nfsv2time(f, t) \ 79 { \ 80 (t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \ 81 if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \ 82 (t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \ 83 else \ 84 (t)->tv_nsec = 0; \ 85 } 86 87 #define txdr_nfsv2time(f, t) \ 88 { \ 89 ((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->tv_sec); \ 90 if ((f)->tv_nsec != -1) \ 91 ((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->tv_nsec / 1000); \ 92 else \ 93 ((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \ 94 } 95 96 #define fxdr_nfsv3time(f, t) \ 97 { \ 98 (t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \ 99 (t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \ 100 } 101 102 #define fxdr_nfsv3time2(f, t) { \ 103 (t)->nfsv3_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \ 104 (t)->nfsv3_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \ 105 } 106 107 #define txdr_nfsv3time(f, t) \ 108 { \ 109 ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \ 110 ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \ 111 } 112 113 #define txdr_nfsv3time2(f, t) \ 114 { \ 115 ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->nfsv3_sec); \ 116 ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->nfsv3_nsec); \ 117 } 118 119 #define fxdr_hyper(f) \ 120 ((((uint64_t)ntohl(((uint32_t *)(f))[0])) << 32) | \ 121 (uint64_t)(ntohl(((uint32_t *)(f))[1]))) 122 123 #define txdr_hyper(f, t) \ 124 { \ 125 ((uint32_t *)(t))[0] = htonl((uint32_t)((f) >> 32)); \ 126 ((uint32_t *)(t))[1] = htonl((uint32_t)((f) & 0xffffffff)); \ 127 } 128 129 /* Macros for dealing with byte data saved in uint32_t aligned memory */ 130 131 #define uint32_aligndown(b) ((b) & ~3) 132 #define uint32_alignup(b) (((b) + 3) & ~3) 133 #define uint32_increment(b) (((b) + 3) >> 2) 134 135 #ifdef __cplusplus 136 #if __cplusplus 137 } 138 #endif /* __cplusplus */ 139 #endif /* __cplusplus */ 140 141 #endif /* __FS_NFS_XDR_SUBS_H */ 142