diff options
author | ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162> | 2008-06-05 21:53:49 +0000 |
---|---|---|
committer | ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162> | 2008-06-05 21:53:49 +0000 |
commit | f58c7b354595228e10f023e86b80a7bab527186a (patch) | |
tree | 5cf33990d51f7f9e38cddcdef9cc30cfa194eae5 /block.c | |
parent | ff7ab59f40e12941530cb1d9ecc9b873d900b132 (diff) |
New qemu-img convert -B option, by Marc Bevand.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4672 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -884,6 +884,33 @@ void bdrv_flush(BlockDriverState *bs) bdrv_flush(bs->backing_hd); } +/* + * Returns true iff the specified sector is present in the disk image. Drivers + * not implementing the functionality are assumed to not support backing files, + * hence all their sectors are reported as allocated. + * + * 'pnum' is set to the number of sectors (including and immediately following + * the specified sector) that are known to be in the same + * allocated/unallocated state. + * + * 'nb_sectors' is the max value 'pnum' should be set to. + */ +int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, + int *pnum) +{ + int64_t n; + if (!bs->drv->bdrv_is_allocated) { + if (sector_num >= bs->total_sectors) { + *pnum = 0; + return 0; + } + n = bs->total_sectors - sector_num; + *pnum = (n < nb_sectors) ? (n) : (nb_sectors); + return 1; + } + return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum); +} + #ifndef QEMU_IMG void bdrv_info(void) { |