[xferbuf] Simplify and generalise data transfer buffers

Since all data transfer buffer contents are now accessible via direct
pointer dereferences, remove the unnecessary abstractions for read and
write operations and create two new data transfer buffer types: a
fixed-size buffer, and a void buffer that records its size but can
never receive non-zero lengths of data.  These replace the custom data
buffer types currently implemented for EFI PXE TFTP downloads and for
block device translations.

A new operation xferbuf_detach() is required to take ownership of the
data accumulated in the data transfer buffer, since we no longer rely
on the existence of an independently owned external data pointer for
data transfer buffers allocated via umalloc().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-04-29 09:16:41 +01:00
parent 43fc516298
commit 837b77293b
7 changed files with 130 additions and 245 deletions

View File

@@ -303,48 +303,6 @@ static int efi_pxe_ip_filter ( struct efi_pxe *pxe, EFI_IP_ADDRESS *ip ) {
return 0;
}
/******************************************************************************
*
* Data transfer buffer
*
******************************************************************************
*/
/**
* Reallocate PXE data transfer buffer
*
* @v xferbuf Data transfer buffer
* @v len New length (or zero to free buffer)
* @ret rc Return status code
*/
static int efi_pxe_buf_realloc ( struct xfer_buffer *xferbuf __unused,
size_t len __unused ) {
/* Can never reallocate: return EFI_BUFFER_TOO_SMALL */
return -ERANGE;
}
/**
* Write data to PXE data transfer buffer
*
* @v xferbuf Data transfer buffer
* @v offset Starting offset
* @v data Data to copy
* @v len Length of data
*/
static void efi_pxe_buf_write ( struct xfer_buffer *xferbuf, size_t offset,
const void *data, size_t len ) {
/* Copy data to buffer */
memcpy ( ( xferbuf->data + offset ), data, len );
}
/** PXE data transfer buffer operations */
static struct xfer_buffer_operations efi_pxe_buf_operations = {
.realloc = efi_pxe_buf_realloc,
.write = efi_pxe_buf_write,
};
/******************************************************************************
*
* (M)TFTP download interface
@@ -966,8 +924,7 @@ efi_pxe_mtftp ( EFI_PXE_BASE_CODE_PROTOCOL *base,
pxe->blksize = ( ( callback && blksize ) ? *blksize : -1UL );
/* Initialise data transfer buffer */
pxe->buf.data = data;
pxe->buf.len = *len;
xferbuf_fixed_init ( &pxe->buf, data, *len );
/* Open download */
if ( ( rc = efi_pxe_tftp_open ( pxe, ip,
@@ -987,6 +944,7 @@ efi_pxe_mtftp ( EFI_PXE_BASE_CODE_PROTOCOL *base,
err_download:
efi_pxe_tftp_close ( pxe, rc );
err_open:
xferbuf_fixed_init ( &pxe->buf, NULL, 0 );
efi_snp_release();
err_opcode:
return EFIRC ( rc );
@@ -1611,7 +1569,6 @@ int efi_pxe_install ( EFI_HANDLE handle, struct net_device *netdev ) {
pxe->base.Mode = &pxe->mode;
memcpy ( &pxe->apple, &efi_apple_net_boot_protocol,
sizeof ( pxe->apple ) );
pxe->buf.op = &efi_pxe_buf_operations;
intf_init ( &pxe->tftp, &efi_pxe_tftp_desc, &pxe->refcnt );
intf_init ( &pxe->udp, &efi_pxe_udp_desc, &pxe->refcnt );
INIT_LIST_HEAD ( &pxe->queue );