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

Defines

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

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.
int http_block_read_capacity (struct http_transaction *http, struct interface *data)
 Read block device capacity.

Detailed Description

Hyper Text Transfer Protocol (HTTP) block device.

Definition in file httpblock.c.


Define Documentation

#define HTTP_BLKSIZE   512

Block size used for HTTP block device requests.

Definition at line 41 of file httpblock.c.

Referenced by http_block_read(), and http_block_read_capacity().


Function Documentation

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.

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.

References assert, block_translate(), DBGC, HTTP_BLKSIZE, http_get, http_open(), intf_restart(), http_request_range::len, len, NULL, rc, http_request_range::start, strerror(), and http_transaction::uri.

                                   {
        struct http_request_range range;
        int rc;

        /* Sanity check */
        assert ( len == ( count * HTTP_BLKSIZE ) );

        /* Construct request range descriptor */
        range.start = ( lba * HTTP_BLKSIZE );
        range.len = len;

        /* Start a range request to retrieve the block(s) */
        if ( ( rc = http_open ( data, &http_get, http->uri, &range,
                                NULL ) ) != 0 )
                goto err_open;

        /* Insert block device translator */
        if ( ( rc = block_translate ( data, buffer, len ) ) != 0 ) {
                DBGC ( http, "HTTP %p could not insert block translator: %s\n",
                       http, strerror ( rc ) );
                goto err_translate;
        }

        return 0;

 err_translate:
        intf_restart ( data, rc );
 err_open:
        return rc;
}
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.

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

                                                        {
        int rc;

        /* Start a HEAD request to retrieve the capacity */
        if ( ( rc = http_open ( data, &http_head, http->uri, NULL,
                                NULL ) ) != 0 )
                goto err_open;

        /* Insert block device translator */
        if ( ( rc = block_translate ( data, UNULL, HTTP_BLKSIZE ) ) != 0 ) {
                DBGC ( http, "HTTP %p could not insert block translator: %s\n",
                       http, strerror ( rc ) );
                goto err_translate;
        }

        return 0;

 err_translate:
        intf_restart ( data, rc );
 err_open:
        return rc;
}