qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v6] block/raw-posix.c: Fixes raw_getlength() on Mac OS X so that it reports the correct length of a real CD
@ 2015-01-13 20:07 Programmingkid
  2015-01-14 17:02 ` Peter Maydell
  0 siblings, 1 reply; 9+ messages in thread
From: Programmingkid @ 2015-01-13 20:07 UTC (permalink / raw)
  To: Peter Maydell, Kevin Wolf, Stefan Hajnoczi; +Cc: qemu-devel qemu-devel

Allows QEMU on Mac OS X to use a real cdrom again.

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

---
Added fallback code - uses lseek() if ioctl() fails.

 block/raw-posix.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index e51293a..5815707 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1312,7 +1312,30 @@ again:
         if (size == 0)
 #endif
 #if defined(__APPLE__) && defined(__MACH__)
-        size = LLONG_MAX;
+    {
+        uint64_t sectors = 0;
+        uint32_t sector_size = 0;
+        bool ioctl_problem = false;
+        ret = 0;
+
+        /* Query the number of sectors on the disk */
+        ret = ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors);
+        if (ret != 0)
+            ioctl_problem = true;
+
+        /* Query the size of each sector */
+        ret = ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size);
+        if (ret != 0)
+            ioctl_problem = true;
+
+        /* If everything is ok */
+        if (ioctl_problem == false)
+            size = sectors * sector_size;
+
+        /* If a problem occurred with ioctl(), fallback to lseek() */
+        else
+            size = lseek(fd, 0LL, SEEK_END);
+    }
 #else
         size = lseek(fd, 0LL, SEEK_END);
         if (size < 0) {
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-01-19 18:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-13 20:07 [Qemu-devel] [PATCH v6] block/raw-posix.c: Fixes raw_getlength() on Mac OS X so that it reports the correct length of a real CD Programmingkid
2015-01-14 17:02 ` Peter Maydell
2015-01-14 18:21   ` Programmingkid
2015-01-15 23:40   ` [Qemu-devel] [PATCH v7] " Programmingkid
2015-01-16  8:22     ` Markus Armbruster
2015-01-19 16:32       ` Programmingkid
2015-01-19 17:45         ` Eric Blake
2015-01-19 18:11         ` Markus Armbruster
2015-01-17 22:53     ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).