mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 21:03:54 -06:00
luks: extract qcrypto_block_calculate_payload_offset()
The qcow2 .bdrv_measure() code calculates the crypto payload offset. This logic really belongs in crypto/block.c where it can be reused by other image formats. The "luks" block driver will need this same logic in order to implement .bdrv_measure(), so extract the qcrypto_block_calculate_payload_offset() function now. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-Id: <20200221112522.1497712-2-stefanha@redhat.com> Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
ba29883206
commit
6d49d3a859
3 changed files with 77 additions and 55 deletions
|
@ -115,6 +115,42 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options,
|
|||
}
|
||||
|
||||
|
||||
static ssize_t qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block,
|
||||
size_t headerlen, void *opaque, Error **errp)
|
||||
{
|
||||
size_t *headerlenp = opaque;
|
||||
|
||||
/* Stash away the payload size */
|
||||
*headerlenp = headerlen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static ssize_t qcrypto_block_headerlen_hdr_write_func(QCryptoBlock *block,
|
||||
size_t offset, const uint8_t *buf, size_t buflen,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
/* Discard the bytes, we're not actually writing to an image */
|
||||
return buflen;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
qcrypto_block_calculate_payload_offset(QCryptoBlockCreateOptions *create_opts,
|
||||
const char *optprefix,
|
||||
size_t *len,
|
||||
Error **errp)
|
||||
{
|
||||
/* Fake LUKS creation in order to determine the payload size */
|
||||
g_autoptr(QCryptoBlock) crypto =
|
||||
qcrypto_block_create(create_opts, optprefix,
|
||||
qcrypto_block_headerlen_hdr_init_func,
|
||||
qcrypto_block_headerlen_hdr_write_func,
|
||||
len, errp);
|
||||
return crypto != NULL;
|
||||
}
|
||||
|
||||
|
||||
QCryptoBlockInfo *qcrypto_block_get_info(QCryptoBlock *block,
|
||||
Error **errp)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue