iPXE
Data Structures | Macros | Functions | Variables
xferbuf.h File Reference

Data transfer buffer. More...

#include <stdint.h>
#include <ipxe/iobuf.h>
#include <ipxe/uaccess.h>
#include <ipxe/interface.h>
#include <ipxe/xfer.h>

Go to the source code of this file.

Data Structures

struct  xfer_buffer
 A data transfer buffer. More...
 
struct  xfer_buffer_operations
 Data transfer buffer operations. More...
 

Macros

#define xfer_buffer_TYPE(object_type)   typeof ( struct xfer_buffer * ( object_type ) )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static __attribute__ ((always_inline)) void xferbuf_malloc_init(struct xfer_buffer *xferbuf)
 Initialise malloc()-based data transfer buffer. More...
 
void xferbuf_free (struct xfer_buffer *xferbuf)
 Free data transfer buffer. More...
 
int xferbuf_write (struct xfer_buffer *xferbuf, size_t offset, const void *data, size_t len)
 Write to data transfer buffer. More...
 
int xferbuf_read (struct xfer_buffer *xferbuf, size_t offset, void *data, size_t len)
 Read from data transfer buffer. More...
 
int xferbuf_deliver (struct xfer_buffer *xferbuf, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Add received data to data transfer buffer. More...
 
struct xfer_bufferxfer_buffer (struct interface *intf)
 Get underlying data transfer buffer. More...
 

Variables

struct xfer_buffer_operations xferbuf_malloc_operations
 malloc()-based data buffer operations More...
 
struct xfer_buffer_operations xferbuf_umalloc_operations
 umalloc()-based data buffer operations More...
 
static userptr_tdata
 
xferbuf op = &xferbuf_umalloc_operations
 

Detailed Description

Data transfer buffer.

Definition in file xferbuf.h.

Macro Definition Documentation

◆ xfer_buffer_TYPE

#define xfer_buffer_TYPE (   object_type)    typeof ( struct xfer_buffer * ( object_type ) )

Definition at line 102 of file xferbuf.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Initialise malloc()-based data transfer buffer.

Initialise umalloc()-based data transfer buffer.

Parameters
xferbufData transfer buffer
xferbufData transfer buffer
dataUser pointer

Definition at line 75 of file xferbuf.h.

76  {
77  xferbuf->op = &xferbuf_malloc_operations;
78 }
struct xfer_buffer_operations xferbuf_malloc_operations
malloc()-based data buffer operations
Definition: xferbuf.c:226

References xfer_buffer::op, and xferbuf_malloc_operations.

◆ xferbuf_free()

void xferbuf_free ( struct xfer_buffer xferbuf)

Free data transfer buffer.

Parameters
xferbufData transfer buffer

Definition at line 58 of file xferbuf.c.

58  {
59 
60  xferbuf->op->realloc ( xferbuf, 0 );
61  xferbuf->len = 0;
62  xferbuf->pos = 0;
63 }
size_t pos
Current offset within data.
Definition: xferbuf.h:25
size_t len
Size of data.
Definition: xferbuf.h:23
struct xfer_buffer_operations * op
Data transfer buffer operations.
Definition: xferbuf.h:27
int(* realloc)(struct xfer_buffer *xferbuf, size_t len)
Reallocate data buffer.
Definition: xferbuf.h:38

References xfer_buffer::len, xfer_buffer::op, xfer_buffer::pos, and xfer_buffer_operations::realloc.

Referenced by peerblk_reset(), peermux_free(), validator_free(), and validator_xfer_close().

◆ xferbuf_write()

int xferbuf_write ( struct xfer_buffer xferbuf,
size_t  offset,
const void *  data,
size_t  len 
)

Write to data transfer buffer.

Parameters
xferbufData transfer buffer
offsetStarting offset
dataData to write
lenLength of data

Definition at line 98 of file xferbuf.c.

99  {
100  size_t max_len;
101  int rc;
102 
103  /* Check for overflow */
104  max_len = ( offset + len );
105  if ( max_len < offset )
106  return -EOVERFLOW;
107 
108  /* Ensure buffer is large enough to contain this write */
109  if ( ( rc = xferbuf_ensure_size ( xferbuf, max_len ) ) != 0 )
110  return rc;
111 
112  /* Copy data to buffer */
113  profile_start ( &xferbuf_write_profiler );
114  xferbuf->op->write ( xferbuf, offset, data, len );
115  profile_stop ( &xferbuf_write_profiler );
116 
117  return 0;
118 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void size_t size_t max_len
Definition: entropy.h:153
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
void(* write)(struct xfer_buffer *xferbuf, size_t offset, const void *data, size_t len)
Write data to buffer.
Definition: xferbuf.h:50
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
struct xfer_buffer_operations * op
Data transfer buffer operations.
Definition: xferbuf.h:27
#define EOVERFLOW
Value too large to be stored in data type.
Definition: errno.h:609
uint32_t len
Length.
Definition: ena.h:14
static int xferbuf_ensure_size(struct xfer_buffer *xferbuf, size_t len)
Ensure that data transfer buffer is large enough for the specified size.
Definition: xferbuf.c:72
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References data, EOVERFLOW, len, max_len, offset, xfer_buffer::op, profile_start(), profile_stop(), rc, xfer_buffer_operations::write, and xferbuf_ensure_size().

Referenced by peerblk_decrypt_write(), peerblk_retrieval_rx(), and xferbuf_deliver().

◆ xferbuf_read()

int xferbuf_read ( struct xfer_buffer xferbuf,
size_t  offset,
void *  data,
size_t  len 
)

Read from data transfer buffer.

Parameters
xferbufData transfer buffer
offsetStarting offset
dataData to write
lenLength of data

Definition at line 128 of file xferbuf.c.

129  {
130 
131  /* Check that read is within buffer range */
132  if ( ( offset > xferbuf->len ) ||
133  ( len > ( xferbuf->len - offset ) ) )
134  return -ENOENT;
135 
136  /* Copy data from buffer */
137  profile_start ( &xferbuf_read_profiler );
138  xferbuf->op->read ( xferbuf, offset, data, len );
139  profile_stop ( &xferbuf_read_profiler );
140 
141  return 0;
142 }
void(* read)(struct xfer_buffer *xferbuf, size_t offset, void *data, size_t len)
Read data from buffer.
Definition: xferbuf.h:63
#define ENOENT
No such file or directory.
Definition: errno.h:514
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
size_t len
Size of data.
Definition: xferbuf.h:23
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
struct xfer_buffer_operations * op
Data transfer buffer operations.
Definition: xferbuf.h:27
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References data, ENOENT, len, xfer_buffer::len, offset, xfer_buffer::op, profile_start(), profile_stop(), and xfer_buffer_operations::read.

Referenced by peerblk_decrypt_read().

◆ xferbuf_deliver()

int xferbuf_deliver ( struct xfer_buffer xferbuf,
struct io_buffer iobuf,
struct xfer_metadata meta 
)

Add received data to data transfer buffer.

Parameters
xferbufData transfer buffer
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 152 of file xferbuf.c.

153  {
154  size_t len = iob_len ( iobuf );
155  size_t pos;
156  int rc;
157 
158  /* Start profiling */
159  profile_start ( &xferbuf_deliver_profiler );
160 
161  /* Calculate new buffer position */
162  pos = xferbuf->pos;
163  if ( meta->flags & XFER_FL_ABS_OFFSET )
164  pos = 0;
165  pos += meta->offset;
166 
167  /* Write data to buffer */
168  if ( ( rc = xferbuf_write ( xferbuf, pos, iobuf->data, len ) ) != 0 )
169  goto done;
170 
171  /* Update current buffer position */
172  xferbuf->pos = ( pos + len );
173 
174  done:
175  free_iob ( iobuf );
176  profile_stop ( &xferbuf_deliver_profiler );
177  return rc;
178 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:47
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
size_t pos
Current offset within data.
Definition: xferbuf.h:25
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
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
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
int meta(WINDOW *, bool)
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:44
struct bofm_section_header done
Definition: bofm_test.c:46

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().

◆ xfer_buffer()

struct xfer_buffer* xfer_buffer ( struct interface intf)

Get underlying data transfer buffer.

Parameters
interfaceData transfer interface
Return values
xferbufData 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 301 of file xferbuf.c.

301  {
302  struct interface *dest;
303  xfer_buffer_TYPE ( void * ) *op =
304  intf_get_dest_op ( intf, xfer_buffer, &dest );
305  void *object = intf_object ( dest );
306  struct interface *xfer_deliver_dest;
307  struct xfer_buffer *xferbuf;
308 
309  /* Check that this operation is provided by the same interface
310  * which handles xfer_deliver().
311  */
312  ( void ) intf_get_dest_op ( intf, xfer_deliver, &xfer_deliver_dest );
313 
314  if ( op && ( dest == xfer_deliver_dest ) ) {
315  xferbuf = op ( object );
316  } else {
317  /* Default is to not have a data transfer buffer */
318  xferbuf = NULL;
319  }
320 
321  intf_put ( xfer_deliver_dest );
322  intf_put ( dest );
323  return xferbuf;
324 }
A data transfer buffer.
Definition: xferbuf.h:19
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:154
An object interface.
Definition: interface.h:109
#define xfer_buffer_TYPE(object_type)
Definition: xferbuf.h:102
static void * dest
Definition: strings.h:176
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:193
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:144
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:214

References dest, 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().

Variable Documentation

◆ xferbuf_malloc_operations

struct xfer_buffer_operations xferbuf_malloc_operations

malloc()-based data buffer operations

Definition at line 226 of file xferbuf.c.

Referenced by __attribute__().

◆ xferbuf_umalloc_operations

struct xfer_buffer_operations xferbuf_umalloc_operations

umalloc()-based data buffer operations

Definition at line 281 of file xferbuf.c.

◆ data

userptr_t* data
Initial value:
{
xferbuf->data = data
static userptr_t * data
Definition: xferbuf.h:87

Definition at line 87 of file xferbuf.h.

◆ op

Definition at line 89 of file xferbuf.h.