int bdrv_truncate(BlockDriverState *bs, int64_t offset)

{

    BlockDriver *drv = bs->drv;

    int ret;

    if (!drv)

        return -ENOMEDIUM;

    if (!drv->bdrv_truncate)

        return -ENOTSUP;

    if (bs->read_only)

        return -EACCES;



    ret = drv->bdrv_truncate(bs, offset);

    if (ret == 0) {

        ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);

        bdrv_dirty_bitmap_truncate(bs);

        if (bs->blk) {

            blk_dev_resize_cb(bs->blk);

        }

    }

    return ret;

}

int bdrv_truncate(BlockDriverState *bs, int64_t offset)

{

    BlockDriver *drv = bs->drv;

    int ret;

    if (!drv)

        return -ENOMEDIUM;

    if (!drv->bdrv_truncate)

        return -ENOTSUP;

    if (bs->read_only)

        return -EACCES;



    ret = drv->bdrv_truncate(bs, offset);

    if (ret == 0) {

        ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);

        bdrv_dirty_bitmap_truncate(bs);

        if (bs->blk) {

            blk_dev_resize_cb(bs->blk);

        }

    }

    return ret;

}

int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1)

{

    BlockDriver *drv = VAR_0->drv;

    int VAR_2;

    if (!drv)

        return -ENOMEDIUM;

    if (!drv->FUNC_0)

        return -ENOTSUP;

    if (VAR_0->read_only)

        return -EACCES;



    VAR_2 = drv->FUNC_0(VAR_0, VAR_1);

    if (VAR_2 == 0) {

        VAR_2 = refresh_total_sectors(VAR_0, VAR_1 >> BDRV_SECTOR_BITS);

        bdrv_dirty_bitmap_truncate(VAR_0);

        if (VAR_0->blk) {

            blk_dev_resize_cb(VAR_0->blk);

        }

    }

    return VAR_2;

}

int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1)
{ BlockDriver *drv = VAR_0->drv; int VAR_2; if (!drv)
return -ENOMEDIUM; if (!drv->FUNC_0)
return -ENOTSUP; if (VAR_0->read_only)
return -EACCES; VAR_2 = drv->FUNC_0(VAR_0, VAR_1); if (VAR_2 == 0) { VAR_2 = refresh_total_sectors(VAR_0, VAR_1 >> BDRV_SECTOR_BITS); bdrv_dirty_bitmap_truncate(VAR_0); if (VAR_0->blk) { blk_dev_resize_cb(VAR_0->blk); } } return VAR_2; }