static int raw_read_options(QDict *options, BlockDriverState *bs,

    BDRVRawState *s, Error **errp)

{

    Error *local_err = NULL;

    QemuOpts *opts = NULL;

    int64_t real_size = 0;

    int ret;



    real_size = bdrv_getlength(bs->file->bs);

    if (real_size < 0) {

        error_setg_errno(errp, -real_size, "Could not get image size");

        return real_size;

    }



    opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);

    qemu_opts_absorb_qdict(opts, options, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        ret = -EINVAL;

        goto end;

    }



    s->offset = qemu_opt_get_size(opts, "offset", 0);

    if (s->offset > real_size) {

        error_setg(errp, "Offset (%" PRIu64 ") cannot be greater than "

            "size of the containing file (%" PRId64 ")",

            s->offset, real_size);

        ret = -EINVAL;

        goto end;

    }



    if (qemu_opt_find(opts, "size") != NULL) {

        s->size = qemu_opt_get_size(opts, "size", 0);

        s->has_size = true;

    } else {

        s->has_size = false;

        s->size = real_size - s->offset;

    }



    /* Check size and offset */

    if ((real_size - s->offset) < s->size) {

        error_setg(errp, "The sum of offset (%" PRIu64 ") and size "

            "(%" PRIu64 ") has to be smaller or equal to the "

            " actual size of the containing file (%" PRId64 ")",

            s->offset, s->size, real_size);

        ret = -EINVAL;

        goto end;

    }



    /* Make sure size is multiple of BDRV_SECTOR_SIZE to prevent rounding

     * up and leaking out of the specified area. */

    if (s->has_size && !QEMU_IS_ALIGNED(s->size, BDRV_SECTOR_SIZE)) {

        error_setg(errp, "Specified size is not multiple of %llu",

            BDRV_SECTOR_SIZE);

        ret = -EINVAL;

        goto end;

    }



    ret = 0;



end:



    qemu_opts_del(opts);



    return ret;

}

static int raw_read_options(QDict *options, BlockDriverState *bs,

    BDRVRawState *s, Error **errp)

{

    Error *local_err = NULL;

    QemuOpts *opts = NULL;

    int64_t real_size = 0;

    int ret;



    real_size = bdrv_getlength(bs->file->bs);

    if (real_size < 0) {

        error_setg_errno(errp, -real_size, "Could not get image size");

        return real_size;

    }



    opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);

    qemu_opts_absorb_qdict(opts, options, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        ret = -EINVAL;

        goto end;

    }



    s->offset = qemu_opt_get_size(opts, "offset", 0);

    if (s->offset > real_size) {

        error_setg(errp, "Offset (%" PRIu64 ") cannot be greater than "

            "size of the containing file (%" PRId64 ")",

            s->offset, real_size);

        ret = -EINVAL;

        goto end;

    }



    if (qemu_opt_find(opts, "size") != NULL) {

        s->size = qemu_opt_get_size(opts, "size", 0);

        s->has_size = true;

    } else {

        s->has_size = false;

        s->size = real_size - s->offset;

    }



    

    if ((real_size - s->offset) < s->size) {

        error_setg(errp, "The sum of offset (%" PRIu64 ") and size "

            "(%" PRIu64 ") has to be smaller or equal to the "

            " actual size of the containing file (%" PRId64 ")",

            s->offset, s->size, real_size);

        ret = -EINVAL;

        goto end;

    }



    



    if (s->has_size && !QEMU_IS_ALIGNED(s->size, BDRV_SECTOR_SIZE)) {

        error_setg(errp, "Specified size is not multiple of %llu",

            BDRV_SECTOR_SIZE);

        ret = -EINVAL;

        goto end;

    }



    ret = 0;



end:



    qemu_opts_del(opts);



    return ret;

}

static int FUNC_0(QDict *VAR_0, BlockDriverState *VAR_1,

    BDRVRawState *VAR_2, Error **VAR_3)

{

    Error *local_err = NULL;

    QemuOpts *opts = NULL;

    int64_t real_size = 0;

    int VAR_4;



    real_size = bdrv_getlength(VAR_1->file->VAR_1);

    if (real_size < 0) {

        error_setg_errno(VAR_3, -real_size, "Could not get image size");

        return real_size;

    }



    opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);

    qemu_opts_absorb_qdict(opts, VAR_0, &local_err);

    if (local_err) {

        error_propagate(VAR_3, local_err);

        VAR_4 = -EINVAL;

        goto end;

    }



    VAR_2->offset = qemu_opt_get_size(opts, "offset", 0);

    if (VAR_2->offset > real_size) {

        error_setg(VAR_3, "Offset (%" PRIu64 ") cannot be greater than "

            "size of the containing file (%" PRId64 ")",

            VAR_2->offset, real_size);

        VAR_4 = -EINVAL;

        goto end;

    }



    if (qemu_opt_find(opts, "size") != NULL) {

        VAR_2->size = qemu_opt_get_size(opts, "size", 0);

        VAR_2->has_size = true;

    } else {

        VAR_2->has_size = false;

        VAR_2->size = real_size - VAR_2->offset;

    }



    

    if ((real_size - VAR_2->offset) < VAR_2->size) {

        error_setg(VAR_3, "The sum of offset (%" PRIu64 ") and size "

            "(%" PRIu64 ") has to be smaller or equal to the "

            " actual size of the containing file (%" PRId64 ")",

            VAR_2->offset, VAR_2->size, real_size);

        VAR_4 = -EINVAL;

        goto end;

    }



    



    if (VAR_2->has_size && !QEMU_IS_ALIGNED(VAR_2->size, BDRV_SECTOR_SIZE)) {

        error_setg(VAR_3, "Specified size is not multiple of %llu",

            BDRV_SECTOR_SIZE);

        VAR_4 = -EINVAL;

        goto end;

    }



    VAR_4 = 0;



end:



    qemu_opts_del(opts);



    return VAR_4;

}

static int FUNC_0(QDict *VAR_0, BlockDriverState *VAR_1,
BDRVRawState *VAR_2, Error **VAR_3)
{ Error *local_err = NULL; QemuOpts *opts = NULL; int64_t real_size = 0; int VAR_4; real_size = bdrv_getlength(VAR_1->file->VAR_1); if (real_size < 0) { error_setg_errno(VAR_3, -real_size, "Could not get image size"); return real_size; } opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, VAR_0, &local_err); if (local_err) { error_propagate(VAR_3, local_err); VAR_4 = -EINVAL; goto end; } VAR_2->offset = qemu_opt_get_size(opts, "offset", 0); if (VAR_2->offset > real_size) { error_setg(VAR_3, "Offset (%" PRIu64 ") cannot be greater than "
"size of the containing file (%" PRId64 ")",
VAR_2->offset, real_size); VAR_4 = -EINVAL; goto end; } if (qemu_opt_find(opts, "size") != NULL) { VAR_2->size = qemu_opt_get_size(opts, "size", 0); VAR_2->has_size = true; } else { VAR_2->has_size = false; VAR_2->size = real_size - VAR_2->offset; } if ((real_size - VAR_2->offset) < VAR_2->size) { error_setg(VAR_3, "The sum of offset (%" PRIu64 ") and size "
"(%" PRIu64 ") has to be smaller or equal to the "
" actual size of the containing file (%" PRId64 ")",
VAR_2->offset, VAR_2->size, real_size); VAR_4 = -EINVAL; goto end; } if (VAR_2->has_size && !QEMU_IS_ALIGNED(VAR_2->size, BDRV_SECTOR_SIZE)) { error_setg(VAR_3, "Specified size is not multiple of %llu",
BDRV_SECTOR_SIZE); VAR_4 = -EINVAL; goto end; } VAR_4 = 0; end:
qemu_opts_del(opts); return VAR_4; }