diff mbox

[v4] block/raw-posix.c: Fixes raw_getlength() on Mac OS X so that it reports the correct length of a real CD

Message ID D2A0F23E-3BC1-43C4-84A9-35869B36B32D@gmail.com
State New
Headers show

Commit Message

Programmingkid Jan. 2, 2015, 9:44 p.m. UTC
Removes redundant ret variable and renames sectorSize variable to meet QEMU coding standards. 

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

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

Comments

Stefan Hajnoczi Jan. 6, 2015, 2:02 p.m. UTC | #1
On Fri, Jan 02, 2015 at 04:44:38PM -0500, Programmingkid wrote:
> Removes redundant ret variable and renames sectorSize variable to meet QEMU coding standards. 

This is a changelog item for v4 of this patch.  Changelogs should go
below the '---' line so they are not merged into git history.

The rationale is that when a patch is merged into git, the changelog
describing patch revisions that were posted on the mailing list is not
relevant (we only see the final patch in git, not the revisions from the
mailing list).

Patches usually look like this:

Subject: block/raw-posix: brief summary

A longer description of the problem, maybe a command-line to reproduce a
bug, and some rationale for this code change.

Signed-off-by: Me <my@email.com>
---
v2:
 * Fix int -> size_t for memory lengths [Requested by Bob]

The changelog at the bottom is useful to code reviewers but won't get
merged in the git history.

Anyway, thanks for this patch.  I have dropped this changelog line and
merged it!

> 
> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
> 
> ---
>  block/raw-posix.c |   18 +++++++++++++++++-
>  configure         |    2 +-
>  2 files changed, 18 insertions(+), 2 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan
Programmingkid Jan. 6, 2015, 3:04 p.m. UTC | #2
On Jan 6, 2015, at 9:02 AM, Stefan Hajnoczi wrote:

> On Fri, Jan 02, 2015 at 04:44:38PM -0500, Programmingkid wrote:
>> Removes redundant ret variable and renames sectorSize variable to meet QEMU coding standards. 
> 
> This is a changelog item for v4 of this patch.  Changelogs should go
> below the '---' line so they are not merged into git history.
> 
> The rationale is that when a patch is merged into git, the changelog
> describing patch revisions that were posted on the mailing list is not
> relevant (we only see the final patch in git, not the revisions from the
> mailing list).
> 
> Patches usually look like this:
> 
> Subject: block/raw-posix: brief summary
> 
> A longer description of the problem, maybe a command-line to reproduce a
> bug, and some rationale for this code change.
> 
> Signed-off-by: Me <my@email.com>
> ---
> v2:
> * Fix int -> size_t for memory lengths [Requested by Bob]
> 
> The changelog at the bottom is useful to code reviewers but won't get
> merged in the git history.
> 
> Anyway, thanks for this patch.  I have dropped this changelog line and
> merged it!
> 
>> 
>> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
>> 
>> ---
>> block/raw-posix.c |   18 +++++++++++++++++-
>> configure         |    2 +-
>> 2 files changed, 18 insertions(+), 2 deletions(-)
> 
> Thanks, applied to my block tree:
> https://github.com/stefanha/qemu/commits/block
> 
> Stefan

Thank you very much for accepting my patch.
Stefan Hajnoczi Jan. 13, 2015, 2:05 p.m. UTC | #3
On Tue, Jan 6, 2015 at 3:04 PM, Programmingkid
<programmingkidx@gmail.com> wrote:
>
> On Jan 6, 2015, at 9:02 AM, Stefan Hajnoczi wrote:
>
>> On Fri, Jan 02, 2015 at 04:44:38PM -0500, Programmingkid wrote:
>>> Removes redundant ret variable and renames sectorSize variable to meet QEMU coding standards.
>>
>> This is a changelog item for v4 of this patch.  Changelogs should go
>> below the '---' line so they are not merged into git history.
>>
>> The rationale is that when a patch is merged into git, the changelog
>> describing patch revisions that were posted on the mailing list is not
>> relevant (we only see the final patch in git, not the revisions from the
>> mailing list).
>>
>> Patches usually look like this:
>>
>> Subject: block/raw-posix: brief summary
>>
>> A longer description of the problem, maybe a command-line to reproduce a
>> bug, and some rationale for this code change.
>>
>> Signed-off-by: Me <my@email.com>
>> ---
>> v2:
>> * Fix int -> size_t for memory lengths [Requested by Bob]
>>
>> The changelog at the bottom is useful to code reviewers but won't get
>> merged in the git history.
>>
>> Anyway, thanks for this patch.  I have dropped this changelog line and
>> merged it!
>>
>>>
>>> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
>>>
>>> ---
>>> block/raw-posix.c |   18 +++++++++++++++++-
>>> configure         |    2 +-
>>> 2 files changed, 18 insertions(+), 2 deletions(-)
>>
>> Thanks, applied to my block tree:
>> https://github.com/stefanha/qemu/commits/block
>>
>> Stefan
>
> Thank you very much for accepting my patch.

Hi,
Unfortunately I had to drop this patch because it breaks -drive
file=/dev/null,...

/dev/null is a character device and we should not return -ENOTSUP when
the CD-ROM ioctls fail.

Please let it fail gracefully when the device is not a CD-ROM.

Stefan
Programmingkid Jan. 13, 2015, 5:52 p.m. UTC | #4
On Jan 13, 2015, at 9:05 AM, Stefan Hajnoczi wrote:

> On Tue, Jan 6, 2015 at 3:04 PM, Programmingkid
> <programmingkidx@gmail.com> wrote:
>> 
>> On Jan 6, 2015, at 9:02 AM, Stefan Hajnoczi wrote:
>> 
>>> On Fri, Jan 02, 2015 at 04:44:38PM -0500, Programmingkid wrote:
>>>> Removes redundant ret variable and renames sectorSize variable to meet QEMU coding standards.
>>> 
>>> This is a changelog item for v4 of this patch.  Changelogs should go
>>> below the '---' line so they are not merged into git history.
>>> 
>>> The rationale is that when a patch is merged into git, the changelog
>>> describing patch revisions that were posted on the mailing list is not
>>> relevant (we only see the final patch in git, not the revisions from the
>>> mailing list).
>>> 
>>> Patches usually look like this:
>>> 
>>> Subject: block/raw-posix: brief summary
>>> 
>>> A longer description of the problem, maybe a command-line to reproduce a
>>> bug, and some rationale for this code change.
>>> 
>>> Signed-off-by: Me <my@email.com>
>>> ---
>>> v2:
>>> * Fix int -> size_t for memory lengths [Requested by Bob]
>>> 
>>> The changelog at the bottom is useful to code reviewers but won't get
>>> merged in the git history.
>>> 
>>> Anyway, thanks for this patch.  I have dropped this changelog line and
>>> merged it!
>>> 
>>>> 
>>>> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
>>>> 
>>>> ---
>>>> block/raw-posix.c |   18 +++++++++++++++++-
>>>> configure         |    2 +-
>>>> 2 files changed, 18 insertions(+), 2 deletions(-)
>>> 
>>> Thanks, applied to my block tree:
>>> https://github.com/stefanha/qemu/commits/block
>>> 
>>> Stefan
>> 
>> Thank you very much for accepting my patch.
> 
> Hi,
> Unfortunately I had to drop this patch because it breaks -drive
> file=/dev/null,...
> 
> /dev/null is a character device and we should not return -ENOTSUP when
> the CD-ROM ioctls fail.
> 
> Please let it fail gracefully when the device is not a CD-ROM.
> 
> Stefan

What is the exact command you use with QEMU involving the /dev/null device?

What value is suppose to be returned when using a device like /dev/null?
Peter Maydell Jan. 13, 2015, 6:05 p.m. UTC | #5
On 13 January 2015 at 17:52, Programmingkid <programmingkidx@gmail.com> wrote:
> What is the exact command you use with QEMU involving the /dev/null device?

"make check" includes some tests which do this...

> What value is suppose to be returned when using a device like /dev/null?

I think we should fall back to the "try lseek" code path, as we do on
Linux. (That will return zero, as it happens.)

-- PMM
diff mbox

Patch

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 -errno;
+         }
+
+         /* Query the size of each sector */
+         ret = ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size);
+         if (ret == -1) {
+             return -errno;
+         }
+         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.