static int qcow_create2(const char *filename, int64_t total_size,

                        const char *backing_file, const char *backing_format,

                        int flags, size_t cluster_size, int prealloc)

{



    int fd, header_size, backing_filename_len, l1_size, i, shift, l2_bits;

    int ref_clusters, backing_format_len = 0;

    int rounded_ext_bf_len = 0;

    QCowHeader header;

    uint64_t tmp, offset;

    QCowCreateState s1, *s = &s1;

    QCowExtension ext_bf = {0, 0};

    int ret;



    memset(s, 0, sizeof(*s));



    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);

    if (fd < 0)

        return -1;

    memset(&header, 0, sizeof(header));

    header.magic = cpu_to_be32(QCOW_MAGIC);

    header.version = cpu_to_be32(QCOW_VERSION);

    header.size = cpu_to_be64(total_size * 512);

    header_size = sizeof(header);

    backing_filename_len = 0;

    if (backing_file) {

        if (backing_format) {

            ext_bf.magic = QCOW_EXT_MAGIC_BACKING_FORMAT;

            backing_format_len = strlen(backing_format);

            ext_bf.len = backing_format_len;

            rounded_ext_bf_len = (sizeof(ext_bf) + ext_bf.len + 7) & ~7;

            header_size += rounded_ext_bf_len;

        }

        header.backing_file_offset = cpu_to_be64(header_size);

        backing_filename_len = strlen(backing_file);

        header.backing_file_size = cpu_to_be32(backing_filename_len);

        header_size += backing_filename_len;

    }



    /* Cluster size */

    s->cluster_bits = get_bits_from_size(cluster_size);

    if (s->cluster_bits < MIN_CLUSTER_BITS ||

        s->cluster_bits > MAX_CLUSTER_BITS)

    {

        fprintf(stderr, "Cluster size must be a power of two between "

            "%d and %dk\n",

            1 << MIN_CLUSTER_BITS,

            1 << (MAX_CLUSTER_BITS - 10));

        return -EINVAL;

    }

    s->cluster_size = 1 << s->cluster_bits;



    header.cluster_bits = cpu_to_be32(s->cluster_bits);

    header_size = (header_size + 7) & ~7;

    if (flags & BLOCK_FLAG_ENCRYPT) {

        header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES);

    } else {

        header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);

    }

    l2_bits = s->cluster_bits - 3;

    shift = s->cluster_bits + l2_bits;

    l1_size = (((total_size * 512) + (1LL << shift) - 1) >> shift);

    offset = align_offset(header_size, s->cluster_size);

    s->l1_table_offset = offset;

    header.l1_table_offset = cpu_to_be64(s->l1_table_offset);

    header.l1_size = cpu_to_be32(l1_size);

    offset += align_offset(l1_size * sizeof(uint64_t), s->cluster_size);



    s->refcount_table = qemu_mallocz(s->cluster_size);



    s->refcount_table_offset = offset;

    header.refcount_table_offset = cpu_to_be64(offset);

    header.refcount_table_clusters = cpu_to_be32(1);

    offset += s->cluster_size;

    s->refcount_block_offset = offset;



    /* count how many refcount blocks needed */

    tmp = offset >> s->cluster_bits;

    ref_clusters = (tmp >> (s->cluster_bits - REFCOUNT_SHIFT)) + 1;

    for (i=0; i < ref_clusters; i++) {

        s->refcount_table[i] = cpu_to_be64(offset);

        offset += s->cluster_size;

    }



    s->refcount_block = qemu_mallocz(ref_clusters * s->cluster_size);



    /* update refcounts */

    qcow2_create_refcount_update(s, 0, header_size);

    qcow2_create_refcount_update(s, s->l1_table_offset,

        l1_size * sizeof(uint64_t));

    qcow2_create_refcount_update(s, s->refcount_table_offset, s->cluster_size);

    qcow2_create_refcount_update(s, s->refcount_block_offset,

        ref_clusters * s->cluster_size);



    /* write all the data */

    ret = qemu_write_full(fd, &header, sizeof(header));

    if (ret != sizeof(header)) {

        ret = -1;

        goto exit;

    }

    if (backing_file) {

        if (backing_format_len) {

            char zero[16];

            int padding = rounded_ext_bf_len - (ext_bf.len + sizeof(ext_bf));



            memset(zero, 0, sizeof(zero));

            cpu_to_be32s(&ext_bf.magic);

            cpu_to_be32s(&ext_bf.len);

            ret = qemu_write_full(fd, &ext_bf, sizeof(ext_bf));

            if (ret != sizeof(ext_bf)) {

                ret = -1;

                goto exit;

            }

            ret = qemu_write_full(fd, backing_format, backing_format_len);

            if (ret != backing_format_len) {

                ret = -1;

                goto exit;

            }

            if (padding > 0) {

                ret = qemu_write_full(fd, zero, padding);

                if (ret != padding) {

                    ret = -1;

                    goto exit;

                }

            }

        }

        ret = qemu_write_full(fd, backing_file, backing_filename_len);

        if (ret != backing_filename_len) {

            ret = -1;

            goto exit;

        }

    }

    lseek(fd, s->l1_table_offset, SEEK_SET);

    tmp = 0;

    for(i = 0;i < l1_size; i++) {

        ret = qemu_write_full(fd, &tmp, sizeof(tmp));

        if (ret != sizeof(tmp)) {

            ret = -1;

            goto exit;

        }

    }

    lseek(fd, s->refcount_table_offset, SEEK_SET);

    ret = qemu_write_full(fd, s->refcount_table, s->cluster_size);

    if (ret != s->cluster_size) {

        ret = -1;

        goto exit;

    }



    lseek(fd, s->refcount_block_offset, SEEK_SET);

    ret = qemu_write_full(fd, s->refcount_block,

		    ref_clusters * s->cluster_size);

    if (ret != s->cluster_size) {

        ret = -1;

        goto exit;

    }



    ret = 0;

exit:

    qemu_free(s->refcount_table);

    qemu_free(s->refcount_block);

    close(fd);



    /* Preallocate metadata */

    if (prealloc) {

        BlockDriverState *bs;

        bs = bdrv_new("");

        bdrv_open(bs, filename, BDRV_O_CACHE_WB | BDRV_O_RDWR);

        preallocate(bs);

        bdrv_close(bs);

    }



    return ret;

}

static int qcow_create2(const char *filename, int64_t total_size,

                        const char *backing_file, const char *backing_format,

                        int flags, size_t cluster_size, int prealloc)

{



    int fd, header_size, backing_filename_len, l1_size, i, shift, l2_bits;

    int ref_clusters, backing_format_len = 0;

    int rounded_ext_bf_len = 0;

    QCowHeader header;

    uint64_t tmp, offset;

    QCowCreateState s1, *s = &s1;

    QCowExtension ext_bf = {0, 0};

    int ret;



    memset(s, 0, sizeof(*s));



    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);

    if (fd < 0)

        return -1;

    memset(&header, 0, sizeof(header));

    header.magic = cpu_to_be32(QCOW_MAGIC);

    header.version = cpu_to_be32(QCOW_VERSION);

    header.size = cpu_to_be64(total_size * 512);

    header_size = sizeof(header);

    backing_filename_len = 0;

    if (backing_file) {

        if (backing_format) {

            ext_bf.magic = QCOW_EXT_MAGIC_BACKING_FORMAT;

            backing_format_len = strlen(backing_format);

            ext_bf.len = backing_format_len;

            rounded_ext_bf_len = (sizeof(ext_bf) + ext_bf.len + 7) & ~7;

            header_size += rounded_ext_bf_len;

        }

        header.backing_file_offset = cpu_to_be64(header_size);

        backing_filename_len = strlen(backing_file);

        header.backing_file_size = cpu_to_be32(backing_filename_len);

        header_size += backing_filename_len;

    }



    

    s->cluster_bits = get_bits_from_size(cluster_size);

    if (s->cluster_bits < MIN_CLUSTER_BITS ||

        s->cluster_bits > MAX_CLUSTER_BITS)

    {

        fprintf(stderr, "Cluster size must be a power of two between "

            "%d and %dk\n",

            1 << MIN_CLUSTER_BITS,

            1 << (MAX_CLUSTER_BITS - 10));

        return -EINVAL;

    }

    s->cluster_size = 1 << s->cluster_bits;



    header.cluster_bits = cpu_to_be32(s->cluster_bits);

    header_size = (header_size + 7) & ~7;

    if (flags & BLOCK_FLAG_ENCRYPT) {

        header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES);

    } else {

        header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);

    }

    l2_bits = s->cluster_bits - 3;

    shift = s->cluster_bits + l2_bits;

    l1_size = (((total_size * 512) + (1LL << shift) - 1) >> shift);

    offset = align_offset(header_size, s->cluster_size);

    s->l1_table_offset = offset;

    header.l1_table_offset = cpu_to_be64(s->l1_table_offset);

    header.l1_size = cpu_to_be32(l1_size);

    offset += align_offset(l1_size * sizeof(uint64_t), s->cluster_size);



    s->refcount_table = qemu_mallocz(s->cluster_size);



    s->refcount_table_offset = offset;

    header.refcount_table_offset = cpu_to_be64(offset);

    header.refcount_table_clusters = cpu_to_be32(1);

    offset += s->cluster_size;

    s->refcount_block_offset = offset;



    

    tmp = offset >> s->cluster_bits;

    ref_clusters = (tmp >> (s->cluster_bits - REFCOUNT_SHIFT)) + 1;

    for (i=0; i < ref_clusters; i++) {

        s->refcount_table[i] = cpu_to_be64(offset);

        offset += s->cluster_size;

    }



    s->refcount_block = qemu_mallocz(ref_clusters * s->cluster_size);



    

    qcow2_create_refcount_update(s, 0, header_size);

    qcow2_create_refcount_update(s, s->l1_table_offset,

        l1_size * sizeof(uint64_t));

    qcow2_create_refcount_update(s, s->refcount_table_offset, s->cluster_size);

    qcow2_create_refcount_update(s, s->refcount_block_offset,

        ref_clusters * s->cluster_size);



    

    ret = qemu_write_full(fd, &header, sizeof(header));

    if (ret != sizeof(header)) {

        ret = -1;

        goto exit;

    }

    if (backing_file) {

        if (backing_format_len) {

            char zero[16];

            int padding = rounded_ext_bf_len - (ext_bf.len + sizeof(ext_bf));



            memset(zero, 0, sizeof(zero));

            cpu_to_be32s(&ext_bf.magic);

            cpu_to_be32s(&ext_bf.len);

            ret = qemu_write_full(fd, &ext_bf, sizeof(ext_bf));

            if (ret != sizeof(ext_bf)) {

                ret = -1;

                goto exit;

            }

            ret = qemu_write_full(fd, backing_format, backing_format_len);

            if (ret != backing_format_len) {

                ret = -1;

                goto exit;

            }

            if (padding > 0) {

                ret = qemu_write_full(fd, zero, padding);

                if (ret != padding) {

                    ret = -1;

                    goto exit;

                }

            }

        }

        ret = qemu_write_full(fd, backing_file, backing_filename_len);

        if (ret != backing_filename_len) {

            ret = -1;

            goto exit;

        }

    }

    lseek(fd, s->l1_table_offset, SEEK_SET);

    tmp = 0;

    for(i = 0;i < l1_size; i++) {

        ret = qemu_write_full(fd, &tmp, sizeof(tmp));

        if (ret != sizeof(tmp)) {

            ret = -1;

            goto exit;

        }

    }

    lseek(fd, s->refcount_table_offset, SEEK_SET);

    ret = qemu_write_full(fd, s->refcount_table, s->cluster_size);

    if (ret != s->cluster_size) {

        ret = -1;

        goto exit;

    }



    lseek(fd, s->refcount_block_offset, SEEK_SET);

    ret = qemu_write_full(fd, s->refcount_block,

		    ref_clusters * s->cluster_size);

    if (ret != s->cluster_size) {

        ret = -1;

        goto exit;

    }



    ret = 0;

exit:

    qemu_free(s->refcount_table);

    qemu_free(s->refcount_block);

    close(fd);



    

    if (prealloc) {

        BlockDriverState *bs;

        bs = bdrv_new("");

        bdrv_open(bs, filename, BDRV_O_CACHE_WB | BDRV_O_RDWR);

        preallocate(bs);

        bdrv_close(bs);

    }



    return ret;

}

    if (ret != s->cluster_size) {     if (prealloc) {
static int FUNC_0(const char *VAR_0, int64_t VAR_1,

                        const char *VAR_2, const char *VAR_3,

                        int VAR_4, size_t VAR_5, int VAR_6)

{



    int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13;

    int VAR_14, VAR_15 = 0;

    int VAR_16 = 0;

    QCowHeader header;

    uint64_t tmp, offset;

    QCowCreateState s1, *s = &s1;

    QCowExtension ext_bf = {0, 0};

    int VAR_17;



    memset(s, 0, sizeof(*s));



    VAR_7 = open(VAR_0, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);

    if (VAR_7 < 0)

        return -1;

    memset(&header, 0, sizeof(header));

    header.magic = cpu_to_be32(QCOW_MAGIC);

    header.version = cpu_to_be32(QCOW_VERSION);

    header.size = cpu_to_be64(VAR_1 * 512);

    VAR_8 = sizeof(header);

    VAR_9 = 0;

    if (VAR_2) {

        if (VAR_3) {

            ext_bf.magic = QCOW_EXT_MAGIC_BACKING_FORMAT;

            VAR_15 = strlen(VAR_3);

            ext_bf.len = VAR_15;

            VAR_16 = (sizeof(ext_bf) + ext_bf.len + 7) & ~7;

            VAR_8 += VAR_16;

        }

        header.backing_file_offset = cpu_to_be64(VAR_8);

        VAR_9 = strlen(VAR_2);

        header.backing_file_size = cpu_to_be32(VAR_9);

        VAR_8 += VAR_9;

    }



    

    s->cluster_bits = get_bits_from_size(VAR_5);

    if (s->cluster_bits < MIN_CLUSTER_BITS ||

        s->cluster_bits > MAX_CLUSTER_BITS)

    {

        fprintf(stderr, "Cluster size must be a power of two between "

            "%d and %dk\n",

            1 << MIN_CLUSTER_BITS,

            1 << (MAX_CLUSTER_BITS - 10));

        return -EINVAL;

    }

    s->VAR_5 = 1 << s->cluster_bits;



    header.cluster_bits = cpu_to_be32(s->cluster_bits);

    VAR_8 = (VAR_8 + 7) & ~7;

    if (VAR_4 & BLOCK_FLAG_ENCRYPT) {

        header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES);

    } else {

        header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);

    }

    VAR_13 = s->cluster_bits - 3;

    VAR_12 = s->cluster_bits + VAR_13;

    VAR_10 = (((VAR_1 * 512) + (1LL << VAR_12) - 1) >> VAR_12);

    offset = align_offset(VAR_8, s->VAR_5);

    s->l1_table_offset = offset;

    header.l1_table_offset = cpu_to_be64(s->l1_table_offset);

    header.VAR_10 = cpu_to_be32(VAR_10);

    offset += align_offset(VAR_10 * sizeof(uint64_t), s->VAR_5);



    s->refcount_table = qemu_mallocz(s->VAR_5);



    s->refcount_table_offset = offset;

    header.refcount_table_offset = cpu_to_be64(offset);

    header.refcount_table_clusters = cpu_to_be32(1);

    offset += s->VAR_5;

    s->refcount_block_offset = offset;



    

    tmp = offset >> s->cluster_bits;

    VAR_14 = (tmp >> (s->cluster_bits - REFCOUNT_SHIFT)) + 1;

    for (VAR_11=0; VAR_11 < VAR_14; VAR_11++) {

        s->refcount_table[VAR_11] = cpu_to_be64(offset);

        offset += s->VAR_5;

    }



    s->refcount_block = qemu_mallocz(VAR_14 * s->VAR_5);



    

    qcow2_create_refcount_update(s, 0, VAR_8);

    qcow2_create_refcount_update(s, s->l1_table_offset,

        VAR_10 * sizeof(uint64_t));

    qcow2_create_refcount_update(s, s->refcount_table_offset, s->VAR_5);

    qcow2_create_refcount_update(s, s->refcount_block_offset,

        VAR_14 * s->VAR_5);



    

    VAR_17 = qemu_write_full(VAR_7, &header, sizeof(header));

    if (VAR_17 != sizeof(header)) {

        VAR_17 = -1;

        goto exit;

    }

    if (VAR_2) {

        if (VAR_15) {

            char VAR_18[16];

            int VAR_19 = VAR_16 - (ext_bf.len + sizeof(ext_bf));



            memset(VAR_18, 0, sizeof(VAR_18));

            cpu_to_be32s(&ext_bf.magic);

            cpu_to_be32s(&ext_bf.len);

            VAR_17 = qemu_write_full(VAR_7, &ext_bf, sizeof(ext_bf));

            if (VAR_17 != sizeof(ext_bf)) {

                VAR_17 = -1;

                goto exit;

            }

            VAR_17 = qemu_write_full(VAR_7, VAR_3, VAR_15);

            if (VAR_17 != VAR_15) {

                VAR_17 = -1;

                goto exit;

            }

            if (VAR_19 > 0) {

                VAR_17 = qemu_write_full(VAR_7, VAR_18, VAR_19);

                if (VAR_17 != VAR_19) {

                    VAR_17 = -1;

                    goto exit;

                }

            }

        }

        VAR_17 = qemu_write_full(VAR_7, VAR_2, VAR_9);

        if (VAR_17 != VAR_9) {

            VAR_17 = -1;

            goto exit;

        }

    }

    lseek(VAR_7, s->l1_table_offset, SEEK_SET);

    tmp = 0;

    for(VAR_11 = 0;VAR_11 < VAR_10; VAR_11++) {

        VAR_17 = qemu_write_full(VAR_7, &tmp, sizeof(tmp));

        if (VAR_17 != sizeof(tmp)) {

            VAR_17 = -1;

            goto exit;

        }

    }

    lseek(VAR_7, s->refcount_table_offset, SEEK_SET);

    VAR_17 = qemu_write_full(VAR_7, s->refcount_table, s->VAR_5);

    if (VAR_17 != s->VAR_5) {

        VAR_17 = -1;

        goto exit;

    }



    lseek(VAR_7, s->refcount_block_offset, SEEK_SET);

    VAR_17 = qemu_write_full(VAR_7, s->refcount_block,

		    VAR_14 * s->VAR_5);

    if (VAR_17 != s->VAR_5) {

        VAR_17 = -1;

        goto exit;

    }



    VAR_17 = 0;

exit:

    qemu_free(s->refcount_table);

    qemu_free(s->refcount_block);

    close(VAR_7);



    

    if (VAR_6) {

        BlockDriverState *bs;

        bs = bdrv_new("");

        bdrv_open(bs, VAR_0, BDRV_O_CACHE_WB | BDRV_O_RDWR);

        preallocate(bs);

        bdrv_close(bs);

    }



    return VAR_17;

}

static int FUNC_0(const char *VAR_0, int64_t VAR_1,
const char *VAR_2, const char *VAR_3,
int VAR_4, size_t VAR_5, int VAR_6)
{ int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13; int VAR_14, VAR_15 = 0; int VAR_16 = 0; QCowHeader header; uint64_t tmp, offset; QCowCreateState s1, *s = &s1; QCowExtension ext_bf = {0, 0}; int VAR_17; memset(s, 0, sizeof(*s)); VAR_7 = open(VAR_0, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); if (VAR_7 < 0)
return -1; memset(&header, 0, sizeof(header)); header.magic = cpu_to_be32(QCOW_MAGIC); header.version = cpu_to_be32(QCOW_VERSION); header.size = cpu_to_be64(VAR_1 * 512); VAR_8 = sizeof(header); VAR_9 = 0; if (VAR_2) { if (VAR_3) { ext_bf.magic = QCOW_EXT_MAGIC_BACKING_FORMAT; VAR_15 = strlen(VAR_3); ext_bf.len = VAR_15; VAR_16 = (sizeof(ext_bf) + ext_bf.len + 7) & ~7; VAR_8 += VAR_16; } header.backing_file_offset = cpu_to_be64(VAR_8); VAR_9 = strlen(VAR_2); header.backing_file_size = cpu_to_be32(VAR_9); VAR_8 += VAR_9; } s->cluster_bits = get_bits_from_size(VAR_5); if (s->cluster_bits < MIN_CLUSTER_BITS ||
s->cluster_bits > MAX_CLUSTER_BITS)
{ fprintf(stderr, "Cluster size must be a power of two between "
"%d and %dk\n",
1 << MIN_CLUSTER_BITS,
1 << (MAX_CLUSTER_BITS - 10)); return -EINVAL; } s->VAR_5 = 1 << s->cluster_bits; header.cluster_bits = cpu_to_be32(s->cluster_bits); VAR_8 = (VAR_8 + 7) & ~7; if (VAR_4 & BLOCK_FLAG_ENCRYPT) { header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES); } else { header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE); } VAR_13 = s->cluster_bits - 3; VAR_12 = s->cluster_bits + VAR_13; VAR_10 = (((VAR_1 * 512) + (1LL << VAR_12) - 1) >> VAR_12); offset = align_offset(VAR_8, s->VAR_5); s->l1_table_offset = offset; header.l1_table_offset = cpu_to_be64(s->l1_table_offset); header.VAR_10 = cpu_to_be32(VAR_10); offset += align_offset(VAR_10 * sizeof(uint64_t), s->VAR_5); s->refcount_table = qemu_mallocz(s->VAR_5); s->refcount_table_offset = offset; header.refcount_table_offset = cpu_to_be64(offset); header.refcount_table_clusters = cpu_to_be32(1); offset += s->VAR_5; s->refcount_block_offset = offset; tmp = offset >> s->cluster_bits; VAR_14 = (tmp >> (s->cluster_bits - REFCOUNT_SHIFT)) + 1; for (VAR_11=0; VAR_11 < VAR_14; VAR_11++) { s->refcount_table[VAR_11] = cpu_to_be64(offset); offset += s->VAR_5; } s->refcount_block = qemu_mallocz(VAR_14 * s->VAR_5); qcow2_create_refcount_update(s, 0, VAR_8); qcow2_create_refcount_update(s, s->l1_table_offset,
VAR_10 * sizeof(uint64_t)); qcow2_create_refcount_update(s, s->refcount_table_offset, s->VAR_5); qcow2_create_refcount_update(s, s->refcount_block_offset,
VAR_14 * s->VAR_5); VAR_17 = qemu_write_full(VAR_7, &header, sizeof(header)); if (VAR_17 != sizeof(header)) { VAR_17 = -1; goto exit; } if (VAR_2) { if (VAR_15) { char VAR_18[16]; int VAR_19 = VAR_16 - (ext_bf.len + sizeof(ext_bf)); memset(VAR_18, 0, sizeof(VAR_18)); cpu_to_be32s(&ext_bf.magic); cpu_to_be32s(&ext_bf.len); VAR_17 = qemu_write_full(VAR_7, &ext_bf, sizeof(ext_bf)); if (VAR_17 != sizeof(ext_bf)) { VAR_17 = -1; goto exit; } VAR_17 = qemu_write_full(VAR_7, VAR_3, VAR_15); if (VAR_17 != VAR_15) { VAR_17 = -1; goto exit; } if (VAR_19 > 0) { VAR_17 = qemu_write_full(VAR_7, VAR_18, VAR_19); if (VAR_17 != VAR_19) { VAR_17 = -1; goto exit; } } } VAR_17 = qemu_write_full(VAR_7, VAR_2, VAR_9); if (VAR_17 != VAR_9) { VAR_17 = -1; goto exit; } } lseek(VAR_7, s->l1_table_offset, SEEK_SET); tmp = 0; for(VAR_11 = 0;VAR_11 < VAR_10; VAR_11++) { VAR_17 = qemu_write_full(VAR_7, &tmp, sizeof(tmp)); if (VAR_17 != sizeof(tmp)) { VAR_17 = -1; goto exit; } } lseek(VAR_7, s->refcount_table_offset, SEEK_SET); VAR_17 = qemu_write_full(VAR_7, s->refcount_table, s->VAR_5); if (VAR_17 != s->VAR_5) { VAR_17 = -1; goto exit; } lseek(VAR_7, s->refcount_block_offset, SEEK_SET); VAR_17 = qemu_write_full(VAR_7, s->refcount_block,
VAR_14 * s->VAR_5); if (VAR_17 != s->VAR_5) { VAR_17 = -1; goto exit; } VAR_17 = 0; exit:
qemu_free(s->refcount_table); qemu_free(s->refcount_block); close(VAR_7); if (VAR_6) { BlockDriverState *bs; bs = bdrv_new(""); bdrv_open(bs, VAR_0, BDRV_O_CACHE_WB | BDRV_O_RDWR); preallocate(bs); bdrv_close(bs); } return VAR_17; }