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