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  assert ( block->dest != &null_intf );
246  intf_plug_plug ( &blktrans->xfer, block->dest );
247  intf_plug_plug ( &blktrans->block, block );
248  ref_put ( &blktrans->refcnt );
250  DBGC2 ( blktrans, "BLKTRANS %p created", blktrans );
251  if ( buffer ) {
252  DBGC2 ( blktrans, " for %#lx+%#zx",
253  user_to_phys ( buffer, 0 ), size );
254  }
255  DBGC2 ( blktrans, "\n" );
256  return 0;
258  ref_put ( &blktrans->refcnt );
259  err_alloc:
260  return rc;
261 }
struct refcnt refcnt
Reference count.
Definition: blocktrans.h:21
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct interface null_intf
The null interface.
Definition: interface.c:65
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.
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
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
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
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
#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:173
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
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 assert(), 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_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().