iPXE
httpblock.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 FILE_SECBOOT ( PERMITTED );
26 
27 /**
28  * @file
29  *
30  * Hyper Text Transfer Protocol (HTTP) block device
31  *
32  */
33 
34 #include <stdint.h>
35 #include <string.h>
36 #include <ipxe/blocktrans.h>
37 #include <ipxe/blockdev.h>
38 #include <ipxe/acpi.h>
39 #include <ipxe/http.h>
40 
41 /** Block size used for HTTP block device requests */
42 #define HTTP_BLKSIZE 512
43 
44 /**
45  * Read from block device
46  *
47  * @v http HTTP transaction
48  * @v data Data interface
49  * @v lba Starting logical block address
50  * @v count Number of logical blocks
51  * @v buffer Data buffer
52  * @v len Length of data buffer
53  * @ret rc Return status code
54  */
55 int http_block_read ( struct http_transaction *http, struct interface *data,
56  uint64_t lba, unsigned int count, void *buffer,
57  size_t len ) {
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 }
87 
88 /**
89  * Read block device capacity
90  *
91  * @v control Control interface
92  * @v data Data interface
93  * @ret rc Return status code
94  */
96  struct interface *data ) {
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 }
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
struct http_method http_head
HTTP HEAD method.
Definition: httpcore.c:139
HTTP request range descriptor.
Definition: http.h:136
#define DBGC(...)
Definition: compiler.h:505
struct uri * uri
Request URI.
Definition: http.h:435
unsigned long long uint64_t
Definition: stdint.h:13
Block device translator.
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
int http_block_read_capacity(struct http_transaction *http, struct interface *data)
Read block device capacity.
Definition: httpblock.c:95
An HTTP transaction.
Definition: http.h:416
Hyper Text Transport Protocol.
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.
Definition: httpblock.c:55
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
An object interface.
Definition: interface.h:125
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
Block devices.
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
ACPI data structures.
uint64_t lba
Starting block number.
Definition: int13.h:22
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
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
FILE_SECBOOT(PERMITTED)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
String functions.
#define HTTP_BLKSIZE
Block size used for HTTP block device requests.
Definition: httpblock.c:42