From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOtJH-0007vZ-B3 for qemu-devel@nongnu.org; Tue, 02 Sep 2014 15:00:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XOtJ9-0002gL-T2 for qemu-devel@nongnu.org; Tue, 02 Sep 2014 15:00:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOtJ9-0002gC-DX for qemu-devel@nongnu.org; Tue, 02 Sep 2014 14:59:59 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s82IxwAb025972 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 2 Sep 2014 14:59:58 -0400 Message-ID: <540613AB.1080305@redhat.com> Date: Tue, 02 Sep 2014 20:59:55 +0200 From: Max Reitz MIME-Version: 1.0 References: <1409348727-17183-1-git-send-email-mreitz@redhat.com> <1409348727-17183-3-git-send-email-mreitz@redhat.com> <540100AB.4090004@redhat.com> In-Reply-To: <540100AB.4090004@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/2] docs/qcow2: Correct refcount_block_entries List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi On 30.08.2014 00:37, Eric Blake wrote: > On 08/29/2014 03:45 PM, Max Reitz wrote: >> A refblock entry may have a different size than 16 bits, it may even be >> smaller than a byte. Correct the refcount_block_entries calculation >> accordingly. >> >> Signed-off-by: Max Reitz >> --- >> docs/specs/qcow2.txt | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/docs/specs/qcow2.txt b/docs/specs/qcow2.txt >> index cfbc8b0..531c478 100644 >> --- a/docs/specs/qcow2.txt >> +++ b/docs/specs/qcow2.txt >> @@ -183,7 +183,7 @@ blocks and are exactly one cluster in size. >> Given a offset into the image file, the refcount of its cluster can be obtained >> as follows: >> >> - refcount_block_entries = (cluster_size / sizeof(uint16_t)) >> + refcount_block_entries = (cluster_size / (refcount_bits / 8)) >> > > Consider refcount_order == 0 (that is, no shared blocks, ALL blocks have > at most refcount 1). Then, refcount_bits is (1 << 0) == 1. But 1/8 in > integer math truncates to 0 (oops, division by zero is undefined); when > in reality, the expression you want here is (cluster_size * 8 / > refcount_bits). If it is integer division, that is. ;-) I'm counting on you accepting "cluster_size * 8 / refcount_bits" and not rejecting it because of a possible integer overflow. *g* Max