summaryrefslogtreecommitdiffstats
path: root/qemu-img.c
diff options
context:
space:
mode:
authorbellard2004-08-27 23:28:58 +0200
committerbellard2004-08-27 23:28:58 +0200
commit75c238058423fba689599dda4bed2b5bb7634570 (patch)
treeebf4cbf6b340273973f1b1fe79c2d5e8cf1e2412 /qemu-img.c
parentendianness fix (diff)
downloadqemu-75c238058423fba689599dda4bed2b5bb7634570.tar.gz
qemu-75c238058423fba689599dda4bed2b5bb7634570.tar.xz
qemu-75c238058423fba689599dda4bed2b5bb7634570.zip
fixed image creation with base filename
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1056 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'qemu-img.c')
-rw-r--r--qemu-img.c76
1 files changed, 41 insertions, 35 deletions
diff --git a/qemu-img.c b/qemu-img.c
index cdb0ea1244..5f83622358 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -273,6 +273,36 @@ int read_password(char *buf, int buf_size)
}
#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;
@@ -308,7 +338,13 @@ static int img_create(int argc, char **argv)
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];
@@ -330,11 +366,11 @@ static int img_create(int argc, char **argv)
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", size / 1024);
ret = bdrv_create(drv, filename, size / 512, base_filename, encrypted);
if (ret < 0) {
if (ret == -ENOTSUP) {
@@ -437,36 +473,6 @@ static int is_allocated_sectors(const uint8_t *buf, int n, int *pnum)
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)