iPXE
xferbuf.h
Go to the documentation of this file.
1 #ifndef _IPXE_XFERBUF_H
2 #define _IPXE_XFERBUF_H
3 
4 /** @file
5  *
6  * Data transfer buffer
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 #include <ipxe/iobuf.h>
14 #include <ipxe/uaccess.h>
15 #include <ipxe/interface.h>
16 #include <ipxe/xfer.h>
17 
18 /** A data transfer buffer */
19 struct xfer_buffer {
20  /** Data */
21  void *data;
22  /** Size of data */
23  size_t len;
24  /** Current offset within data */
25  size_t pos;
26  /** Data transfer buffer operations */
28 };
29 
30 /** Data transfer buffer operations */
32  /** Reallocate data buffer
33  *
34  * @v xferbuf Data transfer buffer
35  * @v len New length (or zero to free buffer)
36  * @ret rc Return status code
37  */
38  int ( * realloc ) ( struct xfer_buffer *xferbuf, size_t len );
39  /** Write data to buffer
40  *
41  * @v xferbuf Data transfer buffer
42  * @v offset Starting offset
43  * @v data Data to write
44  * @v len Length of data
45  *
46  * This call is simply a wrapper for the appropriate
47  * memcpy()-like operation: the caller is responsible for
48  * ensuring that the write does not exceed the buffer length.
49  */
50  void ( * write ) ( struct xfer_buffer *xferbuf, size_t offset,
51  const void *data, size_t len );
52  /** Read data from buffer
53  *
54  * @v xferbuf Data transfer buffer
55  * @v offset Starting offset
56  * @v data Data to read
57  * @v len Length of data
58  *
59  * This call is simply a wrapper for the appropriate
60  * memcpy()-like operation: the caller is responsible for
61  * ensuring that the read does not exceed the buffer length.
62  */
63  void ( * read ) ( struct xfer_buffer *xferbuf, size_t offset,
64  void *data, size_t len );
65 };
66 
69 
70 /**
71  * Initialise malloc()-based data transfer buffer
72  *
73  * @v xferbuf Data transfer buffer
74  */
75 static inline __attribute__ (( always_inline )) void
76 xferbuf_malloc_init ( struct xfer_buffer *xferbuf ) {
77  xferbuf->op = &xferbuf_malloc_operations;
78 }
79 
80 /**
81  * Initialise umalloc()-based data transfer buffer
82  *
83  * @v xferbuf Data transfer buffer
84  * @v data User pointer
85  */
86 static inline __attribute__ (( always_inline )) void
87 xferbuf_umalloc_init ( struct xfer_buffer *xferbuf, userptr_t *data ) {
88  xferbuf->data = data;
90 }
91 
92 extern void xferbuf_free ( struct xfer_buffer *xferbuf );
93 extern int xferbuf_write ( struct xfer_buffer *xferbuf, size_t offset,
94  const void *data, size_t len );
95 extern int xferbuf_read ( struct xfer_buffer *xferbuf, size_t offset,
96  void *data, size_t len );
97 extern int xferbuf_deliver ( struct xfer_buffer *xferbuf,
98  struct io_buffer *iobuf,
99  struct xfer_metadata *meta );
100 
101 extern struct xfer_buffer * xfer_buffer ( struct interface *intf );
102 #define xfer_buffer_TYPE( object_type ) \
103  typeof ( struct xfer_buffer * ( object_type ) )
104 
105 #endif /* _IPXE_XFERBUF_H */
void * data
Data.
Definition: xferbuf.h:21
Data transfer metadata.
Definition: xfer.h:22
void xferbuf_free(struct xfer_buffer *xferbuf)
Free data transfer buffer.
Definition: xferbuf.c:58
A data transfer buffer.
Definition: xferbuf.h:19
int xferbuf_write(struct xfer_buffer *xferbuf, size_t offset, const void *data, size_t len)
Write to data transfer buffer.
Definition: xferbuf.c:98
I/O buffers.
void(* read)(struct xfer_buffer *xferbuf, size_t offset, void *data, size_t len)
Read data from buffer.
Definition: xferbuf.h:63
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
size_t pos
Current offset within data.
Definition: xferbuf.h:25
Access to external ("user") memory.
Data transfer interfaces.
Data transfer buffer operations.
Definition: xferbuf.h:31
size_t len
Size of data.
Definition: xferbuf.h:23
void(* write)(struct xfer_buffer *xferbuf, size_t offset, const void *data, size_t len)
Write data to buffer.
Definition: xferbuf.h:50
An object interface.
Definition: interface.h:109
Object interfaces.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
int xferbuf_deliver(struct xfer_buffer *xferbuf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Add received data to data transfer buffer.
Definition: xferbuf.c:152
struct xfer_buffer_operations xferbuf_umalloc_operations
umalloc()-based data buffer operations
Definition: xferbuf.c:281
int meta(WINDOW *, bool)
struct xfer_buffer_operations * op
Data transfer buffer operations.
Definition: xferbuf.h:27
struct xfer_buffer_operations xferbuf_malloc_operations
malloc()-based data buffer operations
Definition: xferbuf.c:226
static userptr_t * data
Definition: xferbuf.h:87
struct xfer_buffer * xfer_buffer(struct interface *intf)
Get underlying data transfer buffer.
Definition: xferbuf.c:301
uint32_t len
Length.
Definition: ena.h:14
static __attribute__((always_inline)) void xferbuf_malloc_init(struct xfer_buffer *xferbuf)
Initialise malloc()-based data transfer buffer.
Definition: xferbuf.h:75
int(* realloc)(struct xfer_buffer *xferbuf, size_t len)
Reallocate data buffer.
Definition: xferbuf.h:38
int xferbuf_read(struct xfer_buffer *xferbuf, size_t offset, void *data, size_t len)
Read from data transfer buffer.
Definition: xferbuf.c:128
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33
A persistent I/O buffer.
Definition: iobuf.h:32