int bdrv_read(BlockDriverState *bs, int64_t sector_num,

              uint8_t *buf, int nb_sectors)

{

    BlockDriver *drv = bs->drv;



    if (!drv)

        return -ENOMEDIUM;



    if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {

            memcpy(buf, bs->boot_sector_data, 512);

        sector_num++;

        nb_sectors--;

        buf += 512;

        if (nb_sectors == 0)

            return 0;

    }

    if (drv->bdrv_pread) {

        int ret, len;

        len = nb_sectors * 512;

        ret = drv->bdrv_pread(bs, sector_num * 512, buf, len);

        if (ret < 0)

            return ret;

        else if (ret != len)

            return -EINVAL;

        else {

	    bs->rd_bytes += (unsigned) len;

	    bs->rd_ops ++;

            return 0;

	}

    } else {

        return drv->bdrv_read(bs, sector_num, buf, nb_sectors);

    }

}

int bdrv_read(BlockDriverState *bs, int64_t sector_num,

              uint8_t *buf, int nb_sectors)

{

    BlockDriver *drv = bs->drv;



    if (!drv)

        return -ENOMEDIUM;



    if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {

            memcpy(buf, bs->boot_sector_data, 512);

        sector_num++;

        nb_sectors--;

        buf += 512;

        if (nb_sectors == 0)

            return 0;

    }

    if (drv->bdrv_pread) {

        int ret, len;

        len = nb_sectors * 512;

        ret = drv->bdrv_pread(bs, sector_num * 512, buf, len);

        if (ret < 0)

            return ret;

        else if (ret != len)

            return -EINVAL;

        else {

	    bs->rd_bytes += (unsigned) len;

	    bs->rd_ops ++;

            return 0;

	}

    } else {

        return drv->bdrv_read(bs, sector_num, buf, nb_sectors);

    }

}

int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1,

              uint8_t *VAR_2, int VAR_3)

{

    BlockDriver *drv = VAR_0->drv;



    if (!drv)

        return -ENOMEDIUM;



    if (VAR_1 == 0 && VAR_0->boot_sector_enabled && VAR_3 > 0) {

            memcpy(VAR_2, VAR_0->boot_sector_data, 512);

        VAR_1++;

        VAR_3--;

        VAR_2 += 512;

        if (VAR_3 == 0)

            return 0;

    }

    if (drv->bdrv_pread) {

        int VAR_4, VAR_5;

        VAR_5 = VAR_3 * 512;

        VAR_4 = drv->bdrv_pread(VAR_0, VAR_1 * 512, VAR_2, VAR_5);

        if (VAR_4 < 0)

            return VAR_4;

        else if (VAR_4 != VAR_5)

            return -EINVAL;

        else {

	    VAR_0->rd_bytes += (unsigned) VAR_5;

	    VAR_0->rd_ops ++;

            return 0;

	}

    } else {

        return drv->FUNC_0(VAR_0, VAR_1, VAR_2, VAR_3);

    }

}

int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1,
uint8_t *VAR_2, int VAR_3)
{ BlockDriver *drv = VAR_0->drv; if (!drv)
return -ENOMEDIUM; if (VAR_1 == 0 && VAR_0->boot_sector_enabled && VAR_3 > 0) { memcpy(VAR_2, VAR_0->boot_sector_data, 512); VAR_1++; VAR_3--; VAR_2 += 512; if (VAR_3 == 0)
return 0; } if (drv->bdrv_pread) { int VAR_4, VAR_5; VAR_5 = VAR_3 * 512; VAR_4 = drv->bdrv_pread(VAR_0, VAR_1 * 512, VAR_2, VAR_5); if (VAR_4 < 0)
return VAR_4; else if (VAR_4 != VAR_5)
return -EINVAL; else { VAR_0->rd_bytes += (unsigned) VAR_5; VAR_0->rd_ops ++; return 0; } } else { return drv->FUNC_0(VAR_0, VAR_1, VAR_2, VAR_3); } }