static int qcow2_truncate(BlockDriverState *bs, int64_t offset)

{

    BDRVQcowState *s = bs->opaque;

    int ret, new_l1_size;



    if (offset & 511) {

        return -EINVAL;

    }



    /* cannot proceed if image has snapshots */

    if (s->nb_snapshots) {

        return -ENOTSUP;

    }



    /* shrinking is currently not supported */

    if (offset < bs->total_sectors * 512) {

        return -ENOTSUP;

    }



    new_l1_size = size_to_l1(s, offset);

    ret = qcow2_grow_l1_table(bs, new_l1_size);

    if (ret < 0) {

        return ret;

    }



    /* write updated header.size */

    offset = cpu_to_be64(offset);

    ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, size),

                      &offset, sizeof(uint64_t));

    if (ret < 0) {

        return ret;

    }



    s->l1_vm_state_index = new_l1_size;

    return 0;

}

static int qcow2_truncate(BlockDriverState *bs, int64_t offset)

{

    BDRVQcowState *s = bs->opaque;

    int ret, new_l1_size;



    if (offset & 511) {

        return -EINVAL;

    }



    

    if (s->nb_snapshots) {

        return -ENOTSUP;

    }



    

    if (offset < bs->total_sectors * 512) {

        return -ENOTSUP;

    }



    new_l1_size = size_to_l1(s, offset);

    ret = qcow2_grow_l1_table(bs, new_l1_size);

    if (ret < 0) {

        return ret;

    }



    

    offset = cpu_to_be64(offset);

    ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, size),

                      &offset, sizeof(uint64_t));

    if (ret < 0) {

        return ret;

    }



    s->l1_vm_state_index = new_l1_size;

    return 0;

}

    ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, size),                       &offset, sizeof(uint64_t));
static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1)

{

    BDRVQcowState *s = VAR_0->opaque;

    int VAR_2, VAR_3;



    if (VAR_1 & 511) {

        return -EINVAL;

    }



    

    if (s->nb_snapshots) {

        return -ENOTSUP;

    }



    

    if (VAR_1 < VAR_0->total_sectors * 512) {

        return -ENOTSUP;

    }



    VAR_3 = size_to_l1(s, VAR_1);

    VAR_2 = qcow2_grow_l1_table(VAR_0, VAR_3);

    if (VAR_2 < 0) {

        return VAR_2;

    }



    

    VAR_1 = cpu_to_be64(VAR_1);

    VAR_2 = bdrv_pwrite(VAR_0->file, offsetof(QCowHeader, size),

                      &VAR_1, sizeof(uint64_t));

    if (VAR_2 < 0) {

        return VAR_2;

    }



    s->l1_vm_state_index = VAR_3;

    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1)
{ BDRVQcowState *s = VAR_0->opaque; int VAR_2, VAR_3; if (VAR_1 & 511) { return -EINVAL; } if (s->nb_snapshots) { return -ENOTSUP; } if (VAR_1 < VAR_0->total_sectors * 512) { return -ENOTSUP; } VAR_3 = size_to_l1(s, VAR_1); VAR_2 = qcow2_grow_l1_table(VAR_0, VAR_3); if (VAR_2 < 0) { return VAR_2; } VAR_1 = cpu_to_be64(VAR_1); VAR_2 = bdrv_pwrite(VAR_0->file, offsetof(QCowHeader, size),
&VAR_1, sizeof(uint64_t)); if (VAR_2 < 0) { return VAR_2; } s->l1_vm_state_index = VAR_3; return 0; }