Am 21.01.2013 17:27, schrieb Eric Blake: > On 01/21/2013 07:25 AM, Federico Simoncelli wrote: >> This patch adds the support for reporting the highest offset in use by >> an image. This is particularly useful after a conversion (or a rebase) >> where the destination is a block device in order to find the actual >> amount of space in use. >> >> Signed-off-by: Federico Simoncelli <fsimo...@redhat.com> >> --- >> block/qcow2-refcount.c | 10 ++++++++-- >> include/block/block.h | 1 + >> qemu-img.c | 4 ++++ >> tests/qemu-iotests/026 | 6 +++--- >> tests/qemu-iotests/036 | 3 ++- >> tests/qemu-iotests/039 | 2 +- >> tests/qemu-iotests/044.out | 1 + >> tests/qemu-iotests/common.rc | 5 +++-- >> 8 files changed, 23 insertions(+), 9 deletions(-) >> > >> @@ -1231,6 +1236,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, >> BdrvCheckResult *res, >> } >> } >> >> + res->highest_offset = (highest_cluster + 1) * s->cluster_size; > > That's actually one byte larger than the actual highest offset in use. > That is, if I have a file with exactly 4096 bytes, this computation > would return 4096 (the file size) rather than 4095 (the last offset in use). > >> +++ b/qemu-img.c >> @@ -475,6 +475,10 @@ static int img_check(int argc, char **argv) >> result.bfi.fragmented_clusters * 100.0 / >> result.bfi.allocated_clusters); >> } >> >> + if (result.highest_offset > 0) { >> + printf("Highest offset in use: %" PRId64 "\n", >> result.highest_offset); > > This output message feels off by one. Either you need to subtract 1 > from res->highest_offset to get the address of the last used byte, or > you need to document it as the first unused byte, or instead of calling > it 'highest offset', you should call it 'used bytes' (except that with > sparse files, it's hard to argue that all earlier bytes were 'used').
Good point. I think the number is what we wanted, and what users are interested in is probably "used bytes" rather than "first unused byte". Maybe we can find a better word for "used" (it has the same problem in all three contexts), but I can't think of one off the top of my head. Kevin