static int vhdx_log_read_desc(BlockDriverState *bs, BDRVVHDXState *s,

                              VHDXLogEntries *log, VHDXLogDescEntries **buffer,

                              bool convert_endian)

{

    int ret = 0;

    uint32_t desc_sectors;

    uint32_t sectors_read;

    VHDXLogEntryHeader hdr;

    VHDXLogDescEntries *desc_entries = NULL;

    VHDXLogDescriptor desc;

    int i;



    assert(*buffer == NULL);



    ret = vhdx_log_peek_hdr(bs, log, &hdr);

    if (ret < 0) {

        goto exit;

    }



    if (vhdx_log_hdr_is_valid(log, &hdr, s) == false) {

        ret = -EINVAL;

        goto exit;

    }



    desc_sectors = vhdx_compute_desc_sectors(hdr.descriptor_count);

    desc_entries = qemu_blockalign(bs, desc_sectors * VHDX_LOG_SECTOR_SIZE);



    ret = vhdx_log_read_sectors(bs, log, &sectors_read, desc_entries,

                                desc_sectors, false);

    if (ret < 0) {

        goto free_and_exit;

    }

    if (sectors_read != desc_sectors) {

        ret = -EINVAL;

        goto free_and_exit;

    }



    /* put in proper endianness, and validate each desc */

    for (i = 0; i < hdr.descriptor_count; i++) {

        desc = desc_entries->desc[i];

        vhdx_log_desc_le_import(&desc);

        if (convert_endian) {

            desc_entries->desc[i] = desc;

        }

        if (vhdx_log_desc_is_valid(&desc, &hdr) == false) {

            ret = -EINVAL;

            goto free_and_exit;

        }

    }

    if (convert_endian) {

        desc_entries->hdr = hdr;

    }



    *buffer = desc_entries;

    goto exit;



free_and_exit:

    qemu_vfree(desc_entries);

exit:

    return ret;

}

static int vhdx_log_read_desc(BlockDriverState *bs, BDRVVHDXState *s,

                              VHDXLogEntries *log, VHDXLogDescEntries **buffer,

                              bool convert_endian)

{

    int ret = 0;

    uint32_t desc_sectors;

    uint32_t sectors_read;

    VHDXLogEntryHeader hdr;

    VHDXLogDescEntries *desc_entries = NULL;

    VHDXLogDescriptor desc;

    int i;



    assert(*buffer == NULL);



    ret = vhdx_log_peek_hdr(bs, log, &hdr);

    if (ret < 0) {

        goto exit;

    }



    if (vhdx_log_hdr_is_valid(log, &hdr, s) == false) {

        ret = -EINVAL;

        goto exit;

    }



    desc_sectors = vhdx_compute_desc_sectors(hdr.descriptor_count);

    desc_entries = qemu_blockalign(bs, desc_sectors * VHDX_LOG_SECTOR_SIZE);



    ret = vhdx_log_read_sectors(bs, log, &sectors_read, desc_entries,

                                desc_sectors, false);

    if (ret < 0) {

        goto free_and_exit;

    }

    if (sectors_read != desc_sectors) {

        ret = -EINVAL;

        goto free_and_exit;

    }



    

    for (i = 0; i < hdr.descriptor_count; i++) {

        desc = desc_entries->desc[i];

        vhdx_log_desc_le_import(&desc);

        if (convert_endian) {

            desc_entries->desc[i] = desc;

        }

        if (vhdx_log_desc_is_valid(&desc, &hdr) == false) {

            ret = -EINVAL;

            goto free_and_exit;

        }

    }

    if (convert_endian) {

        desc_entries->hdr = hdr;

    }



    *buffer = desc_entries;

    goto exit;



free_and_exit:

    qemu_vfree(desc_entries);

exit:

    return ret;

}

    desc_entries = qemu_blockalign(bs, desc_sectors * VHDX_LOG_SECTOR_SIZE);
static int FUNC_0(BlockDriverState *VAR_0, BDRVVHDXState *VAR_1,

                              VHDXLogEntries *VAR_2, VHDXLogDescEntries **VAR_3,

                              bool VAR_4)

{

    int VAR_5 = 0;

    uint32_t desc_sectors;

    uint32_t sectors_read;

    VHDXLogEntryHeader hdr;

    VHDXLogDescEntries *desc_entries = NULL;

    VHDXLogDescriptor desc;

    int VAR_6;



    assert(*VAR_3 == NULL);



    VAR_5 = vhdx_log_peek_hdr(VAR_0, VAR_2, &hdr);

    if (VAR_5 < 0) {

        goto exit;

    }



    if (vhdx_log_hdr_is_valid(VAR_2, &hdr, VAR_1) == false) {

        VAR_5 = -EINVAL;

        goto exit;

    }



    desc_sectors = vhdx_compute_desc_sectors(hdr.descriptor_count);

    desc_entries = qemu_blockalign(VAR_0, desc_sectors * VHDX_LOG_SECTOR_SIZE);



    VAR_5 = vhdx_log_read_sectors(VAR_0, VAR_2, &sectors_read, desc_entries,

                                desc_sectors, false);

    if (VAR_5 < 0) {

        goto free_and_exit;

    }

    if (sectors_read != desc_sectors) {

        VAR_5 = -EINVAL;

        goto free_and_exit;

    }



    

    for (VAR_6 = 0; VAR_6 < hdr.descriptor_count; VAR_6++) {

        desc = desc_entries->desc[VAR_6];

        vhdx_log_desc_le_import(&desc);

        if (VAR_4) {

            desc_entries->desc[VAR_6] = desc;

        }

        if (vhdx_log_desc_is_valid(&desc, &hdr) == false) {

            VAR_5 = -EINVAL;

            goto free_and_exit;

        }

    }

    if (VAR_4) {

        desc_entries->hdr = hdr;

    }



    *VAR_3 = desc_entries;

    goto exit;



free_and_exit:

    qemu_vfree(desc_entries);

exit:

    return VAR_5;

}

static int FUNC_0(BlockDriverState *VAR_0, BDRVVHDXState *VAR_1,
VHDXLogEntries *VAR_2, VHDXLogDescEntries **VAR_3,
bool VAR_4)
{ int VAR_5 = 0; uint32_t desc_sectors; uint32_t sectors_read; VHDXLogEntryHeader hdr; VHDXLogDescEntries *desc_entries = NULL; VHDXLogDescriptor desc; int VAR_6; assert(*VAR_3 == NULL); VAR_5 = vhdx_log_peek_hdr(VAR_0, VAR_2, &hdr); if (VAR_5 < 0) { goto exit; } if (vhdx_log_hdr_is_valid(VAR_2, &hdr, VAR_1) == false) { VAR_5 = -EINVAL; goto exit; } desc_sectors = vhdx_compute_desc_sectors(hdr.descriptor_count); desc_entries = qemu_blockalign(VAR_0, desc_sectors * VHDX_LOG_SECTOR_SIZE); VAR_5 = vhdx_log_read_sectors(VAR_0, VAR_2, &sectors_read, desc_entries,
desc_sectors, false); if (VAR_5 < 0) { goto free_and_exit; } if (sectors_read != desc_sectors) { VAR_5 = -EINVAL; goto free_and_exit; } for (VAR_6 = 0; VAR_6 < hdr.descriptor_count; VAR_6++) { desc = desc_entries->desc[VAR_6]; vhdx_log_desc_le_import(&desc); if (VAR_4) { desc_entries->desc[VAR_6] = desc; } if (vhdx_log_desc_is_valid(&desc, &hdr) == false) { VAR_5 = -EINVAL; goto free_and_exit; } } if (VAR_4) { desc_entries->hdr = hdr; } *VAR_3 = desc_entries; goto exit; free_and_exit:
qemu_vfree(desc_entries); exit:
return VAR_5; }