/* Please keep in synch with qemu-img.texi */
static void help(void)
{
- (printf)("qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2008 Fabrice Bellard\n"
- "usage: qemu-img command [command options]\n"
- "QEMU disk image utility\n"
- "\n"
- "Command syntax:\n"
+ const char *help_msg =
+ "qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2008 Fabrice Bellard\n"
+ "usage: qemu-img command [command options]\n"
+ "QEMU disk image utility\n"
+ "\n"
+ "Command syntax:\n"
#define DEF(option, callback, arg_string) \
" " arg_string "\n"
#include "qemu-img-cmds.h"
#undef DEF
#undef GEN_DOCS
- "\n"
- "Command parameters:\n"
- " 'filename' is a disk image filename\n"
- " 'fmt' is the disk image format. It is guessed automatically in most cases\n"
- " 'size' is the disk image size in bytes. Optional suffixes\n"
- " 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)\n"
- " and T (terabyte, 1024G) are supported. 'b' is ignored.\n"
- " 'output_filename' is the destination disk image filename\n"
- " 'output_fmt' is the destination format\n"
- " 'options' is a comma separated list of format specific options in a\n"
- " name=value format. Use -o ? for an overview of the options supported by the\n"
- " used format\n"
- " '-c' indicates that target image must be compressed (qcow format only)\n"
- " '-u' enables unsafe rebasing. It is assumed that old and new backing file\n"
- " match exactly. The image doesn't need a working backing file before\n"
- " rebasing in this case (useful for renaming the backing file)\n"
- " '-h' with or without a command shows this help and lists the supported formats\n"
- "\n"
- "Parameters to snapshot subcommand:\n"
- " 'snapshot' is the name of the snapshot to create, apply or delete\n"
- " '-a' applies a snapshot (revert disk to saved state)\n"
- " '-c' creates a snapshot\n"
- " '-d' deletes a snapshot\n"
- " '-l' lists all snapshots in the given image\n"
- );
- printf("\nSupported formats:");
+ "\n"
+ "Command parameters:\n"
+ " 'filename' is a disk image filename\n"
+ " 'fmt' is the disk image format. It is guessed automatically in most cases\n"
+ " 'size' is the disk image size in bytes. Optional suffixes\n"
+ " 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)\n"
+ " and T (terabyte, 1024G) are supported. 'b' is ignored.\n"
+ " 'output_filename' is the destination disk image filename\n"
+ " 'output_fmt' is the destination format\n"
+ " 'options' is a comma separated list of format specific options in a\n"
+ " name=value format. Use -o ? for an overview of the options supported by the\n"
+ " used format\n"
+ " '-c' indicates that target image must be compressed (qcow format only)\n"
+ " '-u' enables unsafe rebasing. It is assumed that old and new backing file\n"
+ " match exactly. The image doesn't need a working backing file before\n"
+ " rebasing in this case (useful for renaming the backing file)\n"
+ " '-h' with or without a command shows this help and lists the supported formats\n"
+ "\n"
+ "Parameters to snapshot subcommand:\n"
+ " 'snapshot' is the name of the snapshot to create, apply or delete\n"
+ " '-a' applies a snapshot (revert disk to saved state)\n"
+ " '-c' creates a snapshot\n"
+ " '-d' deletes a snapshot\n"
+ " '-l' lists all snapshots in the given image\n";
+
+ printf("%s\nSupported formats:", help_msg);
bdrv_iterate_format(format_print, NULL);
printf("\n");
exit(1);
#endif
static BlockDriverState *bdrv_new_open(const char *filename,
- const char *fmt)
+ const char *fmt,
+ int readonly)
{
BlockDriverState *bs;
BlockDriver *drv;
char password[256];
+ int flags = BRDV_O_FLAGS;
bs = bdrv_new("");
if (!bs)
} else {
drv = NULL;
}
- if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_RDWR, drv) < 0) {
+ if (!readonly) {
+ flags |= BDRV_O_RDWR;
+ }
+ if (bdrv_open2(bs, filename, flags, drv) < 0) {
error("Could not open '%s'", filename);
}
if (bdrv_is_encrypted(bs)) {
}
}
- bs = bdrv_new_open(backing_file->value.s, fmt);
+ bs = bdrv_new_open(backing_file->value.s, fmt, 1);
bdrv_get_geometry(bs, &size);
size *= 512;
bdrv_delete(bs);
BlockDriverState **bs, *out_bs;
int64_t total_sectors, nb_sectors, sector_num, bs_offset;
uint64_t bs_sectors;
- uint8_t buf[IO_BUF_SIZE];
+ uint8_t * buf;
const uint8_t *buf1;
BlockDriverInfo bdi;
QEMUOptionParameter *param = NULL;
total_sectors = 0;
for (bs_i = 0; bs_i < bs_n; bs_i++) {
- bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt);
+ bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, 1);
if (!bs[bs_i])
error("Could not open '%s'", argv[optind + bs_i]);
bdrv_get_geometry(bs[bs_i], &bs_sectors);
}
}
- out_bs = bdrv_new_open(out_filename, out_fmt);
+ out_bs = bdrv_new_open(out_filename, out_fmt, 0);
bs_i = 0;
bs_offset = 0;
bdrv_get_geometry(bs[0], &bs_sectors);
+ buf = qemu_malloc(IO_BUF_SIZE);
if (flags & BLOCK_FLAG_COMPRESS) {
if (bdrv_get_info(out_bs, &bdi) < 0)
}
}
}
+ qemu_free(buf);
bdrv_delete(out_bs);
for (bs_i = 0; bs_i < bs_n; bs_i++)
bdrv_delete(bs[bs_i]);
uint64_t num_sectors;
uint64_t sector;
int n, n1;
- uint8_t buf_old[IO_BUF_SIZE];
- uint8_t buf_new[IO_BUF_SIZE];
+ uint8_t * buf_old;
+ uint8_t * buf_new;
+
+ buf_old = qemu_malloc(IO_BUF_SIZE);
+ buf_new = qemu_malloc(IO_BUF_SIZE);
bdrv_get_geometry(bs, &num_sectors);
written += pnum;
}
}
+
+ qemu_free(buf_old);
+ qemu_free(buf_new);
}
/*