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

{

    Error *err = NULL;

    int c, ret, relative;

    const char *filename, *fmt, *size;

    int64_t n, total_size;

    bool quiet = false;

    BlockBackend *blk = NULL;

    QemuOpts *param;



    static QemuOptsList resize_options = {

        .name = "resize_options",

        .head = QTAILQ_HEAD_INITIALIZER(resize_options.head),

        .desc = {

            {

                .name = BLOCK_OPT_SIZE,

                .type = QEMU_OPT_SIZE,

                .help = "Virtual disk size"

            }, {

                /* end of list */

            }

        },

    };

    bool image_opts = false;



    /* Remove size from argv manually so that negative numbers are not treated

     * as options by getopt. */

    if (argc < 3) {

        error_exit("Not enough arguments");

        return 1;

    }



    size = argv[--argc];



    /* Parse getopt arguments */

    fmt = NULL;

    for(;;) {

        static const struct option long_options[] = {

            {"help", no_argument, 0, 'h'},

            {"object", required_argument, 0, OPTION_OBJECT},

            {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},

            {0, 0, 0, 0}

        };

        c = getopt_long(argc, argv, "f:hq",

                        long_options, NULL);

        if (c == -1) {

            break;

        }

        switch(c) {

        case '?':

        case 'h':

            help();

            break;

        case 'f':

            fmt = optarg;

            break;

        case 'q':

            quiet = true;

            break;

        case OPTION_OBJECT: {

            QemuOpts *opts;

            opts = qemu_opts_parse_noisily(&qemu_object_opts,

                                           optarg, true);

            if (!opts) {

                return 1;

            }

        }   break;

        case OPTION_IMAGE_OPTS:

            image_opts = true;

            break;

        }

    }

    if (optind != argc - 1) {

        error_exit("Expecting one image file name");

    }

    filename = argv[optind++];



    if (qemu_opts_foreach(&qemu_object_opts,

                          user_creatable_add_opts_foreach,

                          NULL, NULL)) {

        return 1;

    }



    /* Choose grow, shrink, or absolute resize mode */

    switch (size[0]) {

    case '+':

        relative = 1;

        size++;

        break;

    case '-':

        relative = -1;

        size++;

        break;

    default:

        relative = 0;

        break;

    }



    /* Parse size */

    param = qemu_opts_create(&resize_options, NULL, 0, &error_abort);

    qemu_opt_set(param, BLOCK_OPT_SIZE, size, &err);

    if (err) {

        error_report_err(err);

        ret = -1;

        qemu_opts_del(param);

        goto out;

    }

    n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);

    qemu_opts_del(param);



    blk = img_open(image_opts, filename, fmt,

                   BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet);

    if (!blk) {

        ret = -1;

        goto out;

    }



    if (relative) {

        total_size = blk_getlength(blk) + n * relative;

    } else {

        total_size = n;

    }

    if (total_size <= 0) {

        error_report("New image size must be positive");

        ret = -1;

        goto out;

    }



    ret = blk_truncate(blk, total_size);

    switch (ret) {

    case 0:

        qprintf(quiet, "Image resized.\n");

        break;

    case -ENOTSUP:

        error_report("This image does not support resize");

        break;

    case -EACCES:

        error_report("Image is read-only");

        break;

    default:

        error_report("Error resizing image: %s", strerror(-ret));

        break;

    }

out:

    blk_unref(blk);

    if (ret) {

        return 1;

    }

    return 0;

}

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

{

    Error *err = NULL;

    int c, ret, relative;

    const char *filename, *fmt, *size;

    int64_t n, total_size;

    bool quiet = false;

    BlockBackend *blk = NULL;

    QemuOpts *param;



    static QemuOptsList resize_options = {

        .name = "resize_options",

        .head = QTAILQ_HEAD_INITIALIZER(resize_options.head),

        .desc = {

            {

                .name = BLOCK_OPT_SIZE,

                .type = QEMU_OPT_SIZE,

                .help = "Virtual disk size"

            }, {

                

            }

        },

    };

    bool image_opts = false;



    



    if (argc < 3) {

        error_exit("Not enough arguments");

        return 1;

    }



    size = argv[--argc];



    

    fmt = NULL;

    for(;;) {

        static const struct option long_options[] = {

            {"help", no_argument, 0, 'h'},

            {"object", required_argument, 0, OPTION_OBJECT},

            {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},

            {0, 0, 0, 0}

        };

        c = getopt_long(argc, argv, "f:hq",

                        long_options, NULL);

        if (c == -1) {

            break;

        }

        switch(c) {

        case '?':

        case 'h':

            help();

            break;

        case 'f':

            fmt = optarg;

            break;

        case 'q':

            quiet = true;

            break;

        case OPTION_OBJECT: {

            QemuOpts *opts;

            opts = qemu_opts_parse_noisily(&qemu_object_opts,

                                           optarg, true);

            if (!opts) {

                return 1;

            }

        }   break;

        case OPTION_IMAGE_OPTS:

            image_opts = true;

            break;

        }

    }

    if (optind != argc - 1) {

        error_exit("Expecting one image file name");

    }

    filename = argv[optind++];



    if (qemu_opts_foreach(&qemu_object_opts,

                          user_creatable_add_opts_foreach,

                          NULL, NULL)) {

        return 1;

    }



    

    switch (size[0]) {

    case '+':

        relative = 1;

        size++;

        break;

    case '-':

        relative = -1;

        size++;

        break;

    default:

        relative = 0;

        break;

    }



    

    param = qemu_opts_create(&resize_options, NULL, 0, &error_abort);

    qemu_opt_set(param, BLOCK_OPT_SIZE, size, &err);

    if (err) {

        error_report_err(err);

        ret = -1;

        qemu_opts_del(param);

        goto out;

    }

    n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);

    qemu_opts_del(param);



    blk = img_open(image_opts, filename, fmt,

                   BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet);

    if (!blk) {

        ret = -1;

        goto out;

    }



    if (relative) {

        total_size = blk_getlength(blk) + n * relative;

    } else {

        total_size = n;

    }

    if (total_size <= 0) {

        error_report("New image size must be positive");

        ret = -1;

        goto out;

    }



    ret = blk_truncate(blk, total_size);

    switch (ret) {

    case 0:

        qprintf(quiet, "Image resized.\n");

        break;

    case -ENOTSUP:

        error_report("This image does not support resize");

        break;

    case -EACCES:

        error_report("Image is read-only");

        break;

    default:

        error_report("Error resizing image: %s", strerror(-ret));

        break;

    }

out:

    blk_unref(blk);

    if (ret) {

        return 1;

    }

    return 0;

}

        c = getopt_long(argc, argv, "f:hq",         case 'h':         case 'h':         case 'h':
static int FUNC_0(int VAR_0, char **VAR_1)

{

    Error *err = NULL;

    int VAR_2, VAR_3, VAR_4;

    const char *VAR_5, *VAR_6, *VAR_7;

    int64_t n, total_size;

    bool quiet = false;

    BlockBackend *blk = NULL;

    QemuOpts *param;



    static QemuOptsList VAR_8 = {

        .name = "VAR_8",

        .head = QTAILQ_HEAD_INITIALIZER(VAR_8.head),

        .desc = {

            {

                .name = BLOCK_OPT_SIZE,

                .type = QEMU_OPT_SIZE,

                .help = "Virtual disk VAR_7"

            }, {

                

            }

        },

    };

    bool image_opts = false;



    



    if (VAR_0 < 3) {

        error_exit("Not enough arguments");

        return 1;

    }



    VAR_7 = VAR_1[--VAR_0];



    

    VAR_6 = NULL;

    for(;;) {

        static const struct option VAR_9[] = {

            {"help", no_argument, 0, 'h'},

            {"object", required_argument, 0, OPTION_OBJECT},

            {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},

            {0, 0, 0, 0}

        };

        VAR_2 = getopt_long(VAR_0, VAR_1, "f:hq",

                        VAR_9, NULL);

        if (VAR_2 == -1) {

            break;

        }

        switch(VAR_2) {

        case '?':

        case 'h':

            help();

            break;

        case 'f':

            VAR_6 = optarg;

            break;

        case 'q':

            quiet = true;

            break;

        case OPTION_OBJECT: {

            QemuOpts *opts;

            opts = qemu_opts_parse_noisily(&qemu_object_opts,

                                           optarg, true);

            if (!opts) {

                return 1;

            }

        }   break;

        case OPTION_IMAGE_OPTS:

            image_opts = true;

            break;

        }

    }

    if (optind != VAR_0 - 1) {

        error_exit("Expecting one image file name");

    }

    VAR_5 = VAR_1[optind++];



    if (qemu_opts_foreach(&qemu_object_opts,

                          user_creatable_add_opts_foreach,

                          NULL, NULL)) {

        return 1;

    }



    

    switch (VAR_7[0]) {

    case '+':

        VAR_4 = 1;

        VAR_7++;

        break;

    case '-':

        VAR_4 = -1;

        VAR_7++;

        break;

    default:

        VAR_4 = 0;

        break;

    }



    

    param = qemu_opts_create(&VAR_8, NULL, 0, &error_abort);

    qemu_opt_set(param, BLOCK_OPT_SIZE, VAR_7, &err);

    if (err) {

        error_report_err(err);

        VAR_3 = -1;

        qemu_opts_del(param);

        goto out;

    }

    n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);

    qemu_opts_del(param);



    blk = img_open(image_opts, VAR_5, VAR_6,

                   BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet);

    if (!blk) {

        VAR_3 = -1;

        goto out;

    }



    if (VAR_4) {

        total_size = blk_getlength(blk) + n * VAR_4;

    } else {

        total_size = n;

    }

    if (total_size <= 0) {

        error_report("New image VAR_7 must be positive");

        VAR_3 = -1;

        goto out;

    }



    VAR_3 = blk_truncate(blk, total_size);

    switch (VAR_3) {

    case 0:

        qprintf(quiet, "Image resized.\n");

        break;

    case -ENOTSUP:

        error_report("This image does not support resize");

        break;

    case -EACCES:

        error_report("Image is read-only");

        break;

    default:

        error_report("Error resizing image: %s", strerror(-VAR_3));

        break;

    }

out:

    blk_unref(blk);

    if (VAR_3) {

        return 1;

    }

    return 0;

}

static int FUNC_0(int VAR_0, char **VAR_1)
{ Error *err = NULL; int VAR_2, VAR_3, VAR_4; const char *VAR_5, *VAR_6, *VAR_7; int64_t n, total_size; bool quiet = false; BlockBackend *blk = NULL; QemuOpts *param; static QemuOptsList VAR_8 = { .name = "VAR_8",
.head = QTAILQ_HEAD_INITIALIZER(VAR_8.head),
.desc = { { .name = BLOCK_OPT_SIZE,
.type = QEMU_OPT_SIZE,
.help = "Virtual disk VAR_7"
}, { } }, }; bool image_opts = false; if (VAR_0 < 3) { error_exit("Not enough arguments"); return 1; } VAR_7 = VAR_1[--VAR_0]; VAR_6 = NULL; for(;;) { static const struct option VAR_9[] = { {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; VAR_2 = getopt_long(VAR_0, VAR_1, "f:hq",
VAR_9, NULL); if (VAR_2 == -1) { break; } switch(VAR_2) { case '?':
case 'h':
help(); break; case 'f':
VAR_6 = optarg; break; case 'q':
quiet = true; break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts,
optarg, true); if (!opts) { return 1; } }   break; case OPTION_IMAGE_OPTS:
image_opts = true; break; } } if (optind != VAR_0 - 1) { error_exit("Expecting one image file name"); } VAR_5 = VAR_1[optind++]; if (qemu_opts_foreach(&qemu_object_opts,
user_creatable_add_opts_foreach,
NULL, NULL)) { return 1; } switch (VAR_7[0]) { case '+':
VAR_4 = 1; VAR_7++; break; case '-':
VAR_4 = -1; VAR_7++; break; default:
VAR_4 = 0; break; } param = qemu_opts_create(&VAR_8, NULL, 0, &error_abort); qemu_opt_set(param, BLOCK_OPT_SIZE, VAR_7, &err); if (err) { error_report_err(err); VAR_3 = -1; qemu_opts_del(param); goto out; } n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0); qemu_opts_del(param); blk = img_open(image_opts, VAR_5, VAR_6,
BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet); if (!blk) { VAR_3 = -1; goto out; } if (VAR_4) { total_size = blk_getlength(blk) + n * VAR_4; } else { total_size = n; } if (total_size <= 0) { error_report("New image VAR_7 must be positive"); VAR_3 = -1; goto out; } VAR_3 = blk_truncate(blk, total_size); switch (VAR_3) { case 0:
qprintf(quiet, "Image resized.\n"); break; case -ENOTSUP:
error_report("This image does not support resize"); break; case -EACCES:
error_report("Image is read-only"); break; default:
error_report("Error resizing image: %s", strerror(-VAR_3)); break; } out:
blk_unref(blk); if (VAR_3) { return 1; } return 0; }