You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

oncrpc_iob.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _IPXE_ONCRPC_IOB_H
  2. #define _IPXE_ONCRPC_IOB_H
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <ipxe/iobuf.h>
  6. #include <ipxe/refcnt.h>
  7. #include <ipxe/oncrpc.h>
  8. /** @file
  9. *
  10. * SUN ONC RPC protocol.
  11. *
  12. */
  13. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  14. /**
  15. * Add a string to the end of an I/O buffer
  16. *
  17. * @v io_buf I/O buffer
  18. * @v val String
  19. * @ret size Size of the data written
  20. */
  21. #define oncrpc_iob_add_string( buf, str ) \
  22. ( { \
  23. const char * _str = (str); \
  24. oncrpc_iob_add_array ( (buf), strlen ( _str ), _str ); \
  25. } )
  26. /**
  27. * Get a 32 bits integer from the beginning of an I/O buffer
  28. *
  29. * @v buf I/O buffer
  30. * @ret int Integer
  31. */
  32. #define oncrpc_iob_get_int( buf ) \
  33. ( { \
  34. uint32_t *_val; \
  35. _val = (buf)->data; \
  36. iob_pull ( (buf), sizeof ( uint32_t ) ); \
  37. ntohl ( *_val ); \
  38. } )
  39. /**
  40. * Get a 64 bits integer from the beginning of an I/O buffer
  41. *
  42. * @v buf I/O buffer
  43. * @ret int Integer
  44. */
  45. #define oncrpc_iob_get_int64( buf ) \
  46. ( { \
  47. uint64_t *_val; \
  48. _val = (buf)->data; \
  49. iob_pull ( (buf), sizeof ( uint64_t ) ); \
  50. ntohll ( *_val ); \
  51. } )
  52. size_t oncrpc_iob_add_fields ( struct io_buffer *io_buf,
  53. const struct oncrpc_field fields[] );
  54. size_t oncrpc_iob_add_array ( struct io_buffer *io_buf, size_t length,
  55. const void *data );
  56. size_t oncrpc_iob_add_intarray ( struct io_buffer *io_buf, size_t length,
  57. const uint32_t *array );
  58. size_t oncrpc_iob_add_cred ( struct io_buffer *io_buf,
  59. const struct oncrpc_cred *cred );
  60. size_t oncrpc_iob_get_cred ( struct io_buffer *io_buf,
  61. struct oncrpc_cred *cred );
  62. /**
  63. * Add a 32 bits integer to the end of an I/O buffer
  64. *
  65. * @v io_buf I/O buffer
  66. * @v val Integer
  67. * @ret size Size of the data written
  68. */
  69. static inline size_t oncrpc_iob_add_int ( struct io_buffer *io_buf,
  70. uint32_t val ) {
  71. * ( uint32_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonl ( val );
  72. return ( sizeof ( val) );
  73. }
  74. /**
  75. * Add a 64 bits integer to the end of an I/O buffer
  76. *
  77. * @v io_buf I/O buffer
  78. * @v val Integer
  79. * @ret size Size of the data written
  80. */
  81. static inline size_t oncrpc_iob_add_int64 ( struct io_buffer *io_buf,
  82. uint64_t val ) {
  83. * ( uint64_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonll ( val );
  84. return ( sizeof ( val) );
  85. }
  86. #endif /* _IPXE_ONCRPC_IOB_H */