Skip to contentSkip to conversation

block/raw-posix.c: Fix raw_getlength() on Mac OS X for CD

PATCH Applied Programmingkid 6 participants 12 messages Jan 19, 2015 – Feb 6, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v8 1/1 block/raw-posix.c: Fix raw_getlength() on Mac OS X for CD

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

This patch allows Mac OS X to use a real CDROM disc in QEMU. Testing this patch will require using QEMU v2.2.0 because the
current git version has a bug in it that prevents /dev/cdrom from being used. "make check" did pass and my Debian boot disc did work.

---
Fixed code indentation to be inline with removed
size = LLONG_MAX.

 block/raw-posix.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
block/raw-posix.c +14 -1
index e51293a..fa431b2 100644
@@ -1312,7 +1312,20 @@ again:
         if (size == 0)
 #endif
 #if defined(__APPLE__) && defined(__MACH__)
-        size = LLONG_MAX;
+        {
+            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;
+                }
+            }
+        }
 #else
         size = lseek(fd, 0LL, SEEK_END);
         if (size < 0) {
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 3 lines · Programmingkid

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

Patch history information goes...

Quoted 9 lines

This patch allows Mac OS X to use a real CDROM disc in QEMU. Testing this patch will require using QEMU v2.2.0 because the
current git version has a bug in it that prevents /dev/cdrom from being used. "make check" did pass and my Debian boot disc did work.

---

... below the --- divider.

Quoted 11 lines

Fixed code indentation to be inline with removed
size = LLONG_MAX.

 block/raw-posix.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
block/raw-posix.c +0 -0
index e51293a..fa431b2 100644

block/raw-posix.c again: · line 1317

Quoted 7 lines
block/raw-posix.c +3 -1
@@ -1312,7 +1312,20 @@ again:
         if (size == 0)
 #endif
 #if defined(__APPLE__) && defined(__MACH__)
-        size = LLONG_MAX;
+        {
+            uint64_t sectors = 0;
+            uint32_t sector_size = 0;

Ignorant question: why do you need to initialize these?

Patch looks plausible otherwise, but know nothing about Macs :)

Quoted 14 lines
block/raw-posix.c +11 -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;
+                }
+            }
+        }
 #else
         size = lseek(fd, 0LL, SEEK_END);
         if (size < 0) {
#2 lore raw
Quoted 14 lines · Markus Armbruster
Quoted 3 lines · Programmingkid

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

Patch history information goes...

Quoted 6 lines

This patch allows Mac OS X to use a real CDROM disc in QEMU. Testing this patch will require using QEMU v2.2.0 because the current git version has a bug in it that prevents /dev/cdrom from being used. "make check" did pass and my Debian boot disc did work.

Quoted 5 lines
Quoted 3 lines

---

... below the --- divider.

I thought I did this. The information above is the description of the patch. Not its history.

Quoted 7 lines
Quoted 7 lines

Fixed code indentation to be inline with removed
size = LLONG_MAX.

block/raw-posix.c | 15 ++++++++++++++-

1 files changed, 14 insertions(+), 1 deletions(-)
Quoted 14 lines

block/raw-posix.c again: · line 1317

Quoted 12 lines
block/raw-posix.c +3 -1
index e51293a..fa431b2 100644
@@ -1312,7 +1312,20 @@ again:
        if (size == 0)
 #endif
 #if defined(__APPLE__) && defined(__MACH__)
-        size = LLONG_MAX;
+        {
+            uint64_t sectors = 0;
+            uint32_t sector_size = 0;

Ignorant question: why do you need to initialize these?

We don't. It's just a habit.

Quoted 2 lines

Patch looks plausible otherwise, but know nothing about Macs :)

It does do the job.

Quoted 15 lines
Quoted 15 lines
block/raw-posix.c +11 -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;
+                }
+            }
+        }
 #else
        size = lseek(fd, 0LL, SEEK_END);
        if (size < 0) {
#3 lore raw
Quoted 9 lines · Programmingkid
Quoted 6 lines · Markus Armbruster
Quoted 3 lines · Programmingkid

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

Quoted 7 lines
Quoted 4 lines

Patch history information goes...

... below the --- divider.

I thought I did this. The information above is the description of the patch. Not its history.

Anything that mentions 'v7' is history. When you read 'git log', you will not see mentions of 'v7', because no one cares how many tries it took to get a patch into git. Knowing about v7 only matters to the reviewers of v8, hence it is patch history that belongs after the divider.

Quoted 3 lines
Quoted 3 lines

block/raw-posix.c again: · line 1320

Quoted 3 lines
block/raw-posix.c +3 -0
+
+            if (ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors) == 0
+               && ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size) == 0) {

Indentation looks off here.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw
Quoted 15 lines · Eric Blake
Quoted 14 lines · Programmingkid
Quoted 10 lines · Markus Armbruster
Quoted 3 lines · Programmingkid

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

Patch history information goes...

... below the --- divider.

Quoted 7 lines
Quoted 2 lines

I thought I did this. The information above is the description of the patch. Not its history.

Anything that mentions 'v7' is history. When you read 'git log', you will not see mentions of 'v7', because no one cares how many tries it took to get a patch into git. Knowing about v7 only matters to the reviewers of v8, hence it is patch history that belongs after the divider.

Ok.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

block/raw-posix.c again: · line 1320

Quoted 5 lines
block/raw-posix.c +3 -0
+
+            if (ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors) == 0
+               && ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size) == 0) {

Indentation looks off here.

It does look a little odd, but it also communicates that this is one statement (IMHO).

#5 lore raw
Quoted 29 lines · Programmingkid
Quoted 15 lines · Eric Blake
Quoted 14 lines · Programmingkid
Quoted 10 lines · Markus Armbruster
Quoted 3 lines · Programmingkid

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

Patch history information goes...

... below the --- divider.

Quoted 7 lines
Quoted 2 lines

I thought I did this. The information above is the description of the patch. Not its history.

Anything that mentions 'v7' is history. When you read 'git log', you will not see mentions of 'v7', because no one cares how many tries it took to get a patch into git. Knowing about v7 only matters to the reviewers of v8, hence it is patch history that belongs after the divider.

Ok.

Quoted 2 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

block/raw-posix.c again: · line 1320

Quoted 3 lines
block/raw-posix.c +3 -0
+
+            if (ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors) == 0
+               && ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size) == 0) {

Indentation looks off here.

It does look a little odd, but it also communicates that this is one statement (IMHO).

It's not how the rest of QEMU is indented. Please try to blend in :)

I feel bad about notpicking v8 of an obviously useful and patch that is basically just fine except for these little things. Thanks for persevering!

#6 lore raw
Quoted 37 lines · Markus Armbruster
Quoted 35 lines · Programmingkid
Quoted 15 lines · Eric Blake
Quoted 14 lines · Programmingkid
Quoted 10 lines · Markus Armbruster
Quoted 3 lines · Programmingkid

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

Patch history information goes...

... below the --- divider.

Quoted 7 lines
Quoted 2 lines

I thought I did this. The information above is the description of the patch. Not its history.

Anything that mentions 'v7' is history. When you read 'git log', you will not see mentions of 'v7', because no one cares how many tries it took to get a patch into git. Knowing about v7 only matters to the reviewers of v8, hence it is patch history that belongs after the divider.

Ok.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

block/raw-posix.c again: · line 1320

Quoted 5 lines
block/raw-posix.c +3 -0
+
+            if (ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors) == 0
+               && ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size) == 0) {

Indentation looks off here.

Quoted 8 lines
Quoted 2 lines

It does look a little odd, but it also communicates that this is one statement (IMHO).

It's not how the rest of QEMU is indented. Please try to blend in :)

I feel bad about notpicking v8 of an obviously useful and patch that is basically just fine except for these little things. Thanks for persevering!

Thanks for your encouragement. I personally would have had that whole if condition on one line, but others want an 80 line maximum.

#7 lore raw
Quoted 43 lines · Programmingkid
Quoted 41 lines · Markus Armbruster
Quoted 38 lines · Programmingkid
Quoted 15 lines · Eric Blake
Quoted 14 lines · Programmingkid
Quoted 10 lines · Markus Armbruster
Quoted 3 lines · Programmingkid

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

Patch history information goes...

... below the --- divider.

Quoted 8 lines
Quoted 3 lines

I thought I did this. The information above is the description of the patch.
Not its history.

Anything that mentions 'v7' is history. When you read 'git log', you will not see mentions of 'v7', because no one cares how many tries it took to get a patch into git. Knowing about v7 only matters to the reviewers of v8, hence it is patch history that belongs after the divider.

Ok.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +3 -0
+
+            if (ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors) == 0
+               && ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size) == 0) {

Indentation looks off here.

It does look a little odd, but it also communicates that this is one statement (IMHO).

Quoted 8 lines
Quoted 5 lines

It's not how the rest of QEMU is indented. Please try to blend in :)

I feel bad about notpicking v8 of an obviously useful and patch that is basically just fine except for these little things. Thanks for persevering!

Thanks for your encouragement. I personally would have had that whole if condition on one line, but others want an 80 line maximum.

Humans tend to have trouble following long lines with their eyes (I sure do). Typographic manuals suggest to limit columns to roughly 60 characters for exactly that reason[*]. Code can be a bit wider since it's commonly indented[**].

For commit messages, 70 characters is already a compromise between legibility and "writability".

[*] https://en.wikipedia.org/wiki/Column_(typography)#Typographic_style

[**] Deep nesting is no excuse for exceeding the width limit, because deep nesting is no excuse for *anything* :)

#8 lore raw
Quoted 59 lines · Markus Armbruster
Quoted 43 lines · Programmingkid
Quoted 41 lines · Markus Armbruster
Quoted 38 lines · Programmingkid
Quoted 15 lines · Eric Blake
Quoted 14 lines · Programmingkid
Quoted 10 lines · Markus Armbruster
Quoted 3 lines · Programmingkid

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

Patch history information goes...

... below the --- divider.

Quoted 8 lines
Quoted 3 lines

I thought I did this. The information above is the description of the patch.
Not its history.

Anything that mentions 'v7' is history. When you read 'git log', you will not see mentions of 'v7', because no one cares how many tries it took to get a patch into git. Knowing about v7 only matters to the reviewers of v8, hence it is patch history that belongs after the divider.

Ok.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +3 -0
+
+            if (ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors) == 0
+               && ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size) == 0) {

Indentation looks off here.

It does look a little odd, but it also communicates that this is one statement (IMHO).

Quoted 8 lines
Quoted 5 lines

It's not how the rest of QEMU is indented. Please try to blend in :)

I feel bad about notpicking v8 of an obviously useful and patch that is basically just fine except for these little things. Thanks for persevering!

Thanks for your encouragement. I personally would have had that whole if condition on one line, but others want an 80 line maximum.

Humans tend to have trouble following long lines with their eyes (I sure do). Typographic manuals suggest to limit columns to roughly 60 characters for exactly that reason[*]. Code can be a bit wider since it's commonly indented[**].

Quoted 8 lines

For commit messages, 70 characters is already a compromise between legibility and "writability".

[*] https://en.wikipedia.org/wiki/Column_(typography)#Typographic_style

[**] Deep nesting is no excuse for exceeding the width limit, because deep nesting is no excuse for *anything* :)

<Puts up white flag> I will indent my code at around the 60 to 70 character size.

Reviewed-by on v8 1/1
#9 lore raw
In reply to Programmingkid
Quoted 34 lines · Programmingkid

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

This patch allows Mac OS X to use a real CDROM disc in QEMU. Testing this patch will require using QEMU v2.2.0 because the
current git version has a bug in it that prevents /dev/cdrom from being used. "make check" did pass and my Debian boot disc did work.

---
Fixed code indentation to be inline with removed
size = LLONG_MAX.

 block/raw-posix.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
block/raw-posix.c +7 -1
index e51293a..fa431b2 100644
@@ -1312,7 +1312,20 @@ again:
         if (size == 0)
 #endif
 #if defined(__APPLE__) && defined(__MACH__)
-        size = LLONG_MAX;
+        {
+            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;

block/raw-posix.c again: · line 1331

Quoted 10 lines
block/raw-posix.c +7 -0
+            } else {
+                size = lseek(fd, 0LL, SEEK_END);
+                if (size < 0) {
+                    return -errno;
+                }
+            }
+        }
 #else
         size = lseek(fd, 0LL, SEEK_END);
         if (size < 0) {
Applied
#11 lore raw
In reply to Programmingkid

Am 19.01.2015 um 23:12 hat Programmingkid geschrieben:

Quoted 10 lines

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

This patch allows Mac OS X to use a real CDROM disc in QEMU. Testing this patch will require using QEMU v2.2.0 because the
current git version has a bug in it that prevents /dev/cdrom from being used. "make check" did pass and my Debian boot disc did work.

Thanks, applied to the block branch.

Kevin