static int cow_read(BlockDriverState *bs, int64_t sector_num,

                    uint8_t *buf, int nb_sectors)

{

    BDRVCowState *s = bs->opaque;

    int ret, n;



    while (nb_sectors > 0) {

        if (cow_is_allocated(bs, sector_num, nb_sectors, &n)) {

            ret = bdrv_pread(bs->file,

                        s->cow_sectors_offset + sector_num * 512,

                        buf, n * 512);

            if (ret != n * 512)

                return -1;

        } else {

            if (bs->backing_hd) {

                /* read from the base image */

                ret = bdrv_read(bs->backing_hd, sector_num, buf, n);

                if (ret < 0)

                    return -1;

            } else {

            memset(buf, 0, n * 512);

        }

        }

        nb_sectors -= n;

        sector_num += n;

        buf += n * 512;

    }

    return 0;

}

static int cow_read(BlockDriverState *bs, int64_t sector_num,

                    uint8_t *buf, int nb_sectors)

{

    BDRVCowState *s = bs->opaque;

    int ret, n;



    while (nb_sectors > 0) {

        if (cow_is_allocated(bs, sector_num, nb_sectors, &n)) {

            ret = bdrv_pread(bs->file,

                        s->cow_sectors_offset + sector_num * 512,

                        buf, n * 512);

            if (ret != n * 512)

                return -1;

        } else {

            if (bs->backing_hd) {

                

                ret = bdrv_read(bs->backing_hd, sector_num, buf, n);

                if (ret < 0)

                    return -1;

            } else {

            memset(buf, 0, n * 512);

        }

        }

        nb_sectors -= n;

        sector_num += n;

        buf += n * 512;

    }

    return 0;

}

        if (cow_is_allocated(bs, sector_num, nb_sectors, &n)) {
static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1,

                    uint8_t *VAR_2, int VAR_3)

{

    BDRVCowState *s = VAR_0->opaque;

    int VAR_4, VAR_5;



    while (VAR_3 > 0) {

        if (cow_is_allocated(VAR_0, VAR_1, VAR_3, &VAR_5)) {

            VAR_4 = bdrv_pread(VAR_0->file,

                        s->cow_sectors_offset + VAR_1 * 512,

                        VAR_2, VAR_5 * 512);

            if (VAR_4 != VAR_5 * 512)

                return -1;

        } else {

            if (VAR_0->backing_hd) {

                

                VAR_4 = bdrv_read(VAR_0->backing_hd, VAR_1, VAR_2, VAR_5);

                if (VAR_4 < 0)

                    return -1;

            } else {

            memset(VAR_2, 0, VAR_5 * 512);

        }

        }

        VAR_3 -= VAR_5;

        VAR_1 += VAR_5;

        VAR_2 += VAR_5 * 512;

    }

    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1,
uint8_t *VAR_2, int VAR_3)
{ BDRVCowState *s = VAR_0->opaque; int VAR_4, VAR_5; while (VAR_3 > 0) { if (cow_is_allocated(VAR_0, VAR_1, VAR_3, &VAR_5)) { VAR_4 = bdrv_pread(VAR_0->file,
s->cow_sectors_offset + VAR_1 * 512,
VAR_2, VAR_5 * 512); if (VAR_4 != VAR_5 * 512)
return -1; } else { if (VAR_0->backing_hd) { VAR_4 = bdrv_read(VAR_0->backing_hd, VAR_1, VAR_2, VAR_5); if (VAR_4 < 0)
return -1; } else { memset(VAR_2, 0, VAR_5 * 512); } } VAR_3 -= VAR_5; VAR_1 += VAR_5; VAR_2 += VAR_5 * 512; } return 0; }