iPXE
Functions
iobuf.c File Reference

I/O buffers. More...

#include <stdint.h>
#include <strings.h>
#include <errno.h>
#include <ipxe/malloc.h>
#include <ipxe/iobuf.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
struct io_bufferalloc_iob_raw (size_t len, size_t align, size_t offset)
 Allocate I/O buffer with specified alignment and offset. More...
 
struct io_bufferalloc_iob (size_t len)
 Allocate I/O buffer. More...
 
void free_iob (struct io_buffer *iobuf)
 Free I/O buffer. More...
 
struct io_bufferalloc_rx_iob (size_t len, struct dma_device *dma)
 Allocate and map I/O buffer for receive DMA. More...
 
void free_rx_iob (struct io_buffer *iobuf)
 Unmap and free I/O buffer for receive DMA. More...
 
int iob_ensure_headroom (struct io_buffer *iobuf, size_t len)
 Ensure I/O buffer has sufficient headroom. More...
 
struct io_bufferiob_concatenate (struct list_head *list)
 Concatenate I/O buffers into a single buffer. More...
 
struct io_bufferiob_split (struct io_buffer *iobuf, size_t len)
 Split I/O buffer. More...
 

Detailed Description

I/O buffers.

Definition in file iobuf.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ alloc_iob_raw()

struct io_buffer* alloc_iob_raw ( size_t  len,
size_t  align,
size_t  offset 
)

Allocate I/O buffer with specified alignment and offset.

Parameters
lenRequired length of buffer
alignPhysical alignment
offsetOffset from physical alignment
Return values
iobufI/O buffer, or NULL if none available

align will be rounded up to the nearest power of two.

Definition at line 48 of file iobuf.c.

48  {
49  struct io_buffer *iobuf;
50  size_t headroom;
51  size_t tailroom;
52  size_t padding;
53  size_t threshold;
54  unsigned int align_log2;
55  void *data;
56 
57  /* Round up requested alignment and calculate initial headroom
58  * and tailroom to ensure that no cachelines are shared
59  * between I/O buffer data and other data structures.
60  */
61  if ( align < IOB_ZLEN )
62  align = IOB_ZLEN;
63  headroom = ( offset & ( IOB_ZLEN - 1 ) );
64  tailroom = ( ( - len - offset ) & ( IOB_ZLEN - 1 ) );
65  padding = ( headroom + tailroom );
66  offset -= headroom;
67  len += padding;
68  if ( len < padding )
69  return NULL;
70 
71  /* Round up alignment to the nearest power of two, avoiding
72  * a potentially undefined shift operation.
73  */
74  align_log2 = fls ( align - 1 );
75  if ( align_log2 >= ( 8 * sizeof ( align ) ) )
76  return NULL;
77  align = ( 1UL << align_log2 );
78 
79  /* Calculate length threshold */
80  assert ( align >= sizeof ( *iobuf ) );
81  threshold = ( align - sizeof ( *iobuf ) );
82 
83  /* Allocate buffer plus an inline descriptor as a single unit,
84  * unless doing so would push the total size over the
85  * alignment boundary.
86  */
87  if ( len <= threshold ) {
88 
89  /* Allocate memory for buffer plus descriptor */
90  data = malloc_phys_offset ( len + sizeof ( *iobuf ), align,
91  offset );
92  if ( ! data )
93  return NULL;
94  iobuf = ( data + len );
95 
96  } else {
97 
98  /* Allocate memory for buffer */
99  data = malloc_phys_offset ( len, align, offset );
100  if ( ! data )
101  return NULL;
102 
103  /* Allocate memory for descriptor */
104  iobuf = malloc ( sizeof ( *iobuf ) );
105  if ( ! iobuf ) {
106  free_phys ( data, len );
107  return NULL;
108  }
109  }
110 
111  /* Populate descriptor */
112  memset ( &iobuf->map, 0, sizeof ( iobuf->map ) );
113  iobuf->head = data;
114  iobuf->data = iobuf->tail = ( data + headroom );
115  iobuf->end = ( data + len );
116 
117  return iobuf;
118 }
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:47
void * tail
End of data.
Definition: iobuf.h:54
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
void * malloc_phys_offset(size_t size, size_t phys_align, size_t offset)
Allocate memory with specified physical alignment and offset.
Definition: malloc.c:684
void * end
End of the buffer.
Definition: iobuf.h:56
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:620
void * head
Start of the buffer.
Definition: iobuf.h:50
#define IOB_ZLEN
Minimum I/O buffer length and alignment.
Definition: iobuf.h:28
void * data
Start of data.
Definition: iobuf.h:52
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.c:722
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
#define fls(x)
Find last (i.e.
Definition: strings.h:166
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:37

References assert(), data, io_buffer::data, io_buffer::end, fls, free_phys(), io_buffer::head, IOB_ZLEN, len, malloc(), malloc_phys_offset(), io_buffer::map, memset(), NULL, offset, and io_buffer::tail.

Referenced by alloc_iob(), alloc_iob_fail_okx(), alloc_iob_okx(), ath_rx_init(), ath_rx_tasklet(), iob_concatenate(), ipoib_alloc_iob(), and tls_newdata_process_header().

◆ alloc_iob()

struct io_buffer* alloc_iob ( size_t  len)

Allocate I/O buffer.

Parameters
lenRequired length of buffer
Return values
iobufI/O buffer, or NULL if none available

The I/O buffer will be physically aligned on its own size (rounded up to the nearest power of two), up to a maximum of page-size alignment.

Definition at line 130 of file iobuf.c.

130  {
131  size_t align;
132 
133  /* Pad to minimum length */
134  if ( len < IOB_ZLEN )
135  len = IOB_ZLEN;
136 
137  /* Align buffer on its own size (up to page size) to avoid
138  * potential problems with boundary-crossing DMA.
139  */
140  align = len;
141  if ( align > PAGE_SIZE )
142  align = PAGE_SIZE;
143 
144  return alloc_iob_raw ( len, align, 0 );
145 }
struct io_buffer * alloc_iob_raw(size_t len, size_t align, size_t offset)
Allocate I/O buffer with specified alignment and offset.
Definition: iobuf.c:48
#define PAGE_SIZE
Page size.
Definition: io.h:27
ring len
Length.
Definition: dwmac.h:231
#define IOB_ZLEN
Minimum I/O buffer length and alignment.
Definition: iobuf.h:28

References alloc_iob_raw(), IOB_ZLEN, len, and PAGE_SIZE.

Referenced by a3c90x_refill_rx_ring(), acm_control_receive(), alloc_rx_iob(), aoecmd_tx(), arp_tx_request(), ath5k_rx_iob_alloc(), atl1e_clean_rx_irq(), axge_in_complete(), b44_init_rx_ring(), b44_rx_refill(), ccmp_decrypt(), ccmp_encrypt(), eapol_tx(), efab_fill_rx_queue(), efi_snp_transmit(), efi_usb_sync_transfer(), efx_hunt_rxq_fill(), ena_refill_rx(), eoib_duplicate(), exanic_poll_rx(), fcoe_alloc_iob(), fcoe_fip_tx_keepalive(), fcoe_fip_tx_solicitation(), fcoe_fip_tx_vlan(), fragment_reassemble(), gdbudp_send(), gve_poll_rx(), http_rx_chunk_data(), hunt_mcdi_init(), ib_mi_send(), icplus_refill_rx(), ifec_get_rx_desc(), igbvf_refill_rx_ring(), igbvf_setup_rx_resources(), imux_alloc_iob(), imux_tx_syn(), imux_tx_version(), iob_split(), jme_make_new_rx_buf(), legacy_poll(), loopback_test(), mnpnet_poll_rx(), myri10ge_net_open(), myri10ge_net_poll(), myson_refill_rx(), natsemi_refill_rx(), ncm_in_complete(), ndp_tx_ll_addr(), net80211_accum_frags(), net80211_probe_start(), net80211_probe_step(), net80211_send_assoc(), net80211_send_auth(), net80211_send_disassoc(), netfront_refill_rx(), nii_poll_rx(), nv_alloc_rx(), pcnet32_refill_rx_ring(), phantom_refill_rx_ring(), ping_alloc_iob(), pnic_poll(), pxenv_undi_transmit(), realtek_legacy_poll_rx(), rhine_refill_rx(), rndis_alloc_iob(), rtl818x_handle_rx(), rtl818x_init_rx_ring(), sis190_alloc_rx_iob(), skge_rx_refill(), sky2_rx_alloc(), snpnet_poll_rx(), tcp_xmit_reset(), tcp_xmit_sack(), tg3_alloc_rx_iob(), tkip_decrypt(), tkip_encrypt(), txnic_refill_rq(), udp_xfer_alloc_iob(), undinet_poll(), usb_control(), usb_prefill(), usb_refill_limit(), usbblk_out_command(), usbblk_out_data(), velocity_refill_rx(), vmbus_xfer_page_iobufs(), vmxnet3_refill_rx(), vxge_hw_ring_replenish(), vxge_hw_vpath_poll_rx(), wep_decrypt(), wep_encrypt(), wpa_alloc_frame(), and xfer_alloc_iob().

◆ free_iob()

void free_iob ( struct io_buffer iobuf)

Free I/O buffer.

Parameters
iobufI/O buffer

Definition at line 152 of file iobuf.c.

152  {
153  size_t len;
154 
155  /* Allow free_iob(NULL) to be valid */
156  if ( ! iobuf )
157  return;
158 
159  /* Sanity checks */
160  assert ( iobuf->head <= iobuf->data );
161  assert ( iobuf->data <= iobuf->tail );
162  assert ( iobuf->tail <= iobuf->end );
163  assert ( ! dma_mapped ( &iobuf->map ) );
164 
165  /* Free buffer */
166  len = ( iobuf->end - iobuf->head );
167  if ( iobuf->end == iobuf ) {
168 
169  /* Descriptor is inline */
170  free_phys ( iobuf->head, ( len + sizeof ( *iobuf ) ) );
171 
172  } else {
173 
174  /* Descriptor is detached */
175  free_phys ( iobuf->head, len );
176  free ( iobuf );
177  }
178 }
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:47
void * tail
End of data.
Definition: iobuf.h:54
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
static __always_inline int dma_mapped(struct dma_mapping *map)
Check if DMA unmapping is required.
Definition: dma.h:441
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * end
End of the buffer.
Definition: iobuf.h:56
void * head
Start of the buffer.
Definition: iobuf.h:50
void * data
Start of data.
Definition: iobuf.h:52
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.c:722

References assert(), io_buffer::data, dma_mapped(), io_buffer::end, free, free_phys(), io_buffer::head, len, io_buffer::map, and io_buffer::tail.

Referenced by __vxge_hw_ring_delete(), a3c90x_free_rx_iobuf(), acm_control_receive(), acm_in_complete(), acm_intr_complete(), alloc_iob_okx(), alloc_rx_iob(), aoe_rx(), aoecmd_rx(), arp_rx(), ath5k_rxbuf_free(), ath9k_stop(), ath9k_tx(), ath_rx_cleanup(), axge_in_complete(), axge_intr_complete(), b44_free_rx_ring(), b44_rx_refill(), ccmp_decrypt(), dhcp_deliver(), dhcp_tx(), dhcpv6_rx(), dm96xx_in_complete(), dm96xx_intr_complete(), dns_xfer_deliver(), eapol_eap_rx(), eapol_key_rx(), eapol_rx(), ecm_in_complete(), ecm_intr_complete(), efab_free_resources(), efab_receive(), efi_download_deliver_iob(), efi_local_step(), efi_pxe_udp_close(), efi_pxe_udp_deliver(), efi_pxe_udp_read(), efi_pxe_udp_write(), efi_snp_flush(), efi_snp_receive(), efi_snp_transmit(), efi_usb_async_complete(), efi_usb_sync_transfer(), efx_hunt_close(), ena_empty_rx(), eoib_heartbeat_rx(), eth_slow_marker_rx(), eth_slow_rx(), fc_els_rx(), fc_ns_query_deliver(), fc_port_deliver(), fc_xchg_rx(), fc_xchg_tx(), fcoe_deliver(), fcoe_fip_rx(), fcoe_rx(), fcpcmd_recv_rddata(), fcpcmd_recv_rsp(), fcpcmd_recv_unknown(), fcpcmd_recv_xfer_rdy(), fragment_expired(), fragment_reassemble(), free_rx_iob(), free_tls(), ftp_control_deliver(), gdbudp_recv(), http_conn_deliver(), http_content_deliver(), http_tx_request(), hunt_mcdi_fini(), ib_cmrc_complete_recv(), ib_cmrc_complete_send(), ib_cmrc_xfer_deliver(), ib_complete_recv(), ib_complete_send(), ib_mi_complete_recv(), ib_mi_send(), ib_refill_recv(), icmp_rx_echo_reply(), icmp_rx_echo_request(), icmp_tx_echo_request(), icmpv4_rx(), icmpv6_rx(), icplus_close(), ifec_free(), igbvf_free_rx_resources(), imux_in_complete(), imux_out_complete(), imux_rx_tcp(), imux_tx(), iob_concatenate(), ipair_deliver(), iphone_in_complete(), ipv4_rx(), ipv4_tx(), ipv6_rx(), ipv6_tx(), iscsi_socket_deliver(), jme_free_rx_buf(), legacy_poll(), lldp_rx(), loopback_wait(), lotest_flush(), lotest_rx(), myri10ge_net_close(), myri10ge_net_open(), myson_close(), natsemi_close(), ncm_intr_complete(), ndp_rx_neighbour(), ndp_rx_router_advertisement(), net80211_free_frags(), net80211_free_wlan(), net80211_handle_mgmt(), net80211_probe_finish_all(), net80211_probe_finish_best(), net80211_probe_step(), net80211_rx(), net80211_rx_frag(), net80211_tx_mgmt(), net_discard(), net_poll(), net_rx(), netdev_rx_err(), netdev_tx_err(), netfront_close(), netfront_discard(), netvsc_recv_data(), nfs_deliver(), nfs_mount_deliver(), nfs_pm_deliver(), nii_close(), ntp_deliver(), nv_free_rxtx_resources(), pcnet32_free_rx_resources(), peerblk_deliver(), peerblk_raw_rx(), peerblk_retrieval_rx(), peerdisc_socket_rx(), phantom_close(), ping_rx(), pinger_deliver(), posix_file_free(), posix_file_xfer_deliver(), pxe_tftp_xfer_deliver(), pxe_udp_deliver(), pxe_udp_discard(), pxenv_udp_close(), pxenv_udp_read(), pxenv_undi_isr(), pxenv_undi_transmit(), rarp_rx(), read(), rhine_close(), rndis_rx_initialise(), rndis_rx_query_oid(), rndis_rx_set_oid(), rndis_rx_status(), rndis_tx_complete_err(), rndis_tx_halt(), rndis_tx_initialise(), rndis_tx_oid(), rtl818x_free_rx_ring(), sis190_free(), skge_rx_clean(), sky2_rx_clean(), slam_mc_socket_deliver(), slam_socket_deliver(), slam_tx_nack(), smsc75xx_in_complete(), smsc95xx_in_complete(), smscusb_intr_complete(), snpnet_close(), srpdev_deliver(), stp_rx(), tcp_close(), tcp_discard(), tcp_process_tx_queue(), tcp_rx(), tcp_rx_data(), tcp_rx_enqueue(), tcpip_rx(), tcpip_tx(), tftp_rx(), tftp_rx_data(), tg3_rx_iob_free(), tkip_decrypt(), tls_cipherstream_deliver(), tls_new_record(), tls_newdata_process_header(), tls_plainstream_deliver(), tls_send_record(), txnic_destroy_rq(), udp_rx(), udp_tx(), unregister_usb(), usb_control(), usb_flush(), usbblk_in_complete(), usbblk_out_command(), usbblk_out_complete(), usbblk_out_data(), velocity_close(), vlan_rx(), vmbus_xfer_page_iobufs(), vxge_hw_ring_replenish(), wep_decrypt(), xcm_deliver(), xfer_deliver(), and xferbuf_deliver().

◆ alloc_rx_iob()

struct io_buffer* alloc_rx_iob ( size_t  len,
struct dma_device dma 
)

Allocate and map I/O buffer for receive DMA.

Parameters
lenLength of I/O buffer
dmaDMA device
Return values
iobufI/O buffer, or NULL on error

Definition at line 187 of file iobuf.c.

187  {
188  struct io_buffer *iobuf;
189  int rc;
190 
191  /* Allocate I/O buffer */
192  iobuf = alloc_iob ( len );
193  if ( ! iobuf )
194  goto err_alloc;
195 
196  /* Map I/O buffer */
197  if ( ( rc = iob_map_rx ( iobuf, dma ) ) != 0 )
198  goto err_map;
199 
200  return iobuf;
201 
202  iob_unmap ( iobuf );
203  err_map:
204  free_iob ( iobuf );
205  err_alloc:
206  return NULL;
207 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:152
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:130
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:278
ring len
Length.
Definition: dwmac.h:231
static __always_inline int iob_map_rx(struct io_buffer *iobuf, struct dma_device *dma)
Map empty I/O buffer for receive DMA.
Definition: iobuf.h:255
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
A persistent I/O buffer.
Definition: iobuf.h:37

References alloc_iob(), dma(), free_iob(), iob_map_rx(), iob_unmap(), len, NULL, and rc.

Referenced by atl_rx_ring_fill(), bnxt_alloc_rx_iob(), cgem_refill_rx(), dwmac_refill_rx(), intel_refill_rx(), intelxl_refill_rx(), rdc_refill_rx(), realtek_refill_rx(), and virtnet_refill_rx_virtqueue().

◆ free_rx_iob()

void free_rx_iob ( struct io_buffer iobuf)

Unmap and free I/O buffer for receive DMA.

Parameters
iobufI/O buffer

Definition at line 214 of file iobuf.c.

214  {
215 
216  /* Unmap I/O buffer */
217  iob_unmap ( iobuf );
218 
219  /* Free I/O buffer */
220  free_iob ( iobuf );
221 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:152
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:278

References free_iob(), and iob_unmap().

Referenced by bnxt_free_rx_iob(), cgem_close(), dwmac_close(), intel_empty_rx(), intelxl_empty_rx(), rdc_close(), realtek_close(), and virtnet_close().

◆ iob_ensure_headroom()

int iob_ensure_headroom ( struct io_buffer iobuf,
size_t  len 
)

Ensure I/O buffer has sufficient headroom.

Parameters
iobufI/O buffer
lenRequired headroom

This function currently only checks for the required headroom; it does not reallocate the I/O buffer if required. If we ever have a code path that requires this functionality, it's a fairly trivial change to make.

Definition at line 234 of file iobuf.c.

234  {
235 
236  if ( iob_headroom ( iobuf ) >= len )
237  return 0;
238  return -ENOBUFS;
239 }
ring len
Length.
Definition: dwmac.h:231
static size_t iob_headroom(struct io_buffer *iobuf)
Calculate available space at start of an I/O buffer.
Definition: iobuf.h:169
#define ENOBUFS
No buffer space available.
Definition: errno.h:498

References ENOBUFS, iob_headroom(), and len.

Referenced by axge_out_transmit(), dm96xx_out_transmit(), efi_pxe_udp_deliver(), ncm_out_transmit(), pxe_udp_deliver(), smsc75xx_out_transmit(), smsc95xx_out_transmit(), and udp_tx().

◆ iob_concatenate()

struct io_buffer* iob_concatenate ( struct list_head list)

Concatenate I/O buffers into a single buffer.

Parameters
listList of I/O buffers
Return values
iobufConcatenated I/O buffer, or NULL on allocation failure

After a successful concatenation, the list will be empty.

Definition at line 249 of file iobuf.c.

249  {
250  struct io_buffer *iobuf;
251  struct io_buffer *tmp;
252  struct io_buffer *concatenated;
253  size_t len = 0;
254 
255  /* If the list contains only a single entry, avoid an
256  * unnecessary additional allocation.
257  */
258  if ( list_is_singular ( list ) ) {
259  iobuf = list_first_entry ( list, struct io_buffer, list );
260  INIT_LIST_HEAD ( list );
261  return iobuf;
262  }
263 
264  /* Calculate total length */
265  list_for_each_entry ( iobuf, list, list )
266  len += iob_len ( iobuf );
267 
268  /* Allocate new I/O buffer */
269  concatenated = alloc_iob_raw ( len, IOB_ZLEN, 0 );
270  if ( ! concatenated )
271  return NULL;
272 
273  /* Move data to new I/O buffer */
274  list_for_each_entry_safe ( iobuf, tmp, list, list ) {
275  list_del ( &iobuf->list );
276  memcpy ( iob_put ( concatenated, iob_len ( iobuf ) ),
277  iobuf->data, iob_len ( iobuf ) );
278  free_iob ( iobuf );
279  }
280 
281  return concatenated;
282 }
#define iob_put(iobuf, len)
Definition: iobuf.h:124
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:152
struct io_buffer * alloc_iob_raw(size_t len, size_t align, size_t offset)
Allocate I/O buffer with specified alignment and offset.
Definition: iobuf.c:48
unsigned long tmp
Definition: linux_pci.h:64
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
ring len
Length.
Definition: dwmac.h:231
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:458
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:159
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
#define list_is_singular(list)
Test whether a list has just one entry.
Definition: list.h:149
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:44
#define IOB_ZLEN
Minimum I/O buffer length and alignment.
Definition: iobuf.h:28
void * data
Start of data.
Definition: iobuf.h:52
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A persistent I/O buffer.
Definition: iobuf.h:37

References alloc_iob_raw(), io_buffer::data, free_iob(), INIT_LIST_HEAD, iob_len(), iob_put, IOB_ZLEN, len, io_buffer::list, list_del, list_first_entry, list_for_each_entry, list_for_each_entry_safe, list_is_singular, memcpy(), NULL, and tmp.

Referenced by netfront_poll_rx(), and tls_new_record().

◆ iob_split()

struct io_buffer* iob_split ( struct io_buffer iobuf,
size_t  len 
)

Split I/O buffer.

Parameters
iobufI/O buffer
lenLength to split into a new I/O buffer
Return values
splitNew I/O buffer, or NULL on allocation failure

Split the first len bytes of the existing I/O buffer into a separate I/O buffer. The resulting buffers are likely to have no headroom or tailroom.

If this call fails, then the original buffer will be unmodified.

Definition at line 297 of file iobuf.c.

297  {
298  struct io_buffer *split;
299 
300  /* Sanity checks */
301  assert ( len <= iob_len ( iobuf ) );
302 
303  /* Allocate new I/O buffer */
304  split = alloc_iob ( len );
305  if ( ! split )
306  return NULL;
307 
308  /* Copy in data */
309  memcpy ( iob_put ( split, len ), iobuf->data, len );
310  iob_pull ( iobuf, len );
311  return split;
312 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:106
#define iob_put(iobuf, len)
Definition: iobuf.h:124
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:130
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:159
void * data
Start of data.
Definition: iobuf.h:52
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A persistent I/O buffer.
Definition: iobuf.h:37

References alloc_iob(), assert(), io_buffer::data, iob_len(), iob_pull, iob_put, len, memcpy(), and NULL.