Received: from eggs.gnu.org ([2001:4830:134:3::10]:38301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YB6Ay-0001sI-Vj for qemu-devel@nongnu.org; Tue, 13 Jan 2015 13:26:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YB6Au-0000Cx-Tf for qemu-devel@nongnu.org; Tue, 13 Jan 2015 13:26:48 -0500 Received: from mail-qa0-x22a.google.com ([2607:f8b0:400d:c00::22a]:39421) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YB6Au-0000Ct-OR for qemu-devel@nongnu.org; Tue, 13 Jan 2015 13:26:44 -0500 Received: by mail-qa0-f42.google.com with SMTP id dc16so3318939qab.1 for ; Tue, 13 Jan 2015 10:26:44 -0800 (PST) From: Programmingkid Content-Type: multipart/alternative; boundary=Apple-Mail-1-484770238 Date: Tue, 13 Jan 2015 13:26:41 -0500 Message-Id: Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH v5] 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: Peter Maydell , Stefan Hajnoczi --Apple-Mail-1-484770238 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Allows for using real cdrom disc in QEMU under Mac OS X. This command was used to see if this patch worked: ./qemu-system-i386 -drive if=3Dnone,id=3Ddrive0,file=3D/dev/null,format=3D= raw Signed-off-by: John Arbuckle --- Replaced -errno with 0 for ioctl() failure return value. "make check" now passes with this patch. block/raw-posix.c | 18 +++++++++++++++++- configure | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index e51293a..16fa0a4 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1312,7 +1312,23 @@ again: if (size =3D=3D 0) #endif #if defined(__APPLE__) && defined(__MACH__) - size =3D LLONG_MAX; + { + uint64_t sectors =3D 0; + uint32_t sector_size =3D 0; + + /* Query the number of sectors on the disk */ + ret =3D ioctl(fd, DKIOCGETBLOCKCOUNT, §ors); + if (ret =3D=3D -1) { + return 0; + } + + /* Query the size of each sector */ + ret =3D ioctl(fd, DKIOCGETBLOCKSIZE, §or_size); + if (ret =3D=3D -1) { + return 0; + } + size =3D sectors * sector_size; + } #else size =3D lseek(fd, 0LL, SEEK_END); if (size < 0) { diff --git a/configure b/configure index cae588c..32d3d3f 100755 --- a/configure +++ b/configure @@ -611,7 +611,7 @@ Darwin) cocoa=3D"yes" audio_drv_list=3D"coreaudio" audio_possible_drivers=3D"coreaudio sdl fmod" - LDFLAGS=3D"-framework CoreFoundation -framework IOKit $LDFLAGS" + LDFLAGS=3D"-framework CoreFoundation -framework IOKit -framework = ApplicationServices $LDFLAGS" libs_softmmu=3D"-F/System/Library/Frameworks -framework Cocoa = -framework IOKit $libs_softmmu" # Disable attempts to use ObjectiveC features in os/object.h since = they # won't work when we're compiling with gcc as a C compiler. --=20 1.7.5.4 --Apple-Mail-1-484770238 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Allows for using real cdrom disc in = QEMU under Mac OS X.

This command was used to see if this = patch worked:
./qemu-system-i386 -drive = if=3Dnone,id=3Ddrive0,file=3D/dev/null,format=3Draw

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>= ;

---
Replaced -errno with 0 for = ioctl() failure return value.
"make check" now passes with this = patch.


 block/raw-posix.c | =   18 +++++++++++++++++-
 configure       =   |    2 +-
 2 files changed, 18 = insertions(+), 2 deletions(-)

diff = --git a/block/raw-posix.c b/block/raw-posix.c
index = e51293a..16fa0a4 100644
--- a/block/raw-posix.c
+++ = b/block/raw-posix.c
@@ -1312,7 +1312,23 @@ again:
 #if defined(__APPLE__) && = defined(__MACH__)
-        size =3D = LLONG_MAX;
+    {
+        = uint64_t sectors =3D 0;
+        uint32_t = sector_size =3D 0;
+
+        /* Query the number of = sectors on the disk */
+        ret =3D ioctl(fd, = DKIOCGETBLOCKCOUNT, &sectors);
+        if (ret = =3D=3D -1) {
+            return = 0;
+
+        /* Query = the size of each sector */
+        ret =3D = ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size);
+        size =3D = sectors * sector_size;
+    }
 #else
         if (size < 0) = {
index cae588c..32d3d3f = 100755
--- a/configure
+++ b/configure
@@ = -611,7 +611,7 @@ Darwin)
   cocoa=3D"yes"
   = audio_possible_drivers=3D"coreaudio sdl fmod"
+  LDFLAGS=3D"-framework CoreFoundation = -framework IOKit -framework ApplicationServices $LDFLAGS"
   # Disable = attempts to use ObjectiveC features in os/object.h since they
-- 
1.7.5.4