mirror of https://github.com/xqemu/xqemu.git
fixed image creation with base filename
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1056 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
7c08dbf325
commit
75c2380584
76
qemu-img.c
76
qemu-img.c
|
@ -273,6 +273,36 @@ int read_password(char *buf, int buf_size)
|
||||||
}
|
}
|
||||||
#endif
|
#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)
|
static int img_create(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c, ret, encrypted;
|
int c, ret, encrypted;
|
||||||
|
@ -308,7 +338,13 @@ static int img_create(int argc, char **argv)
|
||||||
help();
|
help();
|
||||||
filename = argv[optind++];
|
filename = argv[optind++];
|
||||||
size = 0;
|
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)
|
if (optind >= argc)
|
||||||
help();
|
help();
|
||||||
p = argv[optind];
|
p = argv[optind];
|
||||||
|
@ -330,11 +366,11 @@ static int img_create(int argc, char **argv)
|
||||||
filename, fmt);
|
filename, fmt);
|
||||||
if (encrypted)
|
if (encrypted)
|
||||||
printf(", encrypted");
|
printf(", encrypted");
|
||||||
if (base_filename)
|
if (base_filename) {
|
||||||
printf(", backing_file=%s\n",
|
printf(", backing_file=%s",
|
||||||
base_filename);
|
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);
|
ret = bdrv_create(drv, filename, size / 512, base_filename, encrypted);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (ret == -ENOTSUP) {
|
if (ret == -ENOTSUP) {
|
||||||
|
@ -437,36 +473,6 @@ static int is_allocated_sectors(const uint8_t *buf, int n, int *pnum)
|
||||||
return v;
|
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
|
#define IO_BUF_SIZE 65536
|
||||||
|
|
||||||
static int img_convert(int argc, char **argv)
|
static int img_convert(int argc, char **argv)
|
||||||
|
|
Loading…
Reference in New Issue