diff options
author | ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162> | 2007-09-16 21:59:02 +0000 |
---|---|---|
committer | ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162> | 2007-09-16 21:59:02 +0000 |
commit | ec36ba14748e140dda237ba22ad3135e360b0d9f (patch) | |
tree | bcaa0fe4961882998a3acb19f225be006ab92a57 | |
parent | 3ae43202754711808ea5186e327bfd0533dd88fc (diff) |
vmdk compatibility level 6 images, by Soren Hansen.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3175 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r-- | block-qcow.c | 2 | ||||
-rw-r--r-- | block-qcow2.c | 2 | ||||
-rw-r--r-- | block-vmdk.c | 4 | ||||
-rw-r--r-- | block_int.h | 4 | ||||
-rw-r--r-- | qemu-img.c | 49 | ||||
-rw-r--r-- | qemu-img.texi | 8 |
6 files changed, 43 insertions, 26 deletions
diff --git a/block-qcow.c b/block-qcow.c index 208e35cca6..1f44355b2f 100644 --- a/block-qcow.c +++ b/block-qcow.c @@ -769,7 +769,7 @@ static int qcow_create(const char *filename, int64_t total_size, l1_size = ((total_size * 512) + (1LL << shift) - 1) >> shift; header.l1_table_offset = cpu_to_be64(header_size); - if (flags) { + if (flags & BLOCK_FLAG_ENCRYPT) { header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES); } else { header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE); diff --git a/block-qcow2.c b/block-qcow2.c index 2df0615440..fca1d03c46 100644 --- a/block-qcow2.c +++ b/block-qcow2.c @@ -1076,7 +1076,7 @@ static int qcow_create(const char *filename, int64_t total_size, s->cluster_size = 1 << s->cluster_bits; header.cluster_bits = cpu_to_be32(s->cluster_bits); header_size = (header_size + 7) & ~7; - if (flags) { + if (flags & BLOCK_FLAG_ENCRYPT) { header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES); } else { header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE); diff --git a/block-vmdk.c b/block-vmdk.c index 197fb5a620..436241c79b 100644 --- a/block-vmdk.c +++ b/block-vmdk.c @@ -712,7 +712,7 @@ static int vmdk_create(const char *filename, int64_t total_size, "# The Disk Data Base \n" "#DDB\n" "\n" - "ddb.virtualHWVersion = \"4\"\n" + "ddb.virtualHWVersion = \"%d\"\n" "ddb.geometry.cylinders = \"%lu\"\n" "ddb.geometry.heads = \"16\"\n" "ddb.geometry.sectors = \"63\"\n" @@ -789,7 +789,7 @@ static int vmdk_create(const char *filename, int64_t total_size, if ((temp_str = strrchr(real_filename, ':')) != NULL) real_filename = temp_str + 1; sprintf(desc, desc_template, time(NULL), (unsigned long)total_size, - real_filename, total_size / (63 * 16)); + real_filename, (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4), total_size / (63 * 16)); /* write the descriptor */ lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET); diff --git a/block_int.h b/block_int.h index e8fff77a01..3565941458 100644 --- a/block_int.h +++ b/block_int.h @@ -24,6 +24,10 @@ #ifndef BLOCK_INT_H #define BLOCK_INT_H +#define BLOCK_FLAG_ENCRYPT 1 +#define BLOCK_FLAG_COMPRESS 2 +#define BLOCK_FLAG_COMPAT6 4 + struct BlockDriver { const char *format_name; int instance_size; diff --git a/qemu-img.c b/qemu-img.c index 6712f81fdb..aa3d719a86 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ #include "vl.h" +#include "block_int.h" #ifdef _WIN32 #include <windows.h> @@ -98,9 +99,9 @@ void help(void) "QEMU disk image utility\n" "\n" "Command syntax:\n" - " create [-e] [-b base_image] [-f fmt] filename [size]\n" + " create [-e] [-6] [-b base_image] [-f fmt] filename [size]\n" " commit [-f fmt] filename\n" - " convert [-c] [-e] [-f fmt] filename [-O output_fmt] output_filename\n" + " convert [-c] [-e] [-6] [-f fmt] filename [-O output_fmt] output_filename\n" " info [-f fmt] filename\n" "\n" "Command parameters:\n" @@ -114,6 +115,7 @@ void help(void) " 'output_fmt' is the destination format\n" " '-c' indicates that target image must be compressed (qcow format only)\n" " '-e' indicates that the target image must be encrypted (qcow format only)\n" + " '-6' indicates that the target image must use compatibility level 6 (vmdk format only)\n" ); printf("\nSupported format:"); bdrv_iterate_format(format_print, NULL); @@ -241,7 +243,7 @@ static BlockDriverState *bdrv_new_open(const char *filename, static int img_create(int argc, char **argv) { - int c, ret, encrypted; + int c, ret, flags; const char *fmt = "raw"; const char *filename; const char *base_filename = NULL; @@ -249,9 +251,9 @@ static int img_create(int argc, char **argv) const char *p; BlockDriver *drv; - encrypted = 0; + flags = 0; for(;;) { - c = getopt(argc, argv, "b:f:he"); + c = getopt(argc, argv, "b:f:he6"); if (c == -1) break; switch(c) { @@ -265,8 +267,11 @@ static int img_create(int argc, char **argv) fmt = optarg; break; case 'e': - encrypted = 1; + flags |= BLOCK_FLAG_ENCRYPT; break; + case '6': + flags |= BLOCK_FLAG_COMPAT6; + break; } } if (optind >= argc) @@ -299,14 +304,16 @@ static int img_create(int argc, char **argv) error("Unknown file format '%s'", fmt); printf("Formatting '%s', fmt=%s", filename, fmt); - if (encrypted) + if (flags & BLOCK_FLAG_ENCRYPT) printf(", encrypted"); + if (flags & BLOCK_FLAG_COMPAT6) + printf(", compatibility level=6"); if (base_filename) { printf(", backing_file=%s", base_filename); } printf(", size=%" PRId64 " kB\n", (int64_t) (size / 1024)); - ret = bdrv_create(drv, filename, size / 512, base_filename, encrypted); + ret = bdrv_create(drv, filename, size / 512, base_filename, flags); if (ret < 0) { if (ret == -ENOTSUP) { error("Formatting or formatting option not supported for file format '%s'", fmt); @@ -411,7 +418,7 @@ static int is_allocated_sectors(const uint8_t *buf, int n, int *pnum) static int img_convert(int argc, char **argv) { - int c, ret, n, n1, compress, cluster_size, cluster_sectors, encrypt; + int c, ret, n, n1, flags, cluster_size, cluster_sectors; const char *filename, *fmt, *out_fmt, *out_filename; BlockDriver *drv; BlockDriverState *bs, *out_bs; @@ -422,10 +429,9 @@ static int img_convert(int argc, char **argv) fmt = NULL; out_fmt = "raw"; - compress = 0; - encrypt = 0; + flags = 0; for(;;) { - c = getopt(argc, argv, "f:O:hce"); + c = getopt(argc, argv, "f:O:hce6"); if (c == -1) break; switch(c) { @@ -439,10 +445,13 @@ static int img_convert(int argc, char **argv) out_fmt = optarg; break; case 'c': - compress = 1; + flags |= BLOCK_FLAG_COMPRESS; break; case 'e': - encrypt = 1; + flags |= BLOCK_FLAG_ENCRYPT; + break; + case '6': + flags |= BLOCK_FLAG_COMPAT6; break; } } @@ -458,14 +467,16 @@ static int img_convert(int argc, char **argv) drv = bdrv_find_format(out_fmt); if (!drv) error("Unknown file format '%s'", out_fmt); - if (compress && drv != &bdrv_qcow && drv != &bdrv_qcow2) + if (flags & BLOCK_FLAG_COMPRESS && drv != &bdrv_qcow && drv != &bdrv_qcow2) error("Compression not supported for this file format"); - if (encrypt && drv != &bdrv_qcow && drv != &bdrv_qcow2) + if (flags & BLOCK_FLAG_ENCRYPT && drv != &bdrv_qcow && drv != &bdrv_qcow2) error("Encryption not supported for this file format"); - if (compress && encrypt) + if (flags & BLOCK_FLAG_COMPRESS && drv != &bdrv_vmdk) + error("Alternative compatibility level not supported for this file format"); + if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS) error("Compression and encryption not supported at the same time"); bdrv_get_geometry(bs, &total_sectors); - ret = bdrv_create(drv, out_filename, total_sectors, NULL, encrypt); + ret = bdrv_create(drv, out_filename, total_sectors, NULL, flags); if (ret < 0) { if (ret == -ENOTSUP) { error("Formatting not supported for file format '%s'", fmt); @@ -476,7 +487,7 @@ static int img_convert(int argc, char **argv) out_bs = bdrv_new_open(out_filename, out_fmt); - if (compress) { + if (flags && BLOCK_FLAG_COMPRESS) { if (bdrv_get_info(out_bs, &bdi) < 0) error("could not get block driver info"); cluster_size = bdi.cluster_size; diff --git a/qemu-img.texi b/qemu-img.texi index 5b99dff0aa..89f912df97 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -8,9 +8,9 @@ usage: qemu-img command [command options] The following commands are supported: @table @option -@item create [-e] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}] +@item create [-e] [-6] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}] @item commit [-f @var{fmt}] @var{filename} -@item convert [-c] [-e] [-f @var{fmt}] @var{filename} [-O @var{output_fmt}] @var{output_filename} +@item convert [-c] [-e] [-6] [-f @var{fmt}] @var{filename} [-O @var{output_fmt}] @var{output_filename} @item info [-f @var{fmt}] @var{filename} @end table @@ -67,12 +67,14 @@ is the destination disk image filename indicates that target image must be compressed (qcow format only) @item -e indicates that the target image must be encrypted (qcow format only) +@item -6 +indicates that the target image must use compatibility level 6 (vmdk format only) @end table Command description: @table @option -@item create [-e] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}] +@item create [-6] [-e] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}] Create the new disk image @var{filename} of size @var{size} and format @var{fmt}. |