From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YDKZE-0008Ry-AZ for qemu-devel@nongnu.org; Mon, 19 Jan 2015 17:13:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YDKZ9-0004tj-9p for qemu-devel@nongnu.org; Mon, 19 Jan 2015 17:13:04 -0500 Received: from mail-qa0-x232.google.com ([2607:f8b0:400d:c00::232]:36573) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YDKZ9-0004sx-5r for qemu-devel@nongnu.org; Mon, 19 Jan 2015 17:12:59 -0500 Received: by mail-qa0-f50.google.com with SMTP id k15so25950747qaq.9 for ; Mon, 19 Jan 2015 14:12:58 -0800 (PST) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 19 Jan 2015 17:12:55 -0500 Message-Id: <2ACCDD16-AFEC-49BF-8BD3-3A3EC55DB2E5@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH v8] block/raw-posix.c: Fix raw_getlength() on Mac OS X for CD List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel qemu-devel Subject was: Re: [PATCH v7] block/raw-posix.c: Fixes raw_getlength() on Mac OS X so that it reports the correct length of a real CD This patch allows Mac OS X to use a real CDROM disc in QEMU. Testing this patch will require using QEMU v2.2.0 because the current git version has a bug in it that prevents /dev/cdrom from being used. "make check" did pass and my Debian boot disc did work. Signed-off-by: John Arbuckle --- Fixed code indentation to be inline with removed size = LLONG_MAX. block/raw-posix.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index e51293a..fa431b2 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1312,7 +1312,20 @@ again: if (size == 0) #endif #if defined(__APPLE__) && defined(__MACH__) - size = LLONG_MAX; + { + uint64_t sectors = 0; + uint32_t sector_size = 0; + + if (ioctl(fd, DKIOCGETBLOCKCOUNT, §ors) == 0 + && ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) == 0) { + size = sectors * sector_size; + } else { + size = lseek(fd, 0LL, SEEK_END); + if (size < 0) { + return -errno; + } + } + } #else size = lseek(fd, 0LL, SEEK_END); if (size < 0) { -- 1.7.5.4