From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LRa9w-00065h-Au for qemu-devel@nongnu.org; Mon, 26 Jan 2009 17:42:24 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LRa9r-000636-Kf for qemu-devel@nongnu.org; Mon, 26 Jan 2009 17:42:23 -0500 Received: from [199.232.76.173] (port=35699 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LRa9r-00062t-De for qemu-devel@nongnu.org; Mon, 26 Jan 2009 17:42:19 -0500 Received: from mx2.redhat.com ([66.187.237.31]:44830) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LRa9q-0001ve-U3 for qemu-devel@nongnu.org; Mon, 26 Jan 2009 17:42:19 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n0QMgHDS012120 for ; Mon, 26 Jan 2009 17:42:17 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n0QMgHbe022156 for ; Mon, 26 Jan 2009 17:42:18 -0500 Received: from bree.surriel.com (vpn-10-5.bos.redhat.com [10.16.10.5]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n0QMgHMG017034 for ; Mon, 26 Jan 2009 17:42:17 -0500 Date: Mon, 26 Jan 2009 17:42:09 -0500 From: Rik van Riel Message-ID: <20090126174209.1690ef05@bree.surriel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] fix sector overflow for scsi disks >1TB large Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Sector numbers can overflow on a virtual scsi disk of over 1TB in size. Qemu's bdrv_read expects an int64_t, so fix the overflow by going to that data type. Also clip capacity to 2TB instead of returning "capacity modulo 2TB". Signed-off-by: Rik van Riel Index: trunk/hw/scsi-disk.c =================================================================== --- trunk/hw/scsi-disk.c (revision 6451) +++ trunk/hw/scsi-disk.c (working copy) @@ -50,7 +50,7 @@ /* ??? We should probably keep track of whether the data trasfer is a read or a write. Currently we rely on the host getting it right. */ /* Both sector and sector_count are in terms of qemu 512 byte blocks. */ - int sector; + uint64_t sector; int sector_count; /* The amounnt of data in the buffer. */ int buf_len; @@ -731,6 +731,9 @@ /* Returned value is the address of the last sector. */ if (nb_sectors) { nb_sectors--; + /* Clip to 2TB, instead of returning capacity modulo 2TB. */ + if (nb_sectors > UINT_MAX) + nb_sectors = UINT_MAX; outbuf[0] = (nb_sectors >> 24) & 0xff; outbuf[1] = (nb_sectors >> 16) & 0xff; outbuf[2] = (nb_sectors >> 8) & 0xff;