qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2] block/raw-posix.c: Fixes raw_getlength() on


From: Programmingkid
Subject: Re: [Qemu-devel] [PATCH v2] block/raw-posix.c: Fixes raw_getlength() on Mac OS X so that it reports the correct length of a real CD
Date: Sat, 27 Dec 2014 22:00:47 -0500

On Dec 27, 2014, at 8:19 PM, Peter Maydell wrote:

> On 28 December 2014 at 00:36, Programmingkid <address@hidden> wrote:
>> The raw_getlength() function under Mac OS X incorrectly returned a constant 
>> value instead of calculating the size of a real CD-ROM disc. This patch 
>> fixes this problem and makes booting from a real CD-ROM disc possible again 
>> under Mac OS X.
>> 
>> signed-off-by: John Arbuckle <address@hidden>
> 
> Thanks. (My Mac doesn't have a cdrom...)
> 
>> ---
>> block/raw-posix.c |   11 ++++++++++-
>> 1 files changed, 10 insertions(+), 1 deletions(-)
>> 
>> diff --git a/block/raw-posix.c b/block/raw-posix.c
>> index e51293a..d723133 100644
>> --- a/block/raw-posix.c
>> +++ b/block/raw-posix.c
>> @@ -1312,7 +1312,16 @@ again:
>>         if (size == 0)
>> #endif
>> #if defined(__APPLE__) && defined(__MACH__)
>> -        size = LLONG_MAX;
>> +        // Query the number of sectors on the disk
> 
> I note in passing that this whole function is a total mess
> -- look at that "if (size == 0)" in the previous #ifdef...
> However since I think it's impossible to both have the
> previous #ifdef and this one enabled it won't cause an issue.

I agree. This file needs a lot of work. 

> 
>> +        uint64_t sectors = 0;
>> +        ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors);
> 
> You need to check the error return from these ioctl calls.
> 
>> +
>> +        // Query the size of each sector
>> +        uint32_t sectorSize = 0;
>> +        ioctl(fd, DKIOCGETBLOCKSIZE, &sectorSize);
>> +
>> +        size = sectors * sectorSize;
>> +        //printf("size of disc = %d MB\n", size/(1024*1024));
>> #else
>>         size = lseek(fd, 0LL, SEEK_END);
>>         if (size < 0) {
> 
> Minor style issues you might want to fix for v2:
> * use /* */ comments, not //
> * declare variables only at the top of {} code blocks
> * don't leave commented out debug printfs in code
> 
> thanks
> -- PMM

Here is version 2 of the patch. All the suggestions have been implemented.

signed-off-by: John Arbuckle <address@hidden>

---
 block/raw-posix.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index e51293a..0148161 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1312,7 +1312,25 @@ again:
         if (size == 0)
 #endif
 #if defined(__APPLE__) && defined(__MACH__)
-        size = LLONG_MAX;
+        #define IOCTL_ERROR_VALUE -1
+        uint64_t sectors = 0;
+        uint32_t sectorSize = 0;
+        int ret;
+
+        /* Query the number of sectors on the disk */
+        ret = ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors);
+        if(ret == IOCTL_ERROR_VALUE) {
+           printf("\n\nWarning: problem detected retrieving sector 
count!\n\n");
+           return -errno;
+        }
+
+        /* Query the size of each sector */
+        ret = ioctl(fd, DKIOCGETBLOCKSIZE, &sectorSize);
+        if(ret == IOCTL_ERROR_VALUE) {
+           printf("\n\nWarning: problem detected retrieving sector size!\n\n");
+           return -errno;
+        }
+        size = sectors * sectorSize;
 #else
         size = lseek(fd, 0LL, SEEK_END);
         if (size < 0) {
-- 
1.7.5.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]