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

{

    int c, ret, relative;

    const char *filename, *fmt, *size;

    int64_t n, total_size;

    BlockDriverState *bs = 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 */

            }

        },

    };



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

     * as options by getopt. */

    if (argc < 3) {

        help();

        return 1;

    }



    size = argv[--argc];



    /* Parse getopt arguments */

    fmt = NULL;

    for(;;) {

        c = getopt(argc, argv, "f:h");

        if (c == -1) {

            break;

        }

        switch(c) {

        case '?':

        case 'h':

            help();

            break;

        case 'f':

            fmt = optarg;

            break;

        }

    }

    if (optind >= argc) {

        help();

    }

    filename = argv[optind++];



    /* 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, NULL);

    if (qemu_opt_set(param, BLOCK_OPT_SIZE, size)) {

        /* Error message already printed when size parsing fails */

        ret = -1;

        qemu_opts_del(param);

        goto out;

    }

    n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);

    qemu_opts_del(param);



    bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);

    if (!bs) {

        ret = -1;

        goto out;

    }



    if (relative) {

        total_size = bdrv_getlength(bs) + n * relative;

    } else {

        total_size = n;

    }

    if (total_size <= 0) {

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

        ret = -1;

        goto out;

    }



    ret = bdrv_truncate(bs, total_size);

    switch (ret) {

    case 0:

        printf("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 (%d)", -ret);

        break;

    }

out:

    if (bs) {

        bdrv_delete(bs);

    }

    if (ret) {

        return 1;

    }

    return 0;

}

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

{

    int c, ret, relative;

    const char *filename, *fmt, *size;

    int64_t n, total_size;

    BlockDriverState *bs = 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"

            }, {

                

            }

        },

    };



    



    if (argc < 3) {

        help();

        return 1;

    }



    size = argv[--argc];



    

    fmt = NULL;

    for(;;) {

        c = getopt(argc, argv, "f:h");

        if (c == -1) {

            break;

        }

        switch(c) {

        case '?':

        case 'h':

            help();

            break;

        case 'f':

            fmt = optarg;

            break;

        }

    }

    if (optind >= argc) {

        help();

    }

    filename = argv[optind++];



    

    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, NULL);

    if (qemu_opt_set(param, BLOCK_OPT_SIZE, size)) {

        

        ret = -1;

        qemu_opts_del(param);

        goto out;

    }

    n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);

    qemu_opts_del(param);



    bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);

    if (!bs) {

        ret = -1;

        goto out;

    }



    if (relative) {

        total_size = bdrv_getlength(bs) + n * relative;

    } else {

        total_size = n;

    }

    if (total_size <= 0) {

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

        ret = -1;

        goto out;

    }



    ret = bdrv_truncate(bs, total_size);

    switch (ret) {

    case 0:

        printf("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 (%d)", -ret);

        break;

    }

out:

    if (bs) {

        bdrv_delete(bs);

    }

    if (ret) {

        return 1;

    }

    return 0;

}

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

{

    int VAR_2, VAR_3, VAR_4;

    const char *VAR_5, *VAR_6, *VAR_7;

    int64_t n, total_size;

    BlockDriverState *bs = 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"

            }, {

                

            }

        },

    };



    



    if (VAR_0 < 3) {

        help();

        return 1;

    }



    VAR_7 = VAR_1[--VAR_0];



    

    VAR_6 = NULL;

    for(;;) {

        VAR_2 = getopt(VAR_0, VAR_1, "f:h");

        if (VAR_2 == -1) {

            break;

        }

        switch(VAR_2) {

        case '?':

        case 'h':

            help();

            break;

        case 'f':

            VAR_6 = optarg;

            break;

        }

    }

    if (optind >= VAR_0) {

        help();

    }

    VAR_5 = VAR_1[optind++];



    

    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, NULL);

    if (qemu_opt_set(param, BLOCK_OPT_SIZE, VAR_7)) {

        

        VAR_3 = -1;

        qemu_opts_del(param);

        goto out;

    }

    n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);

    qemu_opts_del(param);



    bs = bdrv_new_open(VAR_5, VAR_6, BDRV_O_FLAGS | BDRV_O_RDWR);

    if (!bs) {

        VAR_3 = -1;

        goto out;

    }



    if (VAR_4) {

        total_size = bdrv_getlength(bs) + 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 = bdrv_truncate(bs, total_size);

    switch (VAR_3) {

    case 0:

        printf("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 (%d)", -VAR_3);

        break;

    }

out:

    if (bs) {

        bdrv_delete(bs);

    }

    if (VAR_3) {

        return 1;

    }

    return 0;

}

static int FUNC_0(int VAR_0, char **VAR_1)
{ int VAR_2, VAR_3, VAR_4; const char *VAR_5, *VAR_6, *VAR_7; int64_t n, total_size; BlockDriverState *bs = 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"
}, { } }, }; if (VAR_0 < 3) { help(); return 1; } VAR_7 = VAR_1[--VAR_0]; VAR_6 = NULL; for(;;) { VAR_2 = getopt(VAR_0, VAR_1, "f:h"); if (VAR_2 == -1) { break; } switch(VAR_2) { case '?':
case 'h':
help(); break; case 'f':
VAR_6 = optarg; break; } } if (optind >= VAR_0) { help(); } VAR_5 = VAR_1[optind++]; 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, NULL); if (qemu_opt_set(param, BLOCK_OPT_SIZE, VAR_7)) { VAR_3 = -1; qemu_opts_del(param); goto out; } n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0); qemu_opts_del(param); bs = bdrv_new_open(VAR_5, VAR_6, BDRV_O_FLAGS | BDRV_O_RDWR); if (!bs) { VAR_3 = -1; goto out; } if (VAR_4) { total_size = bdrv_getlength(bs) + 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 = bdrv_truncate(bs, total_size); switch (VAR_3) { case 0:
printf("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 (%d)", -VAR_3); break; } out:
if (bs) { bdrv_delete(bs); } if (VAR_3) { return 1; } return 0; }