static int img_amend(int argc, char **argv)

{

    int c, ret = 0;

    char *options = NULL;

    QemuOptsList *create_opts = NULL;

    QemuOpts *opts = NULL;

    const char *fmt = NULL, *filename, *cache;

    int flags;

    bool quiet = false, progress = false;

    BlockBackend *blk = NULL;

    BlockDriverState *bs = NULL;



    cache = BDRV_DEFAULT_CACHE;

    for (;;) {

        c = getopt(argc, argv, "ho:f:t:pq");

        if (c == -1) {

            break;

        }



        switch (c) {

            case 'h':

            case '?':

                help();

                break;

            case 'o':

                if (!is_valid_option_list(optarg)) {

                    error_report("Invalid option list: %s", optarg);

                    ret = -1;

                    goto out;

                }

                if (!options) {

                    options = g_strdup(optarg);

                } else {

                    char *old_options = options;

                    options = g_strdup_printf("%s,%s", options, optarg);

                    g_free(old_options);

                }

                break;

            case 'f':

                fmt = optarg;

                break;

            case 't':

                cache = optarg;

                break;

            case 'p':

                progress = true;

                break;

            case 'q':

                quiet = true;

                break;

        }

    }



    if (!options) {

        error_exit("Must specify options (-o)");

    }



    if (quiet) {

        progress = false;

    }

    qemu_progress_init(progress, 1.0);



    filename = (optind == argc - 1) ? argv[argc - 1] : NULL;

    if (fmt && has_help_option(options)) {

        /* If a format is explicitly specified (and possibly no filename is

         * given), print option help here */

        ret = print_block_option_help(filename, fmt);

        goto out;

    }



    if (optind != argc - 1) {

        error_report("Expecting one image file name");

        ret = -1;

        goto out;

    }



    flags = BDRV_O_FLAGS | BDRV_O_RDWR;

    ret = bdrv_parse_cache_flags(cache, &flags);

    if (ret < 0) {

        error_report("Invalid cache option: %s", cache);

        goto out;

    }



    blk = img_open("image", filename, fmt, flags, true, quiet);

    if (!blk) {

        ret = -1;

        goto out;

    }

    bs = blk_bs(blk);



    fmt = bs->drv->format_name;



    if (has_help_option(options)) {

        /* If the format was auto-detected, print option help here */

        ret = print_block_option_help(filename, fmt);

        goto out;

    }



    if (!bs->drv->create_opts) {

        error_report("Format driver '%s' does not support any options to amend",

                     fmt);

        ret = -1;

        goto out;

    }



    create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);

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

    if (options && qemu_opts_do_parse(opts, options, NULL)) {

        error_report("Invalid options for file format '%s'", fmt);

        ret = -1;

        goto out;

    }



    /* In case the driver does not call amend_status_cb() */

    qemu_progress_print(0.f, 0);

    ret = bdrv_amend_options(bs, opts, &amend_status_cb);

    qemu_progress_print(100.f, 0);

    if (ret < 0) {

        error_report("Error while amending options: %s", strerror(-ret));

        goto out;

    }



out:

    qemu_progress_end();



    blk_unref(blk);

    qemu_opts_del(opts);

    qemu_opts_free(create_opts);

    g_free(options);



    if (ret) {

        return 1;

    }

    return 0;

}

static int img_amend(int argc, char **argv)

{

    int c, ret = 0;

    char *options = NULL;

    QemuOptsList *create_opts = NULL;

    QemuOpts *opts = NULL;

    const char *fmt = NULL, *filename, *cache;

    int flags;

    bool quiet = false, progress = false;

    BlockBackend *blk = NULL;

    BlockDriverState *bs = NULL;



    cache = BDRV_DEFAULT_CACHE;

    for (;;) {

        c = getopt(argc, argv, "ho:f:t:pq");

        if (c == -1) {

            break;

        }



        switch (c) {

            case 'h':

            case '?':

                help();

                break;

            case 'o':

                if (!is_valid_option_list(optarg)) {

                    error_report("Invalid option list: %s", optarg);

                    ret = -1;

                    goto out;

                }

                if (!options) {

                    options = g_strdup(optarg);

                } else {

                    char *old_options = options;

                    options = g_strdup_printf("%s,%s", options, optarg);

                    g_free(old_options);

                }

                break;

            case 'f':

                fmt = optarg;

                break;

            case 't':

                cache = optarg;

                break;

            case 'p':

                progress = true;

                break;

            case 'q':

                quiet = true;

                break;

        }

    }



    if (!options) {

        error_exit("Must specify options (-o)");

    }



    if (quiet) {

        progress = false;

    }

    qemu_progress_init(progress, 1.0);



    filename = (optind == argc - 1) ? argv[argc - 1] : NULL;

    if (fmt && has_help_option(options)) {

        



        ret = print_block_option_help(filename, fmt);

        goto out;

    }



    if (optind != argc - 1) {

        error_report("Expecting one image file name");

        ret = -1;

        goto out;

    }



    flags = BDRV_O_FLAGS | BDRV_O_RDWR;

    ret = bdrv_parse_cache_flags(cache, &flags);

    if (ret < 0) {

        error_report("Invalid cache option: %s", cache);

        goto out;

    }



    blk = img_open("image", filename, fmt, flags, true, quiet);

    if (!blk) {

        ret = -1;

        goto out;

    }

    bs = blk_bs(blk);



    fmt = bs->drv->format_name;



    if (has_help_option(options)) {

        

        ret = print_block_option_help(filename, fmt);

        goto out;

    }



    if (!bs->drv->create_opts) {

        error_report("Format driver '%s' does not support any options to amend",

                     fmt);

        ret = -1;

        goto out;

    }



    create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);

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

    if (options && qemu_opts_do_parse(opts, options, NULL)) {

        error_report("Invalid options for file format '%s'", fmt);

        ret = -1;

        goto out;

    }



    

    qemu_progress_print(0.f, 0);

    ret = bdrv_amend_options(bs, opts, &amend_status_cb);

    qemu_progress_print(100.f, 0);

    if (ret < 0) {

        error_report("Error while amending options: %s", strerror(-ret));

        goto out;

    }



out:

    qemu_progress_end();



    blk_unref(blk);

    qemu_opts_del(opts);

    qemu_opts_free(create_opts);

    g_free(options);



    if (ret) {

        return 1;

    }

    return 0;

}

static int FUNC_0(int VAR_0, char **VAR_1)

{

    int VAR_2, VAR_3 = 0;

    char *VAR_4 = NULL;

    QemuOptsList *create_opts = NULL;

    QemuOpts *opts = NULL;

    const char *VAR_5 = NULL, *VAR_6, *VAR_7;

    int VAR_8;

    bool quiet = false, progress = false;

    BlockBackend *blk = NULL;

    BlockDriverState *bs = NULL;



    VAR_7 = BDRV_DEFAULT_CACHE;

    for (;;) {

        VAR_2 = getopt(VAR_0, VAR_1, "ho:f:t:pq");

        if (VAR_2 == -1) {

            break;

        }



        switch (VAR_2) {

            case 'h':

            case '?':

                help();

                break;

            case 'o':

                if (!is_valid_option_list(optarg)) {

                    error_report("Invalid option list: %s", optarg);

                    VAR_3 = -1;

                    goto out;

                }

                if (!VAR_4) {

                    VAR_4 = g_strdup(optarg);

                } else {

                    char *VAR_9 = VAR_4;

                    VAR_4 = g_strdup_printf("%s,%s", VAR_4, optarg);

                    g_free(VAR_9);

                }

                break;

            case 'f':

                VAR_5 = optarg;

                break;

            case 't':

                VAR_7 = optarg;

                break;

            case 'p':

                progress = true;

                break;

            case 'q':

                quiet = true;

                break;

        }

    }



    if (!VAR_4) {

        error_exit("Must specify VAR_4 (-o)");

    }



    if (quiet) {

        progress = false;

    }

    qemu_progress_init(progress, 1.0);



    VAR_6 = (optind == VAR_0 - 1) ? VAR_1[VAR_0 - 1] : NULL;

    if (VAR_5 && has_help_option(VAR_4)) {

        



        VAR_3 = print_block_option_help(VAR_6, VAR_5);

        goto out;

    }



    if (optind != VAR_0 - 1) {

        error_report("Expecting one image file name");

        VAR_3 = -1;

        goto out;

    }



    VAR_8 = BDRV_O_FLAGS | BDRV_O_RDWR;

    VAR_3 = bdrv_parse_cache_flags(VAR_7, &VAR_8);

    if (VAR_3 < 0) {

        error_report("Invalid VAR_7 option: %s", VAR_7);

        goto out;

    }



    blk = img_open("image", VAR_6, VAR_5, VAR_8, true, quiet);

    if (!blk) {

        VAR_3 = -1;

        goto out;

    }

    bs = blk_bs(blk);



    VAR_5 = bs->drv->format_name;



    if (has_help_option(VAR_4)) {

        

        VAR_3 = print_block_option_help(VAR_6, VAR_5);

        goto out;

    }



    if (!bs->drv->create_opts) {

        error_report("Format driver '%s' does not support any VAR_4 to amend",

                     VAR_5);

        VAR_3 = -1;

        goto out;

    }



    create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);

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

    if (VAR_4 && qemu_opts_do_parse(opts, VAR_4, NULL)) {

        error_report("Invalid VAR_4 for file format '%s'", VAR_5);

        VAR_3 = -1;

        goto out;

    }



    

    qemu_progress_print(0.f, 0);

    VAR_3 = bdrv_amend_options(bs, opts, &amend_status_cb);

    qemu_progress_print(100.f, 0);

    if (VAR_3 < 0) {

        error_report("Error while amending VAR_4: %s", strerror(-VAR_3));

        goto out;

    }



out:

    qemu_progress_end();



    blk_unref(blk);

    qemu_opts_del(opts);

    qemu_opts_free(create_opts);

    g_free(VAR_4);



    if (VAR_3) {

        return 1;

    }

    return 0;

}

static int FUNC_0(int VAR_0, char **VAR_1)
{ int VAR_2, VAR_3 = 0; char *VAR_4 = NULL; QemuOptsList *create_opts = NULL; QemuOpts *opts = NULL; const char *VAR_5 = NULL, *VAR_6, *VAR_7; int VAR_8; bool quiet = false, progress = false; BlockBackend *blk = NULL; BlockDriverState *bs = NULL; VAR_7 = BDRV_DEFAULT_CACHE; for (;;) { VAR_2 = getopt(VAR_0, VAR_1, "ho:f:t:pq"); if (VAR_2 == -1) { break; } switch (VAR_2) { case 'h':
case '?':
help(); break; case 'o':
if (!is_valid_option_list(optarg)) { error_report("Invalid option list: %s", optarg); VAR_3 = -1; goto out; } if (!VAR_4) { VAR_4 = g_strdup(optarg); } else { char *VAR_9 = VAR_4; VAR_4 = g_strdup_printf("%s,%s", VAR_4, optarg); g_free(VAR_9); } break; case 'f':
VAR_5 = optarg; break; case 't':
VAR_7 = optarg; break; case 'p':
progress = true; break; case 'q':
quiet = true; break; } } if (!VAR_4) { error_exit("Must specify VAR_4 (-o)"); } if (quiet) { progress = false; } qemu_progress_init(progress, 1.0); VAR_6 = (optind == VAR_0 - 1) ? VAR_1[VAR_0 - 1] : NULL; if (VAR_5 && has_help_option(VAR_4)) { VAR_3 = print_block_option_help(VAR_6, VAR_5); goto out; } if (optind != VAR_0 - 1) { error_report("Expecting one image file name"); VAR_3 = -1; goto out; } VAR_8 = BDRV_O_FLAGS | BDRV_O_RDWR; VAR_3 = bdrv_parse_cache_flags(VAR_7, &VAR_8); if (VAR_3 < 0) { error_report("Invalid VAR_7 option: %s", VAR_7); goto out; } blk = img_open("image", VAR_6, VAR_5, VAR_8, true, quiet); if (!blk) { VAR_3 = -1; goto out; } bs = blk_bs(blk); VAR_5 = bs->drv->format_name; if (has_help_option(VAR_4)) { VAR_3 = print_block_option_help(VAR_6, VAR_5); goto out; } if (!bs->drv->create_opts) { error_report("Format driver '%s' does not support any VAR_4 to amend",
VAR_5); VAR_3 = -1; goto out; } create_opts = qemu_opts_append(create_opts, bs->drv->create_opts); opts = qemu_opts_create(create_opts, NULL, 0, &error_abort); if (VAR_4 && qemu_opts_do_parse(opts, VAR_4, NULL)) { error_report("Invalid VAR_4 for file format '%s'", VAR_5); VAR_3 = -1; goto out; } qemu_progress_print(0.f, 0); VAR_3 = bdrv_amend_options(bs, opts, &amend_status_cb); qemu_progress_print(100.f, 0); if (VAR_3 < 0) { error_report("Error while amending VAR_4: %s", strerror(-VAR_3)); goto out; } out:
qemu_progress_end(); blk_unref(blk); qemu_opts_del(opts); qemu_opts_free(create_opts); g_free(VAR_4); if (VAR_3) { return 1; } return 0; }