Commit d15a771da15513560371443bd361abbcf51f70b8
1 parent
a9465922
qcow2 is now used for '-snapshot' - keep BlockDriverState.total_sectors
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2094 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
7 additions
and
8 deletions
block.c
@@ -296,7 +296,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, | @@ -296,7 +296,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, | ||
296 | bdrv_delete(bs1); | 296 | bdrv_delete(bs1); |
297 | 297 | ||
298 | get_tmp_filename(tmp_filename, sizeof(tmp_filename)); | 298 | get_tmp_filename(tmp_filename, sizeof(tmp_filename)); |
299 | - if (bdrv_create(&bdrv_qcow, tmp_filename, | 299 | + if (bdrv_create(&bdrv_qcow2, tmp_filename, |
300 | total_size, filename, 0) < 0) { | 300 | total_size, filename, 0) < 0) { |
301 | return -1; | 301 | return -1; |
302 | } | 302 | } |
@@ -335,7 +335,9 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, | @@ -335,7 +335,9 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, | ||
335 | qemu_free(bs->opaque); | 335 | qemu_free(bs->opaque); |
336 | return ret; | 336 | return ret; |
337 | } | 337 | } |
338 | - | 338 | + if (drv->bdrv_getlength) { |
339 | + bs->total_sectors = bdrv_getlength(bs) >> SECTOR_BITS; | ||
340 | + } | ||
339 | #ifndef _WIN32 | 341 | #ifndef _WIN32 |
340 | if (bs->is_temporary) { | 342 | if (bs->is_temporary) { |
341 | unlink(filename); | 343 | unlink(filename); |
@@ -647,11 +649,7 @@ int64_t bdrv_getlength(BlockDriverState *bs) | @@ -647,11 +649,7 @@ int64_t bdrv_getlength(BlockDriverState *bs) | ||
647 | 649 | ||
648 | void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr) | 650 | void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr) |
649 | { | 651 | { |
650 | - int64_t size; | ||
651 | - size = bdrv_getlength(bs); | ||
652 | - if (size < 0) | ||
653 | - size = 0; | ||
654 | - *nb_sectors_ptr = size >> SECTOR_BITS; | 652 | + *nb_sectors_ptr = bs->total_sectors; |
655 | } | 653 | } |
656 | 654 | ||
657 | /* force a given boot sector. */ | 655 | /* force a given boot sector. */ |
block_int.h
@@ -73,7 +73,8 @@ struct BlockDriver { | @@ -73,7 +73,8 @@ struct BlockDriver { | ||
73 | }; | 73 | }; |
74 | 74 | ||
75 | struct BlockDriverState { | 75 | struct BlockDriverState { |
76 | - int64_t total_sectors; /* XXX: will be suppressed */ | 76 | + int64_t total_sectors; /* if we are reading a disk image, give its |
77 | + size in sectors */ | ||
77 | int read_only; /* if true, the media is read only */ | 78 | int read_only; /* if true, the media is read only */ |
78 | int inserted; /* if true, the media is present */ | 79 | int inserted; /* if true, the media is present */ |
79 | int removable; /* if true, the media can be removed */ | 80 | int removable; /* if true, the media can be removed */ |