iPXE
Macros | Functions
httpblock.c File Reference

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

#include <stdint.h>
#include <ipxe/uaccess.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)
 
int http_block_read (struct http_transaction *http, struct interface *data, uint64_t lba, unsigned int count, userptr_t 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 41 of file httpblock.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ http_block_read()

int http_block_read ( struct http_transaction http,
struct interface data,
uint64_t  lba,
unsigned int  count,
userptr_t  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 54 of file httpblock.c.

56  {
57  struct http_request_range range;
58  int rc;
59 
60  /* Sanity check */
61  assert ( len == ( count * HTTP_BLKSIZE ) );
62 
63  /* Construct request range descriptor */
64  range.start = ( lba * HTTP_BLKSIZE );
65  range.len = len;
66 
67  /* Start a range request to retrieve the block(s) */
68  if ( ( rc = http_open ( data, &http_get, http->uri, &range,
69  NULL ) ) != 0 )
70  goto err_open;
71 
72  /* Insert block device translator */
73  if ( ( rc = block_translate ( data, buffer, len ) ) != 0 ) {
74  DBGC ( http, "HTTP %p could not insert block translator: %s\n",
75  http, strerror ( rc ) );
76  goto err_translate;
77  }
78 
79  return 0;
80 
81  err_translate:
82  intf_restart ( data, rc );
83  err_open:
84  return rc;
85 }
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:337
uint32_t lba
Start address.
Definition: scsi.h:23
HTTP request range descriptor.
Definition: http.h:137
#define DBGC(...)
Definition: compiler.h:505
struct uri * uri
Request URI.
Definition: http.h:434
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
int block_translate(struct interface *block, userptr_t buffer, size_t size)
Insert block device translator.
Definition: blocktrans.c:223
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct http_method http_get
HTTP GET method.
Definition: httpcore.c:138
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint32_t len
Length.
Definition: ena.h:14
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:586
uint16_t count
Number of entries.
Definition: ena.h:22
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define HTTP_BLKSIZE
Block size used for HTTP block device requests.
Definition: httpblock.c:41

References assert(), block_translate(), buffer, count, data, DBGC, HTTP_BLKSIZE, http_get, http_open(), intf_restart(), lba, len, http_request_range::len, NULL, rc, http_request_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 94 of file httpblock.c.

95  {
96  int rc;
97 
98  /* Start a HEAD request to retrieve the capacity */
99  if ( ( rc = http_open ( data, &http_head, http->uri, NULL,
100  NULL ) ) != 0 )
101  goto err_open;
102 
103  /* Insert block device translator */
104  if ( ( rc = block_translate ( data, UNULL, HTTP_BLKSIZE ) ) != 0 ) {
105  DBGC ( http, "HTTP %p could not insert block translator: %s\n",
106  http, strerror ( rc ) );
107  goto err_translate;
108  }
109 
110  return 0;
111 
112  err_translate:
113  intf_restart ( data, rc );
114  err_open:
115  return rc;
116 }
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:337
struct http_method http_head
HTTP HEAD method.
Definition: httpcore.c:133
#define DBGC(...)
Definition: compiler.h:505
struct uri * uri
Request URI.
Definition: http.h:434
int block_translate(struct interface *block, userptr_t buffer, size_t size)
Insert block device translator.
Definition: blocktrans.c:223
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
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:586
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define HTTP_BLKSIZE
Block size used for HTTP block device requests.
Definition: httpblock.c:41

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