static int block_load(QEMUFile *f, void *opaque, int version_id)

{

    static int banner_printed;

    int len, flags;

    char device_name[256];

    int64_t addr;

    BlockDriverState *bs;

    uint8_t *buf;



    do {

        addr = qemu_get_be64(f);



        flags = addr & ~BDRV_SECTOR_MASK;

        addr >>= BDRV_SECTOR_BITS;



        if (flags & BLK_MIG_FLAG_DEVICE_BLOCK) {

            int ret;

            /* get device name */

            len = qemu_get_byte(f);

            qemu_get_buffer(f, (uint8_t *)device_name, len);

            device_name[len] = '\0';



            bs = bdrv_find(device_name);

            if (!bs) {

                fprintf(stderr, "Error unknown block device %s\n",

                        device_name);

                return -EINVAL;

            }



            buf = qemu_malloc(BLOCK_SIZE);



            qemu_get_buffer(f, buf, BLOCK_SIZE);

            ret = bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK);



            qemu_free(buf);

            if (ret < 0) {

                return ret;

            }

        } else if (flags & BLK_MIG_FLAG_PROGRESS) {

            if (!banner_printed) {

                printf("Receiving block device images\n");

                banner_printed = 1;

            }

            printf("Completed %d %%%c", (int)addr,

                   (addr == 100) ? '\n' : '\r');

            fflush(stdout);

        } else if (!(flags & BLK_MIG_FLAG_EOS)) {

            fprintf(stderr, "Unknown flags\n");

            return -EINVAL;

        }

        if (qemu_file_has_error(f)) {

            return -EIO;

        }

    } while (!(flags & BLK_MIG_FLAG_EOS));



    return 0;

}

static int block_load(QEMUFile *f, void *opaque, int version_id)

{

    static int banner_printed;

    int len, flags;

    char device_name[256];

    int64_t addr;

    BlockDriverState *bs;

    uint8_t *buf;



    do {

        addr = qemu_get_be64(f);



        flags = addr & ~BDRV_SECTOR_MASK;

        addr >>= BDRV_SECTOR_BITS;



        if (flags & BLK_MIG_FLAG_DEVICE_BLOCK) {

            int ret;

            

            len = qemu_get_byte(f);

            qemu_get_buffer(f, (uint8_t *)device_name, len);

            device_name[len] = '\0';



            bs = bdrv_find(device_name);

            if (!bs) {

                fprintf(stderr, "Error unknown block device %s\n",

                        device_name);

                return -EINVAL;

            }



            buf = qemu_malloc(BLOCK_SIZE);



            qemu_get_buffer(f, buf, BLOCK_SIZE);

            ret = bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK);



            qemu_free(buf);

            if (ret < 0) {

                return ret;

            }

        } else if (flags & BLK_MIG_FLAG_PROGRESS) {

            if (!banner_printed) {

                printf("Receiving block device images\n");

                banner_printed = 1;

            }

            printf("Completed %d %%%c", (int)addr,

                   (addr == 100) ? '\n' : '\r');

            fflush(stdout);

        } else if (!(flags & BLK_MIG_FLAG_EOS)) {

            fprintf(stderr, "Unknown flags\n");

            return -EINVAL;

        }

        if (qemu_file_has_error(f)) {

            return -EIO;

        }

    } while (!(flags & BLK_MIG_FLAG_EOS));



    return 0;

}

    BlockDriverState *bs;             ret = bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK);
static int FUNC_0(QEMUFile *VAR_0, void *VAR_1, int VAR_2)

{

    static int VAR_3;

    int VAR_4, VAR_5;

    char VAR_6[256];

    int64_t addr;

    BlockDriverState *bs;

    uint8_t *buf;



    do {

        addr = qemu_get_be64(VAR_0);



        VAR_5 = addr & ~BDRV_SECTOR_MASK;

        addr >>= BDRV_SECTOR_BITS;



        if (VAR_5 & BLK_MIG_FLAG_DEVICE_BLOCK) {

            int VAR_7;

            

            VAR_4 = qemu_get_byte(VAR_0);

            qemu_get_buffer(VAR_0, (uint8_t *)VAR_6, VAR_4);

            VAR_6[VAR_4] = '\0';



            bs = bdrv_find(VAR_6);

            if (!bs) {

                fprintf(stderr, "Error unknown block device %s\n",

                        VAR_6);

                return -EINVAL;

            }



            buf = qemu_malloc(BLOCK_SIZE);



            qemu_get_buffer(VAR_0, buf, BLOCK_SIZE);

            VAR_7 = bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK);



            qemu_free(buf);

            if (VAR_7 < 0) {

                return VAR_7;

            }

        } else if (VAR_5 & BLK_MIG_FLAG_PROGRESS) {

            if (!VAR_3) {

                printf("Receiving block device images\n");

                VAR_3 = 1;

            }

            printf("Completed %d %%%c", (int)addr,

                   (addr == 100) ? '\n' : '\r');

            fflush(stdout);

        } else if (!(VAR_5 & BLK_MIG_FLAG_EOS)) {

            fprintf(stderr, "Unknown VAR_5\n");

            return -EINVAL;

        }

        if (qemu_file_has_error(VAR_0)) {

            return -EIO;

        }

    } while (!(VAR_5 & BLK_MIG_FLAG_EOS));



    return 0;

}

static int FUNC_0(QEMUFile *VAR_0, void *VAR_1, int VAR_2)
{ static int VAR_3; int VAR_4, VAR_5; char VAR_6[256]; int64_t addr; BlockDriverState *bs; uint8_t *buf; do { addr = qemu_get_be64(VAR_0); VAR_5 = addr & ~BDRV_SECTOR_MASK; addr >>= BDRV_SECTOR_BITS; if (VAR_5 & BLK_MIG_FLAG_DEVICE_BLOCK) { int VAR_7; VAR_4 = qemu_get_byte(VAR_0); qemu_get_buffer(VAR_0, (uint8_t *)VAR_6, VAR_4); VAR_6[VAR_4] = '\0'; bs = bdrv_find(VAR_6); if (!bs) { fprintf(stderr, "Error unknown block device %s\n",
VAR_6); return -EINVAL; } buf = qemu_malloc(BLOCK_SIZE); qemu_get_buffer(VAR_0, buf, BLOCK_SIZE); VAR_7 = bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK); qemu_free(buf); if (VAR_7 < 0) { return VAR_7; } } else if (VAR_5 & BLK_MIG_FLAG_PROGRESS) { if (!VAR_3) { printf("Receiving block device images\n"); VAR_3 = 1; } printf("Completed %d %%%c", (int)addr,
(addr == 100) ? '\n' : '\r'); fflush(stdout); } else if (!(VAR_5 & BLK_MIG_FLAG_EOS)) { fprintf(stderr, "Unknown VAR_5\n"); return -EINVAL; } if (qemu_file_has_error(VAR_0)) { return -EIO; } } while (!(VAR_5 & BLK_MIG_FLAG_EOS)); return 0; }