bdrv_get_mapping will be used when it is defined, otherwise default to old behaviour.
Signed-off-by: Devin Nakamura <devin...@gmail.com> --- qemu-io.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index a553d0c..caf51fe 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -1543,7 +1543,7 @@ static const cmdinfo_t alloc_cmd = { .oneline = "checks if a sector is present in the file", }; -static int map_f(int argc, char **argv) +static int map_f_old(int argc, char **argv) { int64_t offset; int64_t nb_sectors; @@ -1570,6 +1570,27 @@ static int map_f(int argc, char **argv) return 0; } +static int map_f(int argc, char **argv) +{ + uint64_t host_offset, guest_offset, count; + int ret; + + if (!bs->drv->bdrv_get_mapping) { + return map_f_old(argc, argv); + } + + guest_offset = count = 0; + printf(" Guest Offset - Host Offset - Count\n"); + do { + ret = bdrv_get_mapping(bs, &guest_offset, &host_offset, &count); + if (count) { + printf("%016lx - %016lx - %016lx\n", guest_offset, host_offset, + count); + } + } while (!ret && count > 0); + return ret; +} + static const cmdinfo_t map_cmd = { .name = "map", .argmin = 0, -- 1.7.6.rc1