summaryrefslogtreecommitdiffstats
path: root/qemu/roms/ipxe/src/include/ipxe/oncrpc_iob.h
blob: b550437709cb615da99c683c3c144384b95efcb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef _IPXE_ONCRPC_IOB_H
#define _IPXE_ONCRPC_IOB_H

#include <stdint.h>
#include <string.h>
#include <ipxe/iobuf.h>
#include <ipxe/refcnt.h>
#include <ipxe/oncrpc.h>

/** @file
 *
 * SUN ONC RPC protocol.
 *
 */

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

/**
 * Add a string to the end of an I/O buffer
 *
 * @v io_buf            I/O buffer
 * @v val               String
 * @ret size            Size of the data written
 */
#define oncrpc_iob_add_string( buf, str ) \
( { \
	const char * _str = (str); \
	oncrpc_iob_add_array ( (buf), strlen ( _str ), _str ); \
} )

/**
 * Get a 32 bits integer from the beginning of an I/O buffer
 *
 * @v buf               I/O buffer
 * @ret int             Integer
 */

#define oncrpc_iob_get_int( buf ) \
( { \
	uint32_t *_val; \
	_val = (buf)->data; \
	iob_pull ( (buf), sizeof ( uint32_t ) ); \
	ntohl ( *_val ); \
} )

/**
 * Get a 64 bits integer from the beginning of an I/O buffer
 *
 * @v buf               I/O buffer
 * @ret int             Integer
 */
#define oncrpc_iob_get_int64( buf ) \
( { \
	uint64_t *_val; \
	_val = (buf)->data; \
	iob_pull ( (buf), sizeof ( uint64_t ) ); \
	ntohll ( *_val ); \
} )


size_t oncrpc_iob_add_fields ( struct io_buffer *io_buf,
                               const struct oncrpc_field fields[] );

size_t oncrpc_iob_add_array ( struct io_buffer *io_buf, size_t length,
                              const void *data );

size_t oncrpc_iob_add_intarray ( struct io_buffer *io_buf, size_t length,
                                 const uint32_t *array );

size_t oncrpc_iob_add_cred ( struct io_buffer *io_buf,
                             const struct oncrpc_cred *cred );

size_t oncrpc_iob_get_cred ( struct io_buffer *io_buf,
                             struct oncrpc_cred *cred );

/**
 * Add a 32 bits integer to the end of an I/O buffer
 *
 * @v io_buf            I/O buffer
 * @v val               Integer
 * @ret size            Size of the data written
 */
static inline size_t oncrpc_iob_add_int ( struct io_buffer *io_buf,
                                          uint32_t val ) {
	* ( uint32_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonl ( val );
	return ( sizeof ( val) );
}

/**
 * Add a 64 bits integer to the end of an I/O buffer
 *
 * @v io_buf            I/O buffer
 * @v val               Integer
 * @ret size            Size of the data written
 */
static inline size_t oncrpc_iob_add_int64 ( struct io_buffer *io_buf,
                                            uint64_t val ) {
	* ( uint64_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonll ( val );
	return ( sizeof ( val) );
}

#endif /* _IPXE_ONCRPC_IOB_H */