static int bdrv_fill_options(QDict **options, const char **pfilename, int flags,

                             BlockDriver *drv, Error **errp)

{

    const char *filename = *pfilename;

    const char *drvname;

    bool protocol = flags & BDRV_O_PROTOCOL;

    bool parse_filename = false;

    Error *local_err = NULL;



    /* Parse json: pseudo-protocol */

    if (filename && g_str_has_prefix(filename, "json:")) {

        QDict *json_options = parse_json_filename(filename, &local_err);

        if (local_err) {

            error_propagate(errp, local_err);

            return -EINVAL;

        }



        /* Options given in the filename have lower priority than options

         * specified directly */

        qdict_join(*options, json_options, false);

        QDECREF(json_options);

        *pfilename = filename = NULL;

    }



    /* Fetch the file name from the options QDict if necessary */

    if (protocol && filename) {

        if (!qdict_haskey(*options, "filename")) {

            qdict_put(*options, "filename", qstring_from_str(filename));

            parse_filename = true;

        } else {

            error_setg(errp, "Can't specify 'file' and 'filename' options at "

                             "the same time");

            return -EINVAL;

        }

    }



    /* Find the right block driver */

    filename = qdict_get_try_str(*options, "filename");

    drvname = qdict_get_try_str(*options, "driver");



    if (drv) {

        if (drvname) {

            error_setg(errp, "Driver specified twice");

            return -EINVAL;

        }

        drvname = drv->format_name;

        qdict_put(*options, "driver", qstring_from_str(drvname));

    } else {

        if (!drvname && protocol) {

            if (filename) {

                drv = bdrv_find_protocol(filename, parse_filename, errp);

                if (!drv) {

                    return -EINVAL;

                }



                drvname = drv->format_name;

                qdict_put(*options, "driver", qstring_from_str(drvname));

            } else {

                error_setg(errp, "Must specify either driver or file");

                return -EINVAL;

            }

        } else if (drvname) {

            drv = bdrv_find_format(drvname);

            if (!drv) {

                error_setg(errp, "Unknown driver '%s'", drvname);

                return -ENOENT;

            }

        }

    }



    assert(drv || !protocol);



    /* Driver-specific filename parsing */

    if (drv && drv->bdrv_parse_filename && parse_filename) {

        drv->bdrv_parse_filename(filename, *options, &local_err);

        if (local_err) {

            error_propagate(errp, local_err);

            return -EINVAL;

        }



        if (!drv->bdrv_needs_filename) {

            qdict_del(*options, "filename");

        }

    }



    return 0;

}

static int bdrv_fill_options(QDict **options, const char **pfilename, int flags,

                             BlockDriver *drv, Error **errp)

{

    const char *filename = *pfilename;

    const char *drvname;

    bool protocol = flags & BDRV_O_PROTOCOL;

    bool parse_filename = false;

    Error *local_err = NULL;



    

    if (filename && g_str_has_prefix(filename, "json:")) {

        QDict *json_options = parse_json_filename(filename, &local_err);

        if (local_err) {

            error_propagate(errp, local_err);

            return -EINVAL;

        }



        



        qdict_join(*options, json_options, false);

        QDECREF(json_options);

        *pfilename = filename = NULL;

    }



    

    if (protocol && filename) {

        if (!qdict_haskey(*options, "filename")) {

            qdict_put(*options, "filename", qstring_from_str(filename));

            parse_filename = true;

        } else {

            error_setg(errp, "Can't specify 'file' and 'filename' options at "

                             "the same time");

            return -EINVAL;

        }

    }



    

    filename = qdict_get_try_str(*options, "filename");

    drvname = qdict_get_try_str(*options, "driver");



    if (drv) {

        if (drvname) {

            error_setg(errp, "Driver specified twice");

            return -EINVAL;

        }

        drvname = drv->format_name;

        qdict_put(*options, "driver", qstring_from_str(drvname));

    } else {

        if (!drvname && protocol) {

            if (filename) {

                drv = bdrv_find_protocol(filename, parse_filename, errp);

                if (!drv) {

                    return -EINVAL;

                }



                drvname = drv->format_name;

                qdict_put(*options, "driver", qstring_from_str(drvname));

            } else {

                error_setg(errp, "Must specify either driver or file");

                return -EINVAL;

            }

        } else if (drvname) {

            drv = bdrv_find_format(drvname);

            if (!drv) {

                error_setg(errp, "Unknown driver '%s'", drvname);

                return -ENOENT;

            }

        }

    }



    assert(drv || !protocol);



    

    if (drv && drv->bdrv_parse_filename && parse_filename) {

        drv->bdrv_parse_filename(filename, *options, &local_err);

        if (local_err) {

            error_propagate(errp, local_err);

            return -EINVAL;

        }



        if (!drv->bdrv_needs_filename) {

            qdict_del(*options, "filename");

        }

    }



    return 0;

}

static int FUNC_0(QDict **VAR_0, const char **VAR_1, int VAR_2,

                             BlockDriver *VAR_3, Error **VAR_4)

{

    const char *VAR_5 = *VAR_1;

    const char *VAR_6;

    bool protocol = VAR_2 & BDRV_O_PROTOCOL;

    bool parse_filename = false;

    Error *local_err = NULL;



    

    if (VAR_5 && g_str_has_prefix(VAR_5, "json:")) {

        QDict *json_options = parse_json_filename(VAR_5, &local_err);

        if (local_err) {

            error_propagate(VAR_4, local_err);

            return -EINVAL;

        }



        



        qdict_join(*VAR_0, json_options, false);

        QDECREF(json_options);

        *VAR_1 = VAR_5 = NULL;

    }



    

    if (protocol && VAR_5) {

        if (!qdict_haskey(*VAR_0, "VAR_5")) {

            qdict_put(*VAR_0, "VAR_5", qstring_from_str(VAR_5));

            parse_filename = true;

        } else {

            error_setg(VAR_4, "Can't specify 'file' and 'VAR_5' VAR_0 at "

                             "the same time");

            return -EINVAL;

        }

    }



    

    VAR_5 = qdict_get_try_str(*VAR_0, "VAR_5");

    VAR_6 = qdict_get_try_str(*VAR_0, "driver");



    if (VAR_3) {

        if (VAR_6) {

            error_setg(VAR_4, "Driver specified twice");

            return -EINVAL;

        }

        VAR_6 = VAR_3->format_name;

        qdict_put(*VAR_0, "driver", qstring_from_str(VAR_6));

    } else {

        if (!VAR_6 && protocol) {

            if (VAR_5) {

                VAR_3 = bdrv_find_protocol(VAR_5, parse_filename, VAR_4);

                if (!VAR_3) {

                    return -EINVAL;

                }



                VAR_6 = VAR_3->format_name;

                qdict_put(*VAR_0, "driver", qstring_from_str(VAR_6));

            } else {

                error_setg(VAR_4, "Must specify either driver or file");

                return -EINVAL;

            }

        } else if (VAR_6) {

            VAR_3 = bdrv_find_format(VAR_6);

            if (!VAR_3) {

                error_setg(VAR_4, "Unknown driver '%s'", VAR_6);

                return -ENOENT;

            }

        }

    }



    assert(VAR_3 || !protocol);



    

    if (VAR_3 && VAR_3->bdrv_parse_filename && parse_filename) {

        VAR_3->bdrv_parse_filename(VAR_5, *VAR_0, &local_err);

        if (local_err) {

            error_propagate(VAR_4, local_err);

            return -EINVAL;

        }



        if (!VAR_3->bdrv_needs_filename) {

            qdict_del(*VAR_0, "VAR_5");

        }

    }



    return 0;

}

static int FUNC_0(QDict **VAR_0, const char **VAR_1, int VAR_2,
BlockDriver *VAR_3, Error **VAR_4)
{ const char *VAR_5 = *VAR_1; const char *VAR_6; bool protocol = VAR_2 & BDRV_O_PROTOCOL; bool parse_filename = false; Error *local_err = NULL; if (VAR_5 && g_str_has_prefix(VAR_5, "json:")) { QDict *json_options = parse_json_filename(VAR_5, &local_err); if (local_err) { error_propagate(VAR_4, local_err); return -EINVAL; } qdict_join(*VAR_0, json_options, false); QDECREF(json_options); *VAR_1 = VAR_5 = NULL; } if (protocol && VAR_5) { if (!qdict_haskey(*VAR_0, "VAR_5")) { qdict_put(*VAR_0, "VAR_5", qstring_from_str(VAR_5)); parse_filename = true; } else { error_setg(VAR_4, "Can't specify 'file' and 'VAR_5' VAR_0 at "
"the same time"); return -EINVAL; } } VAR_5 = qdict_get_try_str(*VAR_0, "VAR_5"); VAR_6 = qdict_get_try_str(*VAR_0, "driver"); if (VAR_3) { if (VAR_6) { error_setg(VAR_4, "Driver specified twice"); return -EINVAL; } VAR_6 = VAR_3->format_name; qdict_put(*VAR_0, "driver", qstring_from_str(VAR_6)); } else { if (!VAR_6 && protocol) { if (VAR_5) { VAR_3 = bdrv_find_protocol(VAR_5, parse_filename, VAR_4); if (!VAR_3) { return -EINVAL; } VAR_6 = VAR_3->format_name; qdict_put(*VAR_0, "driver", qstring_from_str(VAR_6)); } else { error_setg(VAR_4, "Must specify either driver or file"); return -EINVAL; } } else if (VAR_6) { VAR_3 = bdrv_find_format(VAR_6); if (!VAR_3) { error_setg(VAR_4, "Unknown driver '%s'", VAR_6); return -ENOENT; } } } assert(VAR_3 || !protocol); if (VAR_3 && VAR_3->bdrv_parse_filename && parse_filename) { VAR_3->bdrv_parse_filename(VAR_5, *VAR_0, &local_err); if (local_err) { error_propagate(VAR_4, local_err); return -EINVAL; } if (!VAR_3->bdrv_needs_filename) { qdict_del(*VAR_0, "VAR_5"); } } return 0; }