void help(void)
{
- printf("qemu-img version " QEMU_VERSION ", Copyright (c) 2004 Fabrice Bellard\n"
+ printf("qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2005 Fabrice Bellard\n"
"usage: qemu-img command [command options]\n"
"QEMU disk image utility\n"
"\n"
int i;
if (size <= 999) {
- snprintf(buf, buf_size, "%lld", size);
+ snprintf(buf, buf_size, "%lld", (long long) size);
} else {
base = 1024;
for(i = 0; i < NB_SUFFIXES; i++) {
break;
} else if (size < (1000 * base) || i == (NB_SUFFIXES - 1)) {
snprintf(buf, buf_size, "%lld%c",
- (size + (base >> 1)) / base,
+ (long long) ((size + (base >> 1)) / base),
suffixes[i]);
break;
}
}
#endif
+static BlockDriverState *bdrv_new_open(const char *filename,
+ const char *fmt)
+{
+ BlockDriverState *bs;
+ BlockDriver *drv;
+ char password[256];
+
+ bs = bdrv_new("");
+ if (!bs)
+ error("Not enough memory");
+ if (fmt) {
+ drv = bdrv_find_format(fmt);
+ if (!drv)
+ error("Unknown file format '%s'", fmt);
+ } else {
+ drv = NULL;
+ }
+ if (bdrv_open2(bs, filename, 0, drv) < 0) {
+ error("Could not open '%s'", filename);
+ }
+ if (bdrv_is_encrypted(bs)) {
+ printf("Disk image '%s' is encrypted.\n", filename);
+ if (read_password(password, sizeof(password)) < 0)
+ error("No password given");
+ if (bdrv_set_key(bs, password) < 0)
+ error("invalid password");
+ }
+ return bs;
+}
+
static int img_create(int argc, char **argv)
{
int c, ret, encrypted;
break;
}
}
- optind++;
if (optind >= argc)
help();
filename = argv[optind++];
size = 0;
- if (!base_filename) {
+ if (base_filename) {
+ BlockDriverState *bs;
+ bs = bdrv_new_open(base_filename, NULL);
+ bdrv_get_geometry(bs, &size);
+ size *= 512;
+ bdrv_delete(bs);
+ } else {
if (optind >= argc)
help();
p = argv[optind];
filename, fmt);
if (encrypted)
printf(", encrypted");
- if (base_filename)
- printf(", backing_file=%s\n",
+ if (base_filename) {
+ printf(", backing_file=%s",
base_filename);
- else
- printf(", size=%lld kB\n", size / 1024);
+ }
+ printf(", size=%lld kB\n", (long long) (size / 1024));
ret = bdrv_create(drv, filename, size / 512, base_filename, encrypted);
if (ret < 0) {
if (ret == -ENOTSUP) {
- error("Formatting or formatting option not suppored for file format '%s'", fmt);
+ error("Formatting or formatting option not supported for file format '%s'", fmt);
} else {
error("Error while formatting");
}
break;
}
}
- optind++;
if (optind >= argc)
help();
filename = argv[optind++];
return v;
}
-static BlockDriverState *bdrv_new_open(const char *filename,
- const char *fmt)
-{
- BlockDriverState *bs;
- BlockDriver *drv;
- char password[256];
-
- bs = bdrv_new("");
- if (!bs)
- error("Not enough memory");
- if (fmt) {
- drv = bdrv_find_format(fmt);
- if (!drv)
- error("Unknown file format '%s'", fmt);
- } else {
- drv = NULL;
- }
- if (bdrv_open2(bs, filename, 0, drv) < 0) {
- error("Could not open '%s'", filename);
- }
- if (bdrv_is_encrypted(bs)) {
- printf("Disk image '%s' is encrypted.\n", filename);
- if (read_password(password, sizeof(password)) < 0)
- error("No password given");
- if (bdrv_set_key(bs, password) < 0)
- error("invalid password");
- }
- return bs;
-}
-
#define IO_BUF_SIZE 65536
static int img_convert(int argc, char **argv)
break;
}
}
- optind++;
if (optind >= argc)
help();
filename = argv[optind++];
ret = bdrv_create(drv, out_filename, total_sectors, NULL, encrypt);
if (ret < 0) {
if (ret == -ENOTSUP) {
- error("Formatting not suppored for file format '%s'", fmt);
+ error("Formatting not supported for file format '%s'", fmt);
} else {
error("Error while formatting '%s'", out_filename);
}
break;
}
}
- optind++;
if (optind >= argc)
help();
filename = argv[optind++];
get_human_readable_size(size_buf, sizeof(size_buf), total_sectors * 512);
allocated_size = get_allocated_file_size(filename);
if (allocated_size < 0)
- error("Could not get file size '%s'", filename);
- get_human_readable_size(dsize_buf, sizeof(dsize_buf),
- allocated_size);
+ sprintf(dsize_buf, "unavailable");
+ else
+ get_human_readable_size(dsize_buf, sizeof(dsize_buf),
+ allocated_size);
printf("image: %s\n"
"file format: %s\n"
"virtual size: %s (%lld bytes)\n"
"disk size: %s\n",
filename, fmt_name, size_buf,
- total_sectors * 512,
+ (long long) (total_sectors * 512),
dsize_buf);
if (bdrv_is_encrypted(bs))
printf("encrypted: yes\n");
if (argc < 2)
help();
cmd = argv[1];
+ optind++;
if (!strcmp(cmd, "create")) {
img_create(argc, argv);
} else if (!strcmp(cmd, "commit")) {