int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,

                       uint64_t *refcount)

{

    BDRVQcowState *s = bs->opaque;

    uint64_t refcount_table_index, block_index;

    int64_t refcount_block_offset;

    int ret;

    void *refcount_block;



    refcount_table_index = cluster_index >> s->refcount_block_bits;

    if (refcount_table_index >= s->refcount_table_size) {

        *refcount = 0;

        return 0;

    }

    refcount_block_offset =

        s->refcount_table[refcount_table_index] & REFT_OFFSET_MASK;

    if (!refcount_block_offset) {

        *refcount = 0;

        return 0;

    }



    if (offset_into_cluster(s, refcount_block_offset)) {

        qcow2_signal_corruption(bs, true, -1, -1, "Refblock offset %#" PRIx64

                                " unaligned (reftable index: %#" PRIx64 ")",

                                refcount_block_offset, refcount_table_index);

        return -EIO;

    }



    ret = qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_offset,

                          &refcount_block);

    if (ret < 0) {

        return ret;

    }



    block_index = cluster_index & (s->refcount_block_size - 1);

    *refcount = s->get_refcount(refcount_block, block_index);



    ret = qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block);

    if (ret < 0) {

        return ret;

    }



    return 0;

}

int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,

                       uint64_t *refcount)

{

    BDRVQcowState *s = bs->opaque;

    uint64_t refcount_table_index, block_index;

    int64_t refcount_block_offset;

    int ret;

    void *refcount_block;



    refcount_table_index = cluster_index >> s->refcount_block_bits;

    if (refcount_table_index >= s->refcount_table_size) {

        *refcount = 0;

        return 0;

    }

    refcount_block_offset =

        s->refcount_table[refcount_table_index] & REFT_OFFSET_MASK;

    if (!refcount_block_offset) {

        *refcount = 0;

        return 0;

    }



    if (offset_into_cluster(s, refcount_block_offset)) {

        qcow2_signal_corruption(bs, true, -1, -1, "Refblock offset %#" PRIx64

                                " unaligned (reftable index: %#" PRIx64 ")",

                                refcount_block_offset, refcount_table_index);

        return -EIO;

    }



    ret = qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_offset,

                          &refcount_block);

    if (ret < 0) {

        return ret;

    }



    block_index = cluster_index & (s->refcount_block_size - 1);

    *refcount = s->get_refcount(refcount_block, block_index);



    ret = qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block);

    if (ret < 0) {

        return ret;

    }



    return 0;

}

int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1,

                       uint64_t *VAR_2)

{

    BDRVQcowState *s = VAR_0->opaque;

    uint64_t refcount_table_index, block_index;

    int64_t refcount_block_offset;

    int VAR_3;

    void *VAR_4;



    refcount_table_index = VAR_1 >> s->refcount_block_bits;

    if (refcount_table_index >= s->refcount_table_size) {

        *VAR_2 = 0;

        return 0;

    }

    refcount_block_offset =

        s->refcount_table[refcount_table_index] & REFT_OFFSET_MASK;

    if (!refcount_block_offset) {

        *VAR_2 = 0;

        return 0;

    }



    if (offset_into_cluster(s, refcount_block_offset)) {

        qcow2_signal_corruption(VAR_0, true, -1, -1, "Refblock offset %#" PRIx64

                                " unaligned (reftable index: %#" PRIx64 ")",

                                refcount_block_offset, refcount_table_index);

        return -EIO;

    }



    VAR_3 = qcow2_cache_get(VAR_0, s->refcount_block_cache, refcount_block_offset,

                          &VAR_4);

    if (VAR_3 < 0) {

        return VAR_3;

    }



    block_index = VAR_1 & (s->refcount_block_size - 1);

    *VAR_2 = s->get_refcount(VAR_4, block_index);



    VAR_3 = qcow2_cache_put(VAR_0, s->refcount_block_cache, &VAR_4);

    if (VAR_3 < 0) {

        return VAR_3;

    }



    return 0;

}

int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1,
uint64_t *VAR_2)
{ BDRVQcowState *s = VAR_0->opaque; uint64_t refcount_table_index, block_index; int64_t refcount_block_offset; int VAR_3; void *VAR_4; refcount_table_index = VAR_1 >> s->refcount_block_bits; if (refcount_table_index >= s->refcount_table_size) { *VAR_2 = 0; return 0; } refcount_block_offset =
s->refcount_table[refcount_table_index] & REFT_OFFSET_MASK; if (!refcount_block_offset) { *VAR_2 = 0; return 0; } if (offset_into_cluster(s, refcount_block_offset)) { qcow2_signal_corruption(VAR_0, true, -1, -1, "Refblock offset %#" PRIx64
" unaligned (reftable index: %#" PRIx64 ")",
refcount_block_offset, refcount_table_index); return -EIO; } VAR_3 = qcow2_cache_get(VAR_0, s->refcount_block_cache, refcount_block_offset,
&VAR_4); if (VAR_3 < 0) { return VAR_3; } block_index = VAR_1 & (s->refcount_block_size - 1); *VAR_2 = s->get_refcount(VAR_4, block_index); VAR_3 = qcow2_cache_put(VAR_0, s->refcount_block_cache, &VAR_4); if (VAR_3 < 0) { return VAR_3; } return 0; }