|
iPXE
|
Data transfer buffers. More...
#include <stdlib.h>#include <string.h>#include <errno.h>#include <ipxe/xfer.h>#include <ipxe/iobuf.h>#include <ipxe/umalloc.h>#include <ipxe/profile.h>#include <ipxe/image.h>#include <ipxe/xferbuf.h>Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| FILE_SECBOOT (PERMITTED) | |
| void | xferbuf_free (struct xfer_buffer *xferbuf) |
| Free data transfer buffer. | |
| static int | xferbuf_ensure_size (struct xfer_buffer *xferbuf, size_t len) |
| Ensure that data transfer buffer is large enough for the specified size. | |
| int | xferbuf_write (struct xfer_buffer *xferbuf, size_t offset, const void *data, size_t len) |
| Write to data transfer buffer. | |
| int | xferbuf_read (struct xfer_buffer *xferbuf, size_t offset, void *data, size_t len) |
| Read from data transfer buffer. | |
| int | xferbuf_deliver (struct xfer_buffer *xferbuf, struct io_buffer *iobuf, struct xfer_metadata *meta) |
| Add received data to data transfer buffer. | |
| static void * | xferbuf_raw_access (struct xfer_buffer *xferbuf) |
| Access raw pointer based data buffer. | |
| static int | xferbuf_malloc_realloc (struct xfer_buffer *xferbuf, size_t len) |
| Reallocate malloc()-based data transfer buffer. | |
| static int | xferbuf_umalloc_realloc (struct xfer_buffer *xferbuf, size_t len) |
| Reallocate umalloc()-based data transfer buffer. | |
| static int | xferbuf_fixed_realloc (struct xfer_buffer *xferbuf, size_t len) |
| Reallocate fixed-size data transfer buffer. | |
| static int | xferbuf_void_realloc (struct xfer_buffer *xferbuf, size_t len __unused) |
| Reallocate void data transfer buffer. | |
| static int | xferbuf_image_realloc (struct xfer_buffer *xferbuf, size_t len) |
| Reallocate image-based data transfer buffer. | |
| static void * | xferbuf_image_access (struct xfer_buffer *xferbuf) |
| Access image-based data transfer buffer. | |
| struct xfer_buffer * | xfer_buffer (struct interface *intf) |
| Get underlying data transfer buffer. | |
Variables | |
| static struct profiler xferbuf_deliver_profiler | __profiler |
| Data delivery profiler. | |
| struct xfer_buffer_operations | xferbuf_malloc_operations |
| malloc()-based data buffer operations | |
| struct xfer_buffer_operations | xferbuf_umalloc_operations |
| umalloc()-based data buffer operations | |
| struct xfer_buffer_operations | xferbuf_fixed_operations |
| Fixed-size data buffer operations. | |
| struct xfer_buffer_operations | xferbuf_void_operations |
| Void data buffer operations. | |
| struct xfer_buffer_operations | xferbuf_image_operations |
| Image-based data buffer operations. | |
Data transfer buffers.
Data transfer buffers provide an abstraction of an underlying storage buffer, with strictly bounds-checking accessors for reading and writing data and optional automatic resizing. They are designed primarily to act as the ultimate sink for receiving I/O buffers containing downloaded data, after all protocol-level framing has been stripped.
The underlying storage buffer may be backed by a malloc() allocation, a umalloc() allocation, a fixed-size buffer, a downloadable image's data, or a /dev/null-style void buffer.
Consumers of data buffers pass an offset and length when reading from or writing to the buffer. Any integer overflow will be reported as a failure (and no data will be read or written).
Attempting to read beyond the end of a buffer will always fail. Attempting to write beyond the end of a buffer will automatically attempt to resize the buffer to accommodate the write (and will fail if this cannot be done).
An object interface may choose to implement the xfer_buffer() interface method to provide another object with direct access to its own data buffer. This is something of a layering violation, but is required to support the badly designed PeerDist protocol which fails to provide the AES initialisation vector until after the encrypted data has all been received.
Definition in file xferbuf.c.
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| FILE_SECBOOT | ( | PERMITTED | ) |
| void xferbuf_free | ( | struct xfer_buffer * | xferbuf | ) |
Free data transfer buffer.
| xferbuf | Data transfer buffer |
Definition at line 88 of file xferbuf.c.
References xfer_buffer::len, xfer_buffer::max, xfer_buffer::op, xfer_buffer::pos, and xfer_buffer_operations::realloc.
Referenced by peerblk_reset(), peermux_free(), validator_free(), and validator_xfer_close().
|
static |
Ensure that data transfer buffer is large enough for the specified size.
| xferbuf | Data transfer buffer |
| len | Required minimum size |
| rc | Return status code |
Definition at line 103 of file xferbuf.c.
References DBGC, len, xfer_buffer::len, xfer_buffer::max, xfer_buffer::op, rc, xfer_buffer_operations::realloc, and strerror().
Referenced by xferbuf_write().
| int xferbuf_write | ( | struct xfer_buffer * | xferbuf, |
| size_t | offset, | ||
| const void * | data, | ||
| size_t | len ) |
Write to data transfer buffer.
Definition at line 133 of file xferbuf.c.
References xfer_buffer_operations::access, data, EOVERFLOW, len, memcpy(), offset, xfer_buffer::op, profile_start(), profile_stop(), raw, rc, and xferbuf_ensure_size().
Referenced by aoecmd_ata_rsp(), fcpcmd_recv_rddata(), iscsi_rx_data_in(), peerblk_decrypt_write(), peerblk_retrieval_rx(), usbblk_in_data(), and xferbuf_deliver().
| int xferbuf_read | ( | struct xfer_buffer * | xferbuf, |
| size_t | offset, | ||
| void * | data, | ||
| size_t | len ) |
Read from data transfer buffer.
Definition at line 166 of file xferbuf.c.
References xfer_buffer_operations::access, data, ENOENT, ENOTTY, len, xfer_buffer::len, memcpy(), offset, xfer_buffer::op, profile_start(), profile_stop(), and raw.
Referenced by aoecmd_ata_cmd(), fcpcmd_send_wrdata(), iscsi_tx_data_out(), peerblk_decrypt_read(), and usbblk_out_data().
| int xferbuf_deliver | ( | struct xfer_buffer * | xferbuf, |
| struct io_buffer * | iobuf, | ||
| struct xfer_metadata * | meta ) |
Add received data to data transfer buffer.
| xferbuf | Data transfer buffer |
| iobuf | I/O buffer |
| meta | Data transfer metadata |
| rc | Return status code |
Definition at line 198 of file xferbuf.c.
References io_buffer::data, done, free_iob(), iob_len(), len, meta, xfer_buffer::pos, profile_start(), profile_stop(), rc, XFER_FL_ABS_OFFSET, and xferbuf_write().
Referenced by blktrans_deliver(), downloader_deliver(), efi_pxe_tftp_deliver(), peermux_info_deliver(), and validator_xfer_deliver().
|
static |
Access raw pointer based data buffer.
| xferbuf | Data transfer buffer |
| raw | Raw data pointer |
Definition at line 232 of file xferbuf.c.
References xfer_buffer::data.
|
static |
Reallocate malloc()-based data transfer buffer.
| xferbuf | Data transfer buffer |
| len | New length (or zero to free buffer) |
| rc | Return status code |
Definition at line 244 of file xferbuf.c.
References xfer_buffer::data, ENOSPC, len, and realloc().
|
static |
Reallocate umalloc()-based data transfer buffer.
| xferbuf | Data transfer buffer |
| len | New length (or zero to free buffer) |
| rc | Return status code |
Definition at line 267 of file xferbuf.c.
References xfer_buffer::data, ENOSPC, len, and urealloc().
|
static |
Reallocate fixed-size data transfer buffer.
| xferbuf | Data transfer buffer |
| len | New length (or zero to free buffer) |
| rc | Return status code |
Definition at line 290 of file xferbuf.c.
References ERANGE, len, and xfer_buffer::len.
|
static |
Reallocate void data transfer buffer.
| xferbuf | Data transfer buffer |
| len | New length (or zero to free buffer) |
| rc | Return status code |
Definition at line 316 of file xferbuf.c.
References __unused, assert, xfer_buffer::data, len, and NULL.
|
static |
Reallocate image-based data transfer buffer.
| xferbuf | Data transfer buffer |
| len | New length (or zero to free buffer) |
| rc | Return status code |
Definition at line 337 of file xferbuf.c.
References xfer_buffer::data, image_set_len(), len, and rc.
|
static |
Access image-based data transfer buffer.
| xferbuf | Data transfer buffer |
| raw | Raw data pointer |
Definition at line 354 of file xferbuf.c.
References xfer_buffer::data, and image::rwdata.
| struct xfer_buffer * xfer_buffer | ( | struct interface * | intf | ) |
Get underlying data transfer buffer.
| interface | Data transfer interface |
| xferbuf | Data transfer buffer, or NULL on error |
This call will check that the xfer_buffer() handler belongs to the destination interface which also provides xfer_deliver() for this interface.
This is done to prevent accidental accesses to a data transfer buffer which may be located behind a non-transparent datapath via a series of pass-through interfaces.
Definition at line 380 of file xferbuf.c.
References dest, interface::intf, intf_get_dest_op, intf_object(), intf_put(), NULL, op, xfer_buffer_TYPE, and xfer_deliver().
Referenced by http_content_buffer(), peerblk_decrypt(), and peermux_block_buffer().
|
static |
| struct xfer_buffer_operations xferbuf_malloc_operations |
malloc()-based data buffer operations
Definition at line 255 of file xferbuf.c.
Referenced by xferbuf_malloc_init().
| struct xfer_buffer_operations xferbuf_umalloc_operations |
umalloc()-based data buffer operations
Definition at line 278 of file xferbuf.c.
Referenced by xferbuf_umalloc_init().
| struct xfer_buffer_operations xferbuf_fixed_operations |
Fixed-size data buffer operations.
Definition at line 304 of file xferbuf.c.
Referenced by xferbuf_fixed_init().
| struct xfer_buffer_operations xferbuf_void_operations |
Void data buffer operations.
Definition at line 325 of file xferbuf.c.
Referenced by xferbuf_void_init().
| struct xfer_buffer_operations xferbuf_image_operations |
Image-based data buffer operations.
Definition at line 361 of file xferbuf.c.
Referenced by xferbuf_image_init().