static int inc_refcounts(BlockDriverState *bs,

                         BdrvCheckResult *res,

                         void **refcount_table,

                         int64_t *refcount_table_size,

                         int64_t offset, int64_t size)

{

    BDRVQcow2State *s = bs->opaque;

    uint64_t start, last, cluster_offset, k, refcount;

    int ret;



    if (size <= 0) {

        return 0;

    }



    start = start_of_cluster(s, offset);

    last = start_of_cluster(s, offset + size - 1);

    for(cluster_offset = start; cluster_offset <= last;

        cluster_offset += s->cluster_size) {

        k = cluster_offset >> s->cluster_bits;

        if (k >= *refcount_table_size) {

            ret = realloc_refcount_array(s, refcount_table,

                                         refcount_table_size, k + 1);

            if (ret < 0) {

                res->check_errors++;

                return ret;

            }

        }



        refcount = s->get_refcount(*refcount_table, k);

        if (refcount == s->refcount_max) {

            fprintf(stderr, "ERROR: overflow cluster offset=0x%" PRIx64

                    "\n", cluster_offset);

            fprintf(stderr, "Use qemu-img amend to increase the refcount entry "

                    "width or qemu-img convert to create a clean copy if the "

                    "image cannot be opened for writing\n");

            res->corruptions++;

            continue;

        }

        s->set_refcount(*refcount_table, k, refcount + 1);

    }



    return 0;

}

static int inc_refcounts(BlockDriverState *bs,

                         BdrvCheckResult *res,

                         void **refcount_table,

                         int64_t *refcount_table_size,

                         int64_t offset, int64_t size)

{

    BDRVQcow2State *s = bs->opaque;

    uint64_t start, last, cluster_offset, k, refcount;

    int ret;



    if (size <= 0) {

        return 0;

    }



    start = start_of_cluster(s, offset);

    last = start_of_cluster(s, offset + size - 1);

    for(cluster_offset = start; cluster_offset <= last;

        cluster_offset += s->cluster_size) {

        k = cluster_offset >> s->cluster_bits;

        if (k >= *refcount_table_size) {

            ret = realloc_refcount_array(s, refcount_table,

                                         refcount_table_size, k + 1);

            if (ret < 0) {

                res->check_errors++;

                return ret;

            }

        }



        refcount = s->get_refcount(*refcount_table, k);

        if (refcount == s->refcount_max) {

            fprintf(stderr, "ERROR: overflow cluster offset=0x%" PRIx64

                    "\n", cluster_offset);

            fprintf(stderr, "Use qemu-img amend to increase the refcount entry "

                    "width or qemu-img convert to create a clean copy if the "

                    "image cannot be opened for writing\n");

            res->corruptions++;

            continue;

        }

        s->set_refcount(*refcount_table, k, refcount + 1);

    }



    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0,

                         BdrvCheckResult *VAR_1,

                         void **VAR_2,

                         int64_t *VAR_3,

                         int64_t VAR_4, int64_t VAR_5)

{

    BDRVQcow2State *s = VAR_0->opaque;

    uint64_t start, last, cluster_offset, k, refcount;

    int VAR_6;



    if (VAR_5 <= 0) {

        return 0;

    }



    start = start_of_cluster(s, VAR_4);

    last = start_of_cluster(s, VAR_4 + VAR_5 - 1);

    for(cluster_offset = start; cluster_offset <= last;

        cluster_offset += s->cluster_size) {

        k = cluster_offset >> s->cluster_bits;

        if (k >= *VAR_3) {

            VAR_6 = realloc_refcount_array(s, VAR_2,

                                         VAR_3, k + 1);

            if (VAR_6 < 0) {

                VAR_1->check_errors++;

                return VAR_6;

            }

        }



        refcount = s->get_refcount(*VAR_2, k);

        if (refcount == s->refcount_max) {

            fprintf(stderr, "ERROR: overflow cluster VAR_4=0x%" PRIx64

                    "\n", cluster_offset);

            fprintf(stderr, "Use qemu-img amend to increase the refcount entry "

                    "width or qemu-img convert to create a clean copy if the "

                    "image cannot be opened for writing\n");

            VAR_1->corruptions++;

            continue;

        }

        s->set_refcount(*VAR_2, k, refcount + 1);

    }



    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0,
BdrvCheckResult *VAR_1,
void **VAR_2,
int64_t *VAR_3,
int64_t VAR_4, int64_t VAR_5)
{ BDRVQcow2State *s = VAR_0->opaque; uint64_t start, last, cluster_offset, k, refcount; int VAR_6; if (VAR_5 <= 0) { return 0; } start = start_of_cluster(s, VAR_4); last = start_of_cluster(s, VAR_4 + VAR_5 - 1); for(cluster_offset = start; cluster_offset <= last; cluster_offset += s->cluster_size) { k = cluster_offset >> s->cluster_bits; if (k >= *VAR_3) { VAR_6 = realloc_refcount_array(s, VAR_2,
VAR_3, k + 1); if (VAR_6 < 0) { VAR_1->check_errors++; return VAR_6; } } refcount = s->get_refcount(*VAR_2, k); if (refcount == s->refcount_max) { fprintf(stderr, "ERROR: overflow cluster VAR_4=0x%" PRIx64
"\n", cluster_offset); fprintf(stderr, "Use qemu-img amend to increase the refcount entry "
"width or qemu-img convert to create a clean copy if the "
"image cannot be opened for writing\n"); VAR_1->corruptions++; continue; } s->set_refcount(*VAR_2, k, refcount + 1); } return 0; }