static void compare_refcounts(BlockDriverState *bs, BdrvCheckResult *res,

                              BdrvCheckMode fix, bool *rebuild,

                              int64_t *highest_cluster,

                              uint16_t *refcount_table, int64_t nb_clusters)

{

    BDRVQcowState *s = bs->opaque;

    int64_t i;

    uint64_t refcount1, refcount2;

    int ret;



    for (i = 0, *highest_cluster = 0; i < nb_clusters; i++) {

        ret = qcow2_get_refcount(bs, i, &refcount1);

        if (ret < 0) {

            fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": %s\n",

                    i, strerror(-ret));

            res->check_errors++;

            continue;

        }



        refcount2 = refcount_table[i];



        if (refcount1 > 0 || refcount2 > 0) {

            *highest_cluster = i;

        }



        if (refcount1 != refcount2) {

            /* Check if we're allowed to fix the mismatch */

            int *num_fixed = NULL;

            if (refcount1 == 0) {

                *rebuild = true;

            } else if (refcount1 > refcount2 && (fix & BDRV_FIX_LEAKS)) {

                num_fixed = &res->leaks_fixed;

            } else if (refcount1 < refcount2 && (fix & BDRV_FIX_ERRORS)) {

                num_fixed = &res->corruptions_fixed;

            }



            fprintf(stderr, "%s cluster %" PRId64 " refcount=%" PRIu64

                    " reference=%" PRIu64 "\n",

                   num_fixed != NULL     ? "Repairing" :

                   refcount1 < refcount2 ? "ERROR" :

                                           "Leaked",

                   i, refcount1, refcount2);



            if (num_fixed) {

                ret = update_refcount(bs, i << s->cluster_bits, 1,

                                      refcount_diff(refcount1, refcount2),

                                      refcount1 > refcount2,

                                      QCOW2_DISCARD_ALWAYS);

                if (ret >= 0) {

                    (*num_fixed)++;

                    continue;

                }

            }



            /* And if we couldn't, print an error */

            if (refcount1 < refcount2) {

                res->corruptions++;

            } else {

                res->leaks++;

            }

        }

    }

}

static void compare_refcounts(BlockDriverState *bs, BdrvCheckResult *res,

                              BdrvCheckMode fix, bool *rebuild,

                              int64_t *highest_cluster,

                              uint16_t *refcount_table, int64_t nb_clusters)

{

    BDRVQcowState *s = bs->opaque;

    int64_t i;

    uint64_t refcount1, refcount2;

    int ret;



    for (i = 0, *highest_cluster = 0; i < nb_clusters; i++) {

        ret = qcow2_get_refcount(bs, i, &refcount1);

        if (ret < 0) {

            fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": %s\n",

                    i, strerror(-ret));

            res->check_errors++;

            continue;

        }



        refcount2 = refcount_table[i];



        if (refcount1 > 0 || refcount2 > 0) {

            *highest_cluster = i;

        }



        if (refcount1 != refcount2) {

            

            int *num_fixed = NULL;

            if (refcount1 == 0) {

                *rebuild = true;

            } else if (refcount1 > refcount2 && (fix & BDRV_FIX_LEAKS)) {

                num_fixed = &res->leaks_fixed;

            } else if (refcount1 < refcount2 && (fix & BDRV_FIX_ERRORS)) {

                num_fixed = &res->corruptions_fixed;

            }



            fprintf(stderr, "%s cluster %" PRId64 " refcount=%" PRIu64

                    " reference=%" PRIu64 "\n",

                   num_fixed != NULL     ? "Repairing" :

                   refcount1 < refcount2 ? "ERROR" :

                                           "Leaked",

                   i, refcount1, refcount2);



            if (num_fixed) {

                ret = update_refcount(bs, i << s->cluster_bits, 1,

                                      refcount_diff(refcount1, refcount2),

                                      refcount1 > refcount2,

                                      QCOW2_DISCARD_ALWAYS);

                if (ret >= 0) {

                    (*num_fixed)++;

                    continue;

                }

            }



            

            if (refcount1 < refcount2) {

                res->corruptions++;

            } else {

                res->leaks++;

            }

        }

    }

}

                              uint16_t *refcount_table, int64_t nb_clusters)         refcount2 = refcount_table[i];
static void FUNC_0(BlockDriverState *VAR_0, BdrvCheckResult *VAR_1,

                              BdrvCheckMode VAR_2, bool *VAR_3,

                              int64_t *VAR_4,

                              uint16_t *VAR_5, int64_t VAR_6)

{

    BDRVQcowState *s = VAR_0->opaque;

    int64_t i;

    uint64_t refcount1, refcount2;

    int VAR_7;



    for (i = 0, *VAR_4 = 0; i < VAR_6; i++) {

        VAR_7 = qcow2_get_refcount(VAR_0, i, &refcount1);

        if (VAR_7 < 0) {

            fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": %s\n",

                    i, strerror(-VAR_7));

            VAR_1->check_errors++;

            continue;

        }



        refcount2 = VAR_5[i];



        if (refcount1 > 0 || refcount2 > 0) {

            *VAR_4 = i;

        }



        if (refcount1 != refcount2) {

            

            int *num_fixed = NULL;

            if (refcount1 == 0) {

                *VAR_3 = true;

            } else if (refcount1 > refcount2 && (VAR_2 & BDRV_FIX_LEAKS)) {

                num_fixed = &VAR_1->leaks_fixed;

            } else if (refcount1 < refcount2 && (VAR_2 & BDRV_FIX_ERRORS)) {

                num_fixed = &VAR_1->corruptions_fixed;

            }



            fprintf(stderr, "%s cluster %" PRId64 " refcount=%" PRIu64

                    " reference=%" PRIu64 "\n",

                   num_fixed != NULL     ? "Repairing" :

                   refcount1 < refcount2 ? "ERROR" :

                                           "Leaked",

                   i, refcount1, refcount2);



            if (num_fixed) {

                VAR_7 = update_refcount(VAR_0, i << s->cluster_bits, 1,

                                      refcount_diff(refcount1, refcount2),

                                      refcount1 > refcount2,

                                      QCOW2_DISCARD_ALWAYS);

                if (VAR_7 >= 0) {

                    (*num_fixed)++;

                    continue;

                }

            }



            

            if (refcount1 < refcount2) {

                VAR_1->corruptions++;

            } else {

                VAR_1->leaks++;

            }

        }

    }

}

static void FUNC_0(BlockDriverState *VAR_0, BdrvCheckResult *VAR_1,
BdrvCheckMode VAR_2, bool *VAR_3,
int64_t *VAR_4,
uint16_t *VAR_5, int64_t VAR_6)
{ BDRVQcowState *s = VAR_0->opaque; int64_t i; uint64_t refcount1, refcount2; int VAR_7; for (i = 0, *VAR_4 = 0; i < VAR_6; i++) { VAR_7 = qcow2_get_refcount(VAR_0, i, &refcount1); if (VAR_7 < 0) { fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": %s\n",
i, strerror(-VAR_7)); VAR_1->check_errors++; continue; } refcount2 = VAR_5[i]; if (refcount1 > 0 || refcount2 > 0) { *VAR_4 = i; } if (refcount1 != refcount2) { int *num_fixed = NULL; if (refcount1 == 0) { *VAR_3 = true; } else if (refcount1 > refcount2 && (VAR_2 & BDRV_FIX_LEAKS)) { num_fixed = &VAR_1->leaks_fixed; } else if (refcount1 < refcount2 && (VAR_2 & BDRV_FIX_ERRORS)) { num_fixed = &VAR_1->corruptions_fixed; } fprintf(stderr, "%s cluster %" PRId64 " refcount=%" PRIu64
" reference=%" PRIu64 "\n",
num_fixed != NULL     ? "Repairing" :
refcount1 < refcount2 ? "ERROR" :
"Leaked",
i, refcount1, refcount2); if (num_fixed) { VAR_7 = update_refcount(VAR_0, i << s->cluster_bits, 1,
refcount_diff(refcount1, refcount2),
refcount1 > refcount2,
QCOW2_DISCARD_ALWAYS); if (VAR_7 >= 0) { (*num_fixed)++; continue; } } if (refcount1 < refcount2) { VAR_1->corruptions++; } else { VAR_1->leaks++; } } } }