int qcow2_pre_write_overlap_check(BlockDriverState *bs, int chk, int64_t offset,

                                  int64_t size)

{

    int ret = qcow2_check_metadata_overlap(bs, chk, offset, size);



    if (ret < 0) {

        return ret;

    } else if (ret > 0) {

        int metadata_ol_bitnr = ffs(ret) - 1;

        char *message;

        QObject *data;



        assert(metadata_ol_bitnr < QCOW2_OL_MAX_BITNR);



        fprintf(stderr, "qcow2: Preventing invalid write on metadata (overlaps "

                "with %s); image marked as corrupt.\n",

                metadata_ol_names[metadata_ol_bitnr]);

        message = g_strdup_printf("Prevented %s overwrite",

                metadata_ol_names[metadata_ol_bitnr]);

        data = qobject_from_jsonf("{ 'device': %s, 'msg': %s, 'offset': %"

                PRId64 ", 'size': %" PRId64 " }", bs->device_name, message,

                offset, size);

        monitor_protocol_event(QEVENT_BLOCK_IMAGE_CORRUPTED, data);

        g_free(message);

        qobject_decref(data);



        qcow2_mark_corrupt(bs);

        bs->drv = NULL; /* make BDS unusable */

        return -EIO;

    }



    return 0;

}

int qcow2_pre_write_overlap_check(BlockDriverState *bs, int chk, int64_t offset,

                                  int64_t size)

{

    int ret = qcow2_check_metadata_overlap(bs, chk, offset, size);



    if (ret < 0) {

        return ret;

    } else if (ret > 0) {

        int metadata_ol_bitnr = ffs(ret) - 1;

        char *message;

        QObject *data;



        assert(metadata_ol_bitnr < QCOW2_OL_MAX_BITNR);



        fprintf(stderr, "qcow2: Preventing invalid write on metadata (overlaps "

                "with %s); image marked as corrupt.\n",

                metadata_ol_names[metadata_ol_bitnr]);

        message = g_strdup_printf("Prevented %s overwrite",

                metadata_ol_names[metadata_ol_bitnr]);

        data = qobject_from_jsonf("{ 'device': %s, 'msg': %s, 'offset': %"

                PRId64 ", 'size': %" PRId64 " }", bs->device_name, message,

                offset, size);

        monitor_protocol_event(QEVENT_BLOCK_IMAGE_CORRUPTED, data);

        g_free(message);

        qobject_decref(data);



        qcow2_mark_corrupt(bs);

        bs->drv = NULL; 

        return -EIO;

    }



    return 0;

}

int qcow2_pre_write_overlap_check(BlockDriverState *bs, int chk, int64_t offset,     int ret = qcow2_check_metadata_overlap(bs, chk, offset, size); int qcow2_pre_write_overlap_check(BlockDriverState *bs, int chk, int64_t offset,
int FUNC_0(BlockDriverState *VAR_0, int VAR_1, int64_t VAR_2,

                                  int64_t VAR_3)

{

    int VAR_4 = qcow2_check_metadata_overlap(VAR_0, VAR_1, VAR_2, VAR_3);



    if (VAR_4 < 0) {

        return VAR_4;

    } else if (VAR_4 > 0) {

        int VAR_5 = ffs(VAR_4) - 1;

        char *VAR_6;

        QObject *data;



        assert(VAR_5 < QCOW2_OL_MAX_BITNR);



        fprintf(stderr, "qcow2: Preventing invalid write on metadata (overlaps "

                "with %s); image marked as corrupt.\n",

                metadata_ol_names[VAR_5]);

        VAR_6 = g_strdup_printf("Prevented %s overwrite",

                metadata_ol_names[VAR_5]);

        data = qobject_from_jsonf("{ 'device': %s, 'msg': %s, 'VAR_2': %"

                PRId64 ", 'VAR_3': %" PRId64 " }", VAR_0->device_name, VAR_6,

                VAR_2, VAR_3);

        monitor_protocol_event(QEVENT_BLOCK_IMAGE_CORRUPTED, data);

        g_free(VAR_6);

        qobject_decref(data);



        qcow2_mark_corrupt(VAR_0);

        VAR_0->drv = NULL; 

        return -EIO;

    }



    return 0;

}

int FUNC_0(BlockDriverState *VAR_0, int VAR_1, int64_t VAR_2,
int64_t VAR_3)
{ int VAR_4 = qcow2_check_metadata_overlap(VAR_0, VAR_1, VAR_2, VAR_3); if (VAR_4 < 0) { return VAR_4; } else if (VAR_4 > 0) { int VAR_5 = ffs(VAR_4) - 1; char *VAR_6; QObject *data; assert(VAR_5 < QCOW2_OL_MAX_BITNR); fprintf(stderr, "qcow2: Preventing invalid write on metadata (overlaps "
"with %s); image marked as corrupt.\n", metadata_ol_names[VAR_5]); VAR_6 = g_strdup_printf("Prevented %s overwrite",
metadata_ol_names[VAR_5]); data = qobject_from_jsonf("{ 'device': %s, 'msg': %s, 'VAR_2': %" PRId64 ", 'VAR_3': %" PRId64 " }", VAR_0->device_name, VAR_6, VAR_2, VAR_3); monitor_protocol_event(QEVENT_BLOCK_IMAGE_CORRUPTED, data); g_free(VAR_6); qobject_decref(data); qcow2_mark_corrupt(VAR_0); VAR_0->drv = NULL; return -EIO; } return 0; }