#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);
}
/*