Skip to contentSkip to conversation

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

PATCH Applied Programmingkid 3 participants 6 messages Jan 2, 2015 – Jan 13, 2015 Block layer

v4 of 7 Applied Latest is v7 →

lore
Share & tools
lore
#0 lore raw

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

Removes redundant ret variable and renames sectorSize variable to meet QEMU coding standards.

---
 block/raw-posix.c |   18 +++++++++++++++++-
 configure         |    2 +-
 2 files changed, 18 insertions(+), 2 deletions(-)
block/raw-posix.c +17 -1
index e51293a..16fa0a4 100644
@@ -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) {
configure +1 -1
index cae588c..32d3d3f 100755
@@ -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.
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 1 line · Programmingkid

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.

---
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!

Quoted 7 lines
---
 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

#2 lore raw
Quoted 37 lines · Stefan Hajnoczi
Quoted 1 line · Programmingkid

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.

---
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!

Quoted 7 lines

---
block/raw-posix.c | 18 +++++++++++++++++-
configure | 2 +-

2 files changed, 18 insertions(+), 2 deletions(-)
Quoted 4 lines

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

Stefan

Thank you very much for accepting my patch.

#3 lore raw
Quoted 40 lines · Programmingkid
Quoted 37 lines · Stefan Hajnoczi
Quoted 1 line · Programmingkid

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.

---
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!

Quoted 7 lines

---
block/raw-posix.c | 18 +++++++++++++++++-
configure | 2 +-

2 files changed, 18 insertions(+), 2 deletions(-)
Quoted 6 lines
Quoted 4 lines

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

#4 lore raw
Quoted 53 lines · Stefan Hajnoczi
Quoted 40 lines · Programmingkid
Quoted 37 lines · Stefan Hajnoczi
Quoted 1 line · Programmingkid

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.

---
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!

Quoted 7 lines

---
block/raw-posix.c | 18 +++++++++++++++++-
configure | 2 +-

2 files changed, 18 insertions(+), 2 deletions(-)
Quoted 6 lines
Quoted 4 lines

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,...

Quoted 6 lines

/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?

#5 lore raw
Quoted 1 line · Programmingkid

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

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

Quoted 1 line

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