xdr_subs.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifndef __FS_NFS_XDR_SUBS_H
  46. #define __FS_NFS_XDR_SUBS_H
  47. /****************************************************************************
  48. * Included Files
  49. ****************************************************************************/
  50. #include <arpa/inet.h>
  51. /****************************************************************************
  52. * Pre-processor Definitions
  53. ****************************************************************************/
  54. /* Macros used for conversion to/from xdr representation by nfs...
  55. * These use the MACHINE DEPENDENT routines ntohl, htonl
  56. * As defined by "XDR: External Data Representation Standard" RFC1014
  57. *
  58. * To simplify the implementation, we use ntohl/htonl even on big-endian
  59. * machines, and count on them being `#define'd away. Some of these
  60. * might be slightly more efficient as int64_t copies on a big-endian,
  61. * but we cannot count on their alignment anyway.
  62. */
  63. #define fxdr_unsigned(t, v) ((t)ntohl(v))
  64. #define txdr_unsigned(v) (htonl(v))
  65. #define fxdr_nfsv3time(f, t) \
  66. { \
  67. (t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \
  68. (t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \
  69. }
  70. #define txdr_nfsv3time(f, t) \
  71. { \
  72. ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \
  73. ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \
  74. }
  75. #define fxdr_hyper(f) \
  76. ((((uint64_t)ntohl(((uint32_t *)(f))[0])) << 32) | \
  77. (uint64_t)(ntohl(((uint32_t *)(f))[1])))
  78. #define txdr_hyper(f, t) \
  79. { \
  80. ((uint32_t *)(t))[0] = htonl((uint32_t)((f) >> 32)); \
  81. ((uint32_t *)(t))[1] = htonl((uint32_t)((f) & 0xffffffff)); \
  82. }
  83. /* Macros for dealing with byte data saved in uint32_t aligned memory */
  84. #define uint32_aligndown(b) ((b) & ~3)
  85. #define uint32_alignup(b) (((b) + 3) & ~3)
  86. #define uint32_increment(b) (((b) + 3) >> 2)
  87. #endif /* __FS_NFS_XDR_SUBS_H */