static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,

                               BdrvCheckMode fix, uint16_t **refcount_table,

                               int64_t *nb_clusters)

{

    BDRVQcowState *s = bs->opaque;

    int64_t i;

    QCowSnapshot *sn;

    int ret;



    if (!*refcount_table) {

        *refcount_table = g_try_new0(uint16_t, *nb_clusters);

        if (*nb_clusters && *refcount_table == NULL) {

            res->check_errors++;

            return -ENOMEM;

        }

    }



    /* header */

    ret = inc_refcounts(bs, res, refcount_table, nb_clusters,

                        0, s->cluster_size);

    if (ret < 0) {

        return ret;

    }



    /* current L1 table */

    ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters,

                             s->l1_table_offset, s->l1_size, CHECK_FRAG_INFO);

    if (ret < 0) {

        return ret;

    }



    /* snapshots */

    for (i = 0; i < s->nb_snapshots; i++) {

        sn = s->snapshots + i;

        ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters,

                                 sn->l1_table_offset, sn->l1_size, 0);

        if (ret < 0) {

            return ret;

        }

    }

    ret = inc_refcounts(bs, res, refcount_table, nb_clusters,

                        s->snapshots_offset, s->snapshots_size);

    if (ret < 0) {

        return ret;

    }



    /* refcount data */

    ret = inc_refcounts(bs, res, refcount_table, nb_clusters,

                        s->refcount_table_offset,

                        s->refcount_table_size * sizeof(uint64_t));

    if (ret < 0) {

        return ret;

    }



    return check_refblocks(bs, res, fix, refcount_table, nb_clusters);

}

static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,

                               BdrvCheckMode fix, uint16_t **refcount_table,

                               int64_t *nb_clusters)

{

    BDRVQcowState *s = bs->opaque;

    int64_t i;

    QCowSnapshot *sn;

    int ret;



    if (!*refcount_table) {

        *refcount_table = g_try_new0(uint16_t, *nb_clusters);

        if (*nb_clusters && *refcount_table == NULL) {

            res->check_errors++;

            return -ENOMEM;

        }

    }



    

    ret = inc_refcounts(bs, res, refcount_table, nb_clusters,

                        0, s->cluster_size);

    if (ret < 0) {

        return ret;

    }



    

    ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters,

                             s->l1_table_offset, s->l1_size, CHECK_FRAG_INFO);

    if (ret < 0) {

        return ret;

    }



    

    for (i = 0; i < s->nb_snapshots; i++) {

        sn = s->snapshots + i;

        ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters,

                                 sn->l1_table_offset, sn->l1_size, 0);

        if (ret < 0) {

            return ret;

        }

    }

    ret = inc_refcounts(bs, res, refcount_table, nb_clusters,

                        s->snapshots_offset, s->snapshots_size);

    if (ret < 0) {

        return ret;

    }



    

    ret = inc_refcounts(bs, res, refcount_table, nb_clusters,

                        s->refcount_table_offset,

                        s->refcount_table_size * sizeof(uint64_t));

    if (ret < 0) {

        return ret;

    }



    return check_refblocks(bs, res, fix, refcount_table, nb_clusters);

}

    BDRVQcowState *s = bs->opaque;     if (ret < 0) {         return ret;     if (ret < 0) {         return ret;     BDRVQcowState *s = bs->opaque;     int ret;     if (ret < 0) {     if (ret < 0) {     if (ret < 0) {     if (ret < 0) {     if (ret < 0) {         return ret;                                BdrvCheckMode fix, uint16_t **refcount_table,                                int64_t *nb_clusters)     return check_refblocks(bs, res, fix, refcount_table, nb_clusters);
static int FUNC_0(BlockDriverState *VAR_0, BdrvCheckResult *VAR_1,

                               BdrvCheckMode VAR_2, uint16_t **VAR_3,

                               int64_t *VAR_4)

{

    BDRVQcowState *s = VAR_0->opaque;

    int64_t i;

    QCowSnapshot *sn;

    int VAR_5;



    if (!*VAR_3) {

        *VAR_3 = g_try_new0(uint16_t, *VAR_4);

        if (*VAR_4 && *VAR_3 == NULL) {

            VAR_1->check_errors++;

            return -ENOMEM;

        }

    }



    

    VAR_5 = inc_refcounts(VAR_0, VAR_1, VAR_3, VAR_4,

                        0, s->cluster_size);

    if (VAR_5 < 0) {

        return VAR_5;

    }



    

    VAR_5 = check_refcounts_l1(VAR_0, VAR_1, VAR_3, VAR_4,

                             s->l1_table_offset, s->l1_size, CHECK_FRAG_INFO);

    if (VAR_5 < 0) {

        return VAR_5;

    }



    

    for (i = 0; i < s->nb_snapshots; i++) {

        sn = s->snapshots + i;

        VAR_5 = check_refcounts_l1(VAR_0, VAR_1, VAR_3, VAR_4,

                                 sn->l1_table_offset, sn->l1_size, 0);

        if (VAR_5 < 0) {

            return VAR_5;

        }

    }

    VAR_5 = inc_refcounts(VAR_0, VAR_1, VAR_3, VAR_4,

                        s->snapshots_offset, s->snapshots_size);

    if (VAR_5 < 0) {

        return VAR_5;

    }



    

    VAR_5 = inc_refcounts(VAR_0, VAR_1, VAR_3, VAR_4,

                        s->refcount_table_offset,

                        s->refcount_table_size * sizeof(uint64_t));

    if (VAR_5 < 0) {

        return VAR_5;

    }



    return check_refblocks(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4);

}

static int FUNC_0(BlockDriverState *VAR_0, BdrvCheckResult *VAR_1,
BdrvCheckMode VAR_2, uint16_t **VAR_3,
int64_t *VAR_4)
{ BDRVQcowState *s = VAR_0->opaque; int64_t i; QCowSnapshot *sn; int VAR_5; if (!*VAR_3) { *VAR_3 = g_try_new0(uint16_t, *VAR_4); if (*VAR_4 && *VAR_3 == NULL) { VAR_1->check_errors++; return -ENOMEM; } } VAR_5 = inc_refcounts(VAR_0, VAR_1, VAR_3, VAR_4,
0, s->cluster_size); if (VAR_5 < 0) { return VAR_5; } VAR_5 = check_refcounts_l1(VAR_0, VAR_1, VAR_3, VAR_4,
s->l1_table_offset, s->l1_size, CHECK_FRAG_INFO); if (VAR_5 < 0) { return VAR_5; } for (i = 0; i < s->nb_snapshots; i++) { sn = s->snapshots + i; VAR_5 = check_refcounts_l1(VAR_0, VAR_1, VAR_3, VAR_4,
sn->l1_table_offset, sn->l1_size, 0); if (VAR_5 < 0) { return VAR_5; } } VAR_5 = inc_refcounts(VAR_0, VAR_1, VAR_3, VAR_4,
s->snapshots_offset, s->snapshots_size); if (VAR_5 < 0) { return VAR_5; } VAR_5 = inc_refcounts(VAR_0, VAR_1, VAR_3, VAR_4,
s->refcount_table_offset,
s->refcount_table_size * sizeof(uint64_t)); if (VAR_5 < 0) { return VAR_5; } return check_refblocks(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4); }