qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Programmingkid <programmingkidx@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@gmail.com>,
	qemu-devel qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [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
Date: Wed, 14 Jan 2015 13:21:44 -0500	[thread overview]
Message-ID: <3CC173D9-8BA2-4E8C-BC3C-64C267F4EC0F@gmail.com> (raw)
In-Reply-To: <CAFEAcA9Z-Uz8VP5PXeOvxLw=53aDLe3WcB-RdqNCN5zMqjz3dg@mail.gmail.com>


On Jan 14, 2015, at 12:02 PM, Peter Maydell wrote:

> On 13 January 2015 at 20:07, Programmingkid <programmingkidx@gmail.com> wrote:
>> 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
> 
> This fixes the "make check" problem, but you're not catching
> the possibility of lseek failing. (Also the if() statements
> are all missing braces our coding style requires.) You can
> avoid that bool flag like this:
> 
>    {
>        uint64_t sectors = 0;
>        uint32_t sector_size = 0;
> 
>        if (ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors) == 0
>            && ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size) == 0) {
>            size = sectors * sector_size;
>        } else {
>            size = lseek(fd, 0LL, SEEK_END);
>            if (size < 0) {
>                return -errno;
>            }
>        }
>    }

Yeah, your code looks great. I will make a patch for it if you need me to. 

  reply	other threads:[~2015-01-14 18:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3CC173D9-8BA2-4E8C-BC3C-64C267F4EC0F@gmail.com \
    --to=programmingkidx@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).