From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y546B-0002qD-Nu for qemu-devel@nongnu.org; Sat, 27 Dec 2014 22:01:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y5466-0002xA-Rz for qemu-devel@nongnu.org; Sat, 27 Dec 2014 22:00:55 -0500 Received: from mail-qa0-x231.google.com ([2607:f8b0:400d:c00::231]:43823) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5466-0002x6-N1 for qemu-devel@nongnu.org; Sat, 27 Dec 2014 22:00:50 -0500 Received: by mail-qa0-f49.google.com with SMTP id dc16so8094941qab.36 for ; Sat, 27 Dec 2014 19:00:50 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: Date: Sat, 27 Dec 2014 22:00:47 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: References: <6392322B-686D-496A-9E66-30C9F962355D@gmail.com> Subject: Re: [Qemu-devel] [PATCH v2] 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: Peter Maydell , Kevin Wolf Cc: qemu-devel qemu-devel On Dec 27, 2014, at 8:19 PM, Peter Maydell wrote: > On 28 December 2014 at 00:36, Programmingkid = wrote: >> The raw_getlength() function under Mac OS X incorrectly returned a = constant value instead of calculating the size of a real CD-ROM disc. = This patch fixes this problem and makes booting from a real CD-ROM disc = possible again under Mac OS X. >>=20 >> signed-off-by: John Arbuckle >=20 > Thanks. (My Mac doesn't have a cdrom...) >=20 >> --- >> block/raw-posix.c | 11 ++++++++++- >> 1 files changed, 10 insertions(+), 1 deletions(-) >>=20 >> diff --git a/block/raw-posix.c b/block/raw-posix.c >> index e51293a..d723133 100644 >> --- a/block/raw-posix.c >> +++ b/block/raw-posix.c >> @@ -1312,7 +1312,16 @@ again: >> if (size =3D=3D 0) >> #endif >> #if defined(__APPLE__) && defined(__MACH__) >> - size =3D LLONG_MAX; >> + // Query the number of sectors on the disk >=20 > I note in passing that this whole function is a total mess > -- look at that "if (size =3D=3D 0)" in the previous #ifdef... > However since I think it's impossible to both have the > previous #ifdef and this one enabled it won't cause an issue. I agree. This file needs a lot of work.=20 >=20 >> + uint64_t sectors =3D 0; >> + ioctl(fd, DKIOCGETBLOCKCOUNT, §ors); >=20 > You need to check the error return from these ioctl calls. >=20 >> + >> + // Query the size of each sector >> + uint32_t sectorSize =3D 0; >> + ioctl(fd, DKIOCGETBLOCKSIZE, §orSize); >> + >> + size =3D sectors * sectorSize; >> + //printf("size of disc =3D %d MB\n", size/(1024*1024)); >> #else >> size =3D lseek(fd, 0LL, SEEK_END); >> if (size < 0) { >=20 > Minor style issues you might want to fix for v2: > * use /* */ comments, not // > * declare variables only at the top of {} code blocks > * don't leave commented out debug printfs in code >=20 > thanks > -- PMM Here is version 2 of the patch. All the suggestions have been = implemented. signed-off-by: John Arbuckle --- block/raw-posix.c | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index e51293a..0148161 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1312,7 +1312,25 @@ again: if (size =3D=3D 0) #endif #if defined(__APPLE__) && defined(__MACH__) - size =3D LLONG_MAX; + #define IOCTL_ERROR_VALUE -1 + 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 IOCTL_ERROR_VALUE) { + printf("\n\nWarning: problem detected retrieving sector = count!\n\n"); + return -errno; + } + + /* Query the size of each sector */ + ret =3D ioctl(fd, DKIOCGETBLOCKSIZE, §orSize); + if(ret =3D=3D IOCTL_ERROR_VALUE) { + printf("\n\nWarning: problem detected retrieving sector = size!\n\n"); + return -errno; + } + size =3D sectors * sectorSize; #else size =3D lseek(fd, 0LL, SEEK_END); if (size < 0) { --=20 1.7.5.4