• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /* Macros used for conversion to/from xdr representation by nfs...
65  * These use the MACHINE DEPENDENT routines ntohl, htonl
66  * As defined by "XDR: External Data Representation Standard" RFC1014
67  *
68  * To simplify the implementation, we use ntohl/htonl even on big-endian
69  * machines, and count on them being `#define'd away.  Some of these
70  * might be slightly more efficient as int64_t copies on a big-endian,
71  * but we cannot count on their alignment anyway.
72  */
73 
74 #define fxdr_unsigned(t, v)  ((t)ntohl(v))
75 #define txdr_unsigned(v)     (htonl(v))
76 
77 #define fxdr_nfsv2time(f, t) \
78 { \
79   (t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \
80   if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \
81     (t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \
82   else \
83     (t)->tv_nsec = 0; \
84 }
85 
86 #define txdr_nfsv2time(f, t) \
87 { \
88   ((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->tv_sec); \
89   if ((f)->tv_nsec != -1) \
90     ((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->tv_nsec / 1000); \
91   else \
92     ((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \
93 }
94 
95 #define fxdr_nfsv3time(f, t) \
96 { \
97   (t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \
98   (t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \
99 }
100 
101 #define fxdr_nfsv3time2(f, t) { \
102   (t)->nfsv3_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \
103   (t)->nfsv3_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \
104 }
105 
106 #define txdr_nfsv3time(f, t) \
107 { \
108   ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \
109   ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \
110 }
111 
112 #define txdr_nfsv3time2(f, t) \
113 { \
114   ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->nfsv3_sec); \
115   ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->nfsv3_nsec); \
116 }
117 
118 #define fxdr_hyper(f) \
119   ((((uint64_t)ntohl(((uint32_t *)(f))[0])) << 32) |  \
120    (uint64_t)(ntohl(((uint32_t *)(f))[1])))
121 
122 #define txdr_hyper(f, t) \
123 { \
124   ((uint32_t *)(t))[0] = htonl((uint32_t)((f) >> 32));    \
125   ((uint32_t *)(t))[1] = htonl((uint32_t)((f) & 0xffffffff));  \
126 }
127 
128 /* Macros for dealing with byte data saved in uint32_t aligned memory */
129 
130 #define uint32_aligndown(b) ((b) & ~3)
131 #define uint32_alignup(b)   (((b) + 3) & ~3)
132 #define uint32_increment(b) (((b) + 3) >> 2)
133 
134 #ifdef __cplusplus
135 #if __cplusplus
136 }
137 #endif /* __cplusplus */
138 #endif /* __cplusplus */
139 
140 #endif /* __FS_NFS_XDR_SUBS_H */
141