qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [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
@ 2015-01-13 18:26 Programmingkid
  2015-01-13 18:34 ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Programmingkid @ 2015-01-13 18:26 UTC (permalink / raw)
  To: qemu-devel qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 1948 bytes --]

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=none,id=drive0,file=/dev/null,format=raw

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 (size == 0)
 #endif
 #if defined(__APPLE__) && defined(__MACH__)
-        size = LLONG_MAX;
+    {
+        uint64_t sectors = 0;
+        uint32_t sector_size = 0;
+
+        /* Query the number of sectors on the disk */
+        ret = ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors);
+        if (ret == -1) {
+            return 0;
+        }
+
+        /* Query the size of each sector */
+        ret = ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size);
+        if (ret == -1) {
+            return 0;
+        }
+        size = sectors * sector_size;
+    }
 #else
         size = 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="yes"
   audio_drv_list="coreaudio"
   audio_possible_drivers="coreaudio sdl fmod"
-  LDFLAGS="-framework CoreFoundation -framework IOKit $LDFLAGS"
+  LDFLAGS="-framework CoreFoundation -framework IOKit -framework ApplicationServices $LDFLAGS"
   libs_softmmu="-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.
-- 
1.7.5.4


[-- Attachment #2: Type: text/html, Size: 11196 bytes --]

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

* Re: [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
  2015-01-13 18:26 [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 Programmingkid
@ 2015-01-13 18:34 ` Peter Maydell
  2015-01-13 18:45   ` Programmingkid
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2015-01-13 18:34 UTC (permalink / raw)
  To: Programmingkid; +Cc: Stefan Hajnoczi, qemu-devel qemu-devel

On 13 January 2015 at 18:26, Programmingkid <programmingkidx@gmail.com> wrote:
> 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=none,id=drive0,file=/dev/null,format=raw
>
> 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 (size == 0)
>  #endif
>  #if defined(__APPLE__) && defined(__MACH__)
> -        size = LLONG_MAX;
> +    {
> +        uint64_t sectors = 0;
> +        uint32_t sector_size = 0;
> +
> +        /* Query the number of sectors on the disk */
> +        ret = ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors);
> +        if (ret == -1) {
> +            return 0;

We should be falling back to lseek, not returning 0...

thanks
-- PMM

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

* Re: [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
  2015-01-13 18:34 ` Peter Maydell
@ 2015-01-13 18:45   ` Programmingkid
  2015-01-13 18:54     ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Programmingkid @ 2015-01-13 18:45 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Stefan Hajnoczi, qemu-devel qemu-devel


On Jan 13, 2015, at 1:34 PM, Peter Maydell wrote:

> On 13 January 2015 at 18:26, Programmingkid <programmingkidx@gmail.com> wrote:
>> 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=none,id=drive0,file=/dev/null,format=raw
>> 
>> 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 (size == 0)
>> #endif
>> #if defined(__APPLE__) && defined(__MACH__)
>> -        size = LLONG_MAX;
>> +    {
>> +        uint64_t sectors = 0;
>> +        uint32_t sector_size = 0;
>> +
>> +        /* Query the number of sectors on the disk */
>> +        ret = ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors);
>> +        if (ret == -1) {
>> +            return 0;
> 
> We should be falling back to lseek, not returning 0...
> 
> thanks
> -- PMM

I did try using lseek, but it doesn't work with Mac OS X block devices. It would always fail. Here is some more information on the problem: http://stackoverflow.com/questions/9073614/open-raw-disk-and-get-size-os-x. 

I thought things would be as simple as using fopen() with a block device as the argument, but Apple decided to make things more difficult. It looks like they are forcing developers to use the IOKit for device communications. Simple posix functions like lseek don't work.

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

* Re: [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
  2015-01-13 18:45   ` Programmingkid
@ 2015-01-13 18:54     ` Peter Maydell
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2015-01-13 18:54 UTC (permalink / raw)
  To: Programmingkid; +Cc: Stefan Hajnoczi, qemu-devel qemu-devel

On 13 January 2015 at 18:45, Programmingkid <programmingkidx@gmail.com> wrote:
>
> On Jan 13, 2015, at 1:34 PM, Peter Maydell wrote:
>
>> On 13 January 2015 at 18:26, Programmingkid <programmingkidx@gmail.com> wrote:
>>> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
>>> +        uint64_t sectors = 0;
>>> +        uint32_t sector_size = 0;
>>> +
>>> +        /* Query the number of sectors on the disk */
>>> +        ret = ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors);
>>> +        if (ret == -1) {
>>> +            return 0;
>>
>> We should be falling back to lseek, not returning 0...

> I did try using lseek, but it doesn't work with Mac OS X block
> devices. It would always fail.

Right, but for block devices the ioctl will succeed, I thought?
We'll only try lseek() if the ioctl fails (hence "fall back").

-- PMM

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-13 18:26 [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 Programmingkid
2015-01-13 18:34 ` Peter Maydell
2015-01-13 18:45   ` Programmingkid
2015-01-13 18:54     ` 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).