iPXE
Macros | Functions
httpblock.c File Reference

Hyper Text Transfer Protocol (HTTP) block device. More...

#include <stdint.h>
#include <string.h>
#include <ipxe/blocktrans.h>
#include <ipxe/blockdev.h>
#include <ipxe/acpi.h>
#include <ipxe/http.h>

Go to the source code of this file.

Macros

#define HTTP_BLKSIZE   512
 Block size used for HTTP block device requests. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
int http_block_read (struct http_transaction *http, struct interface *data, uint64_t lba, unsigned int count, void *buffer, size_t len)
 Read from block device. More...
 
int http_block_read_capacity (struct http_transaction *http, struct interface *data)
 Read block device capacity. More...
 

Detailed Description

Hyper Text Transfer Protocol (HTTP) block device.

Definition in file httpblock.c.

Macro Definition Documentation

◆ HTTP_BLKSIZE

#define HTTP_BLKSIZE   512

Block size used for HTTP block device requests.

Definition at line 42 of file httpblock.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ http_block_read()

int http_block_read ( struct http_transaction http,
struct interface data,
uint64_t  lba,
unsigned int  count,
void *  buffer,
size_t  len 
)

Read from block device.

Parameters
httpHTTP transaction
dataData interface
lbaStarting logical block address
countNumber of logical blocks
bufferData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 55 of file httpblock.c.

57  {
59  int rc;
60 
61  /* Sanity check */
62  assert ( len == ( count * HTTP_BLKSIZE ) );
63 
64  /* Construct request range descriptor */
65  range.start = ( lba * HTTP_BLKSIZE );
66  range.len = len;
67 
68  /* Start a range request to retrieve the block(s) */
69  if ( ( rc = http_open ( data, &http_get, http->uri, &range,
70  NULL ) ) != 0 )
71  goto err_open;
72 
73  /* Insert block device translator */
74  if ( ( rc = block_translate ( data, buffer, len ) ) != 0 ) {
75  DBGC ( http, "HTTP %p could not insert block translator: %s\n",
76  http, strerror ( rc ) );
77  goto err_translate;
78  }
79 
80  return 0;
81 
82  err_translate:
83  intf_restart ( data, rc );
84  err_open:
85  return rc;
86 }
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:25
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:344
struct pci_range range
PCI bus:dev.fn address range.
Definition: pcicloud.c:40
HTTP request range descriptor.
Definition: http.h:136
#define DBGC(...)
Definition: compiler.h:505
struct uri * uri
Request URI.
Definition: http.h:435
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
static unsigned int count
Number of entries.
Definition: dwmac.h:225
struct http_method http_get
HTTP GET method.
Definition: httpcore.c:144
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
uint64_t lba
Starting block number.
Definition: int13.h:22
int block_translate(struct interface *block, void *buffer, size_t size)
Insert block device translator.
Definition: blocktrans.c:140
int http_open(struct interface *xfer, struct http_method *method, struct uri *uri, struct http_request_range *range, struct http_request_content *content)
Open HTTP transaction.
Definition: httpcore.c:642
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#define HTTP_BLKSIZE
Block size used for HTTP block device requests.
Definition: httpblock.c:42

References assert(), block_translate(), buffer, count, data, DBGC, HTTP_BLKSIZE, http_get, http_open(), intf_restart(), lba, len, NULL, range, rc, pci_range::start, strerror(), and http_transaction::uri.

◆ http_block_read_capacity()

int http_block_read_capacity ( struct http_transaction http,
struct interface data 
)

Read block device capacity.

Parameters
controlControl interface
dataData interface
Return values
rcReturn status code

Definition at line 95 of file httpblock.c.

96  {
97  int rc;
98 
99  /* Start a HEAD request to retrieve the capacity */
100  if ( ( rc = http_open ( data, &http_head, http->uri, NULL,
101  NULL ) ) != 0 )
102  goto err_open;
103 
104  /* Insert block device translator */
105  if ( ( rc = block_translate ( data, NULL, HTTP_BLKSIZE ) ) != 0 ) {
106  DBGC ( http, "HTTP %p could not insert block translator: %s\n",
107  http, strerror ( rc ) );
108  goto err_translate;
109  }
110 
111  return 0;
112 
113  err_translate:
114  intf_restart ( data, rc );
115  err_open:
116  return rc;
117 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:344
struct http_method http_head
HTTP HEAD method.
Definition: httpcore.c:139
#define DBGC(...)
Definition: compiler.h:505
struct uri * uri
Request URI.
Definition: http.h:435
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
int block_translate(struct interface *block, void *buffer, size_t size)
Insert block device translator.
Definition: blocktrans.c:140
int http_open(struct interface *xfer, struct http_method *method, struct uri *uri, struct http_request_range *range, struct http_request_content *content)
Open HTTP transaction.
Definition: httpcore.c:642
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#define HTTP_BLKSIZE
Block size used for HTTP block device requests.
Definition: httpblock.c:42

References block_translate(), data, DBGC, HTTP_BLKSIZE, http_head, http_open(), intf_restart(), NULL, rc, strerror(), and http_transaction::uri.