iPXE
Data Structures | Defines | 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...

Defines

#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.
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.
struct xfer_bufferxfer_buffer (struct interface *intf)
 Get underlying data transfer buffer.

Variables

struct xfer_buffer_operations xferbuf_malloc_operations
 malloc()-based data buffer operations
struct xfer_buffer_operations xferbuf_umalloc_operations
 umalloc()-based data buffer operations

Detailed Description

Data transfer buffer.

Definition in file xferbuf.h.


Define Documentation

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

Definition at line 102 of file xferbuf.h.

Referenced by xfer_buffer().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static __attribute__ ( (always_inline)  ) [inline, static]

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.

References xferbuf_malloc_operations.

                                                    {
        xferbuf->op = &xferbuf_malloc_operations;
}
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.

References EOVERFLOW, len, max_len, 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().

                                                   {
        size_t max_len;
        int rc;

        /* Check for overflow */
        max_len = ( offset + len );
        if ( max_len < offset )
                return -EOVERFLOW;

        /* Ensure buffer is large enough to contain this write */
        if ( ( rc = xferbuf_ensure_size ( xferbuf, max_len ) ) != 0 )
                return rc;

        /* Copy data to buffer */
        profile_start ( &xferbuf_write_profiler );
        xferbuf->op->write ( xferbuf, offset, data, len );
        profile_stop ( &xferbuf_write_profiler );

        return 0;
}
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.

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

Referenced by peerblk_decrypt_read().

                                            {

        /* Check that read is within buffer range */
        if ( ( offset > xferbuf->len ) ||
             ( len > ( xferbuf->len - offset ) ) )
                return -ENOENT;

        /* Copy data from buffer */
        profile_start ( &xferbuf_read_profiler );
        xferbuf->op->read ( xferbuf, offset, data, len );
        profile_stop ( &xferbuf_read_profiler );

        return 0;
}
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.

References io_buffer::data, done, xfer_metadata::flags, free_iob(), iob_len(), len, xfer_metadata::offset, 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().

                                                   {
        size_t len = iob_len ( iobuf );
        size_t pos;
        int rc;

        /* Start profiling */
        profile_start ( &xferbuf_deliver_profiler );

        /* Calculate new buffer position */
        pos = xferbuf->pos;
        if ( meta->flags & XFER_FL_ABS_OFFSET )
                pos = 0;
        pos += meta->offset;

        /* Write data to buffer */
        if ( ( rc = xferbuf_write ( xferbuf, pos, iobuf->data, len ) ) != 0 )
                goto done;

        /* Update current buffer position */
        xferbuf->pos = ( pos + len );

 done:
        free_iob ( iobuf );
        profile_stop ( &xferbuf_deliver_profiler );
        return rc;
}
struct xfer_buffer* xfer_buffer ( struct interface intf) [read]

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.

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

                                                            {
        struct interface *dest;
        xfer_buffer_TYPE ( void * ) *op =
                intf_get_dest_op ( intf, xfer_buffer, &dest );
        void *object = intf_object ( dest );
        struct interface *xfer_deliver_dest;
        struct xfer_buffer *xferbuf;

        /* Check that this operation is provided by the same interface
         * which handles xfer_deliver().
         */
        ( void ) intf_get_dest_op ( intf, xfer_deliver, &xfer_deliver_dest );

        if ( op && ( dest == xfer_deliver_dest ) ) {
                xferbuf = op ( object );
        } else {
                /* Default is to not have a data transfer buffer */
                xferbuf = NULL;
        }

        intf_put ( xfer_deliver_dest );
        intf_put ( dest );
        return xferbuf;
}

Variable Documentation

malloc()-based data buffer operations

Definition at line 226 of file xferbuf.c.

Referenced by __attribute__().

umalloc()-based data buffer operations

Definition at line 281 of file xferbuf.c.