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


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

Detailed Description

Block device translator.

Definition in file blocktrans.h.

Function Documentation



◆ block_translate()

int block_translate ( struct interface block,
userptr_t  buffer,
size_t  size 

Insert block device translator.

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.

223  {
224  struct block_translator *blktrans;
225  int rc;
227  /* Allocate and initialise structure */
228  blktrans = zalloc ( sizeof ( *blktrans ) );
229  if ( ! blktrans ) {
230  rc = -ENOMEM;
231  goto err_alloc;
232  }
233  ref_init ( &blktrans->refcnt, NULL );
234  intf_init ( &blktrans->block, &blktrans_block_desc, &blktrans->refcnt );
235  intf_init ( &blktrans->xfer, &blktrans_xfer_desc, &blktrans->refcnt );
237  blktrans->buffer = buffer;
238  if ( buffer ) {
239  blktrans->xferbuf.len = size;
240  } else {
241  blktrans->blksize = size;
242  }
244  /* Attach to interfaces, mortalise self, and return */
245  intf_insert ( block, &blktrans->block, &blktrans->xfer );
246  ref_put ( &blktrans->refcnt );
248  DBGC2 ( blktrans, "BLKTRANS %p created", blktrans );
249  if ( buffer ) {
250  DBGC2 ( blktrans, " for %#lx+%#zx",
251  user_to_phys ( buffer, 0 ), size );
252  }
253  DBGC2 ( blktrans, "\n" );
254  return 0;
256  ref_put ( &blktrans->refcnt );
257  err_alloc:
258  return rc;
259 }
struct refcnt refcnt
Reference count.
Definition: blocktrans.h:21
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct interface_descriptor blktrans_block_desc
Block device translator block device interface descriptor.
Definition: blocktrans.c:199
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
uint16_t block
Definition: tftp.h:12
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
size_t len
Size of data.
Definition: xferbuf.h:23
#define ENOMEM
Not enough space.
Definition: errno.h:534
A block device translator.
Definition: blocktrans.h:19
struct interface xfer
Data transfer interface.
Definition: blocktrans.h:25
struct xfer_buffer_operations * op
Data transfer buffer operations.
Definition: xferbuf.h:27
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static struct interface_descriptor blktrans_xfer_desc
Block device translator data transfer interface descriptor.
Definition: blocktrans.c:211
void intf_insert(struct interface *intf, struct interface *upper, struct interface *lower)
Insert a filter interface.
Definition: interface.c:401
#define DBGC2(...)
Definition: compiler.h:522
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
struct xfer_buffer xferbuf
Data transfer buffer.
Definition: blocktrans.h:28
size_t blksize
Block size.
Definition: blocktrans.h:32
static struct xfer_buffer_operations blktrans_xferbuf_operations
Block device translator data transfer buffer operations.
Definition: blocktrans.c:120
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
userptr_t buffer
Data buffer.
Definition: blocktrans.h:30
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
struct interface block
Block device interface.
Definition: blocktrans.h:23

References block_translator::blksize, blktrans_block_desc, blktrans_xfer_desc, blktrans_xferbuf_operations, block, block_translator::block, buffer, block_translator::buffer, DBGC2, ENOMEM, intf_init(), intf_insert(), xfer_buffer::len, NULL, 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().