static int copy_sectors(BlockDriverState *bs, uint64_t start_sect,

                        uint64_t cluster_offset, int n_start, int n_end)

{

    BDRVQcowState *s = bs->opaque;

    int n, ret;

    void *buf;



    /*

     * If this is the last cluster and it is only partially used, we must only

     * copy until the end of the image, or bdrv_check_request will fail for the

     * bdrv_read/write calls below.

     */

    if (start_sect + n_end > bs->total_sectors) {

        n_end = bs->total_sectors - start_sect;

    }



    n = n_end - n_start;

    if (n <= 0) {

        return 0;

    }



    buf = qemu_blockalign(bs, n * BDRV_SECTOR_SIZE);



    BLKDBG_EVENT(bs->file, BLKDBG_COW_READ);

    ret = bdrv_read(bs, start_sect + n_start, buf, n);

    if (ret < 0) {

        goto out;

    }



    if (s->crypt_method) {

        qcow2_encrypt_sectors(s, start_sect + n_start,

                        buf, buf, n, 1,

                        &s->aes_encrypt_key);

    }



    BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);

    ret = bdrv_write(bs->file, (cluster_offset >> 9) + n_start, buf, n);

    if (ret < 0) {

        goto out;

    }



    ret = 0;

out:

    qemu_vfree(buf);

    return ret;

}

static int copy_sectors(BlockDriverState *bs, uint64_t start_sect,

                        uint64_t cluster_offset, int n_start, int n_end)

{

    BDRVQcowState *s = bs->opaque;

    int n, ret;

    void *buf;



    









    if (start_sect + n_end > bs->total_sectors) {

        n_end = bs->total_sectors - start_sect;

    }



    n = n_end - n_start;

    if (n <= 0) {

        return 0;

    }



    buf = qemu_blockalign(bs, n * BDRV_SECTOR_SIZE);



    BLKDBG_EVENT(bs->file, BLKDBG_COW_READ);

    ret = bdrv_read(bs, start_sect + n_start, buf, n);

    if (ret < 0) {

        goto out;

    }



    if (s->crypt_method) {

        qcow2_encrypt_sectors(s, start_sect + n_start,

                        buf, buf, n, 1,

                        &s->aes_encrypt_key);

    }



    BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);

    ret = bdrv_write(bs->file, (cluster_offset >> 9) + n_start, buf, n);

    if (ret < 0) {

        goto out;

    }



    ret = 0;

out:

    qemu_vfree(buf);

    return ret;

}

static int copy_sectors(BlockDriverState *bs, uint64_t start_sect,                         uint64_t cluster_offset, int n_start, int n_end)     void *buf;     buf = qemu_blockalign(bs, n * BDRV_SECTOR_SIZE);     ret = bdrv_read(bs, start_sect + n_start, buf, n);                         buf, buf, n, 1,     ret = bdrv_write(bs->file, (cluster_offset >> 9) + n_start, buf, n);     qemu_vfree(buf);
static int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,

                        uint64_t VAR_2, int VAR_3, int VAR_4)

{

    BDRVQcowState *s = VAR_0->opaque;

    int VAR_5, VAR_6;

    void *VAR_7;



    









    if (VAR_1 + VAR_4 > VAR_0->total_sectors) {

        VAR_4 = VAR_0->total_sectors - VAR_1;

    }



    VAR_5 = VAR_4 - VAR_3;

    if (VAR_5 <= 0) {

        return 0;

    }



    VAR_7 = qemu_blockalign(VAR_0, VAR_5 * BDRV_SECTOR_SIZE);



    BLKDBG_EVENT(VAR_0->file, BLKDBG_COW_READ);

    VAR_6 = bdrv_read(VAR_0, VAR_1 + VAR_3, VAR_7, VAR_5);

    if (VAR_6 < 0) {

        goto out;

    }



    if (s->crypt_method) {

        qcow2_encrypt_sectors(s, VAR_1 + VAR_3,

                        VAR_7, VAR_7, VAR_5, 1,

                        &s->aes_encrypt_key);

    }



    BLKDBG_EVENT(VAR_0->file, BLKDBG_COW_WRITE);

    VAR_6 = bdrv_write(VAR_0->file, (VAR_2 >> 9) + VAR_3, VAR_7, VAR_5);

    if (VAR_6 < 0) {

        goto out;

    }



    VAR_6 = 0;

out:

    qemu_vfree(VAR_7);

    return VAR_6;

}

static int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,
uint64_t VAR_2, int VAR_3, int VAR_4)
{ BDRVQcowState *s = VAR_0->opaque; int VAR_5, VAR_6; void *VAR_7; if (VAR_1 + VAR_4 > VAR_0->total_sectors) { VAR_4 = VAR_0->total_sectors - VAR_1; } VAR_5 = VAR_4 - VAR_3; if (VAR_5 <= 0) { return 0; } VAR_7 = qemu_blockalign(VAR_0, VAR_5 * BDRV_SECTOR_SIZE); BLKDBG_EVENT(VAR_0->file, BLKDBG_COW_READ); VAR_6 = bdrv_read(VAR_0, VAR_1 + VAR_3, VAR_7, VAR_5); if (VAR_6 < 0) { goto out; } if (s->crypt_method) { qcow2_encrypt_sectors(s, VAR_1 + VAR_3,
VAR_7, VAR_7, VAR_5, 1,
&s->aes_encrypt_key); } BLKDBG_EVENT(VAR_0->file, BLKDBG_COW_WRITE); VAR_6 = bdrv_write(VAR_0->file, (VAR_2 >> 9) + VAR_3, VAR_7, VAR_5); if (VAR_6 < 0) { goto out; } VAR_6 = 0; out:
qemu_vfree(VAR_7); return VAR_6; }