Received: from eggs.gnu.org ([2001:4830:134:3::10]:41480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5LEb-0003CI-Ae for qemu-devel@nongnu.org; Sun, 28 Dec 2014 16:18:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y5LEY-0002De-34 for qemu-devel@nongnu.org; Sun, 28 Dec 2014 16:18:45 -0500 Received: from mail-qc0-x234.google.com ([2607:f8b0:400d:c01::234]:64251) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5LEX-0002DV-Ur for qemu-devel@nongnu.org; Sun, 28 Dec 2014 16:18:42 -0500 Received: by mail-qc0-f180.google.com with SMTP id i8so8621840qcq.25 for ; Sun, 28 Dec 2014 13:18:41 -0800 (PST) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Sun, 28 Dec 2014 16:18:38 -0500 Message-Id: <96FCDECA-CC6E-4E30-A812-40FA3CA78C31@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH v3] block/raw-posix.c: Fixes raw_getlength() on Mac OS X so that it reports the correct length of a real CD List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel qemu-devel Cc: Kevin Wolf , Peter Maydell This patch fixes the problem with raw_getlength() on Mac OS X so that it = actually calculates the correct size of a volume. It has been updated to = fix certain coding style issues. Booting and using a real CD in QEMU = works again.=20 signed-off-by: John Arbuckle --- block/raw-posix.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index e51293a..a090c9c 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1312,7 +1312,24 @@ again: if (size =3D=3D 0) #endif #if defined(__APPLE__) && defined(__MACH__) - size =3D LLONG_MAX; + { + uint64_t sectors =3D 0; + uint32_t sectorSize =3D 0; + int ret; + + /* Query the number of sectors on the disk */ + ret =3D ioctl(fd, DKIOCGETBLOCKCOUNT, §ors); + if (ret =3D=3D -1) { + return -errno; + } + + /* Query the size of each sector */ + ret =3D ioctl(fd, DKIOCGETBLOCKSIZE, §orSize); + if (ret =3D=3D -1) { + return -errno; + } + size =3D sectors * sectorSize; + } #else size =3D lseek(fd, 0LL, SEEK_END); if (size < 0) { --=20 1.7.5.4