aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2008-06-05 21:53:49 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2008-06-05 21:53:49 +0000
commitf58c7b354595228e10f023e86b80a7bab527186a (patch)
tree5cf33990d51f7f9e38cddcdef9cc30cfa194eae5 /block.c
parentff7ab59f40e12941530cb1d9ecc9b873d900b132 (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.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/block.c b/block.c
index bd647a6f47..2aaefe832f 100644
--- a/block.c
+++ b/block.c
@@ -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)
{