static int vpc_write(BlockDriverState *bs, int64_t sector_num,

    const uint8_t *buf, int nb_sectors)

{

    BDRVVPCState *s = bs->opaque;

    int64_t offset;

    int64_t sectors, sectors_per_block;

    int ret;

    VHDFooter *footer =  (VHDFooter *) s->footer_buf;



    if (cpu_to_be32(footer->type) == VHD_FIXED) {

        return bdrv_write(bs->file, sector_num, buf, nb_sectors);

    }

    while (nb_sectors > 0) {

        offset = get_sector_offset(bs, sector_num, 1);



        sectors_per_block = s->block_size >> BDRV_SECTOR_BITS;

        sectors = sectors_per_block - (sector_num % sectors_per_block);

        if (sectors > nb_sectors) {

            sectors = nb_sectors;

        }



        if (offset == -1) {

            offset = alloc_block(bs, sector_num);

            if (offset < 0)

                return -1;

        }



        ret = bdrv_pwrite(bs->file, offset, buf, sectors * BDRV_SECTOR_SIZE);

        if (ret != sectors * BDRV_SECTOR_SIZE) {

            return -1;

        }



        nb_sectors -= sectors;

        sector_num += sectors;

        buf += sectors * BDRV_SECTOR_SIZE;

    }



    return 0;

}

static int vpc_write(BlockDriverState *bs, int64_t sector_num,

    const uint8_t *buf, int nb_sectors)

{

    BDRVVPCState *s = bs->opaque;

    int64_t offset;

    int64_t sectors, sectors_per_block;

    int ret;

    VHDFooter *footer =  (VHDFooter *) s->footer_buf;



    if (cpu_to_be32(footer->type) == VHD_FIXED) {

        return bdrv_write(bs->file, sector_num, buf, nb_sectors);

    }

    while (nb_sectors > 0) {

        offset = get_sector_offset(bs, sector_num, 1);



        sectors_per_block = s->block_size >> BDRV_SECTOR_BITS;

        sectors = sectors_per_block - (sector_num % sectors_per_block);

        if (sectors > nb_sectors) {

            sectors = nb_sectors;

        }



        if (offset == -1) {

            offset = alloc_block(bs, sector_num);

            if (offset < 0)

                return -1;

        }



        ret = bdrv_pwrite(bs->file, offset, buf, sectors * BDRV_SECTOR_SIZE);

        if (ret != sectors * BDRV_SECTOR_SIZE) {

            return -1;

        }



        nb_sectors -= sectors;

        sector_num += sectors;

        buf += sectors * BDRV_SECTOR_SIZE;

    }



    return 0;

}

    if (cpu_to_be32(footer->type) == VHD_FIXED) {     if (cpu_to_be32(footer->type) == VHD_FIXED) {     if (cpu_to_be32(footer->type) == VHD_FIXED) {
static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1,

    const uint8_t *VAR_2, int VAR_3)

{

    BDRVVPCState *s = VAR_0->opaque;

    int64_t offset;

    int64_t sectors, sectors_per_block;

    int VAR_4;

    VHDFooter *footer =  (VHDFooter *) s->footer_buf;



    if (cpu_to_be32(footer->type) == VHD_FIXED) {

        return bdrv_write(VAR_0->file, VAR_1, VAR_2, VAR_3);

    }

    while (VAR_3 > 0) {

        offset = get_sector_offset(VAR_0, VAR_1, 1);



        sectors_per_block = s->block_size >> BDRV_SECTOR_BITS;

        sectors = sectors_per_block - (VAR_1 % sectors_per_block);

        if (sectors > VAR_3) {

            sectors = VAR_3;

        }



        if (offset == -1) {

            offset = alloc_block(VAR_0, VAR_1);

            if (offset < 0)

                return -1;

        }



        VAR_4 = bdrv_pwrite(VAR_0->file, offset, VAR_2, sectors * BDRV_SECTOR_SIZE);

        if (VAR_4 != sectors * BDRV_SECTOR_SIZE) {

            return -1;

        }



        VAR_3 -= sectors;

        VAR_1 += sectors;

        VAR_2 += sectors * BDRV_SECTOR_SIZE;

    }



    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1,
const uint8_t *VAR_2, int VAR_3)
{ BDRVVPCState *s = VAR_0->opaque; int64_t offset; int64_t sectors, sectors_per_block; int VAR_4; VHDFooter *footer =  (VHDFooter *) s->footer_buf; if (cpu_to_be32(footer->type) == VHD_FIXED) { return bdrv_write(VAR_0->file, VAR_1, VAR_2, VAR_3); } while (VAR_3 > 0) { offset = get_sector_offset(VAR_0, VAR_1, 1); sectors_per_block = s->block_size >> BDRV_SECTOR_BITS; sectors = sectors_per_block - (VAR_1 % sectors_per_block); if (sectors > VAR_3) { sectors = VAR_3; } if (offset == -1) { offset = alloc_block(VAR_0, VAR_1); if (offset < 0)
return -1; } VAR_4 = bdrv_pwrite(VAR_0->file, offset, VAR_2, sectors * BDRV_SECTOR_SIZE); if (VAR_4 != sectors * BDRV_SECTOR_SIZE) { return -1; } VAR_3 -= sectors; VAR_1 += sectors; VAR_2 += sectors * BDRV_SECTOR_SIZE; } return 0; }