iPXE
Data Structures | Functions
blocktrans.h File Reference

Block device translator. More...

#include <stdint.h>
#include <ipxe/refcnt.h>
#include <ipxe/interface.h>
#include <ipxe/xferbuf.h>
#include <ipxe/uaccess.h>

Go to the source code of this file.

Data Structures

struct  block_translator
 A block device translator. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int block_translate (struct interface *block, userptr_t buffer, size_t size)
 Insert block device translator.

Detailed Description

Block device translator.

Definition in file blocktrans.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int block_translate ( struct interface block,
userptr_t  buffer,
size_t  size 
)

Insert block device translator.

Parameters:
blockBlock device interface
bufferData buffer (or UNULL)
sizeLength of data buffer, or block size
Return values:
rcReturn status code

Definition at line 223 of file blocktrans.c.

References assert, block_translator::blksize, blktrans_xferbuf_operations, block_translator::block, block_translator::buffer, buffer, DBGC2, interface::dest, ENOMEM, intf_init(), intf_plug_plug(), xfer_buffer::len, NULL, null_intf, xfer_buffer::op, rc, ref_init, ref_put, block_translator::refcnt, size, user_to_phys(), block_translator::xfer, block_translator::xferbuf, and zalloc().

Referenced by http_block_read(), and http_block_read_capacity().

                                                                               {
        struct block_translator *blktrans;
        int rc;

        /* Allocate and initialise structure */
        blktrans = zalloc ( sizeof ( *blktrans ) );
        if ( ! blktrans ) {
                rc = -ENOMEM;
                goto err_alloc;
        }
        ref_init ( &blktrans->refcnt, NULL );
        intf_init ( &blktrans->block, &blktrans_block_desc, &blktrans->refcnt );
        intf_init ( &blktrans->xfer, &blktrans_xfer_desc, &blktrans->refcnt );
        blktrans->xferbuf.op = &blktrans_xferbuf_operations;
        blktrans->buffer = buffer;
        if ( buffer ) {
                blktrans->xferbuf.len = size;
        } else {
                blktrans->blksize = size;
        }

        /* Attach to interfaces, mortalise self, and return */
        assert ( block->dest != &null_intf );
        intf_plug_plug ( &blktrans->xfer, block->dest );
        intf_plug_plug ( &blktrans->block, block );
        ref_put ( &blktrans->refcnt );

        DBGC2 ( blktrans, "BLKTRANS %p created", blktrans );
        if ( buffer ) {
                DBGC2 ( blktrans, " for %#lx+%#zx",
                        user_to_phys ( buffer, 0 ), size );
        }
        DBGC2 ( blktrans, "\n" );
        return 0;

        ref_put ( &blktrans->refcnt );
 err_alloc:
        return rc;
}