]> git.proxmox.com Git - mirror_qemu.git/commitdiff
block/raw-posix.c: Fix raw_getlength() on Mac OS X block devices
authorProgrammingkid <programmingkidx@gmail.com>
Mon, 19 Jan 2015 22:12:55 +0000 (17:12 -0500)
committerKevin Wolf <kwolf@redhat.com>
Fri, 6 Feb 2015 17:00:53 +0000 (18:00 +0100)
This patch replaces the dummy code in raw_getlength() for block devices
on OS X, which always returned LLONG_MAX, with a real implementation
that returns the actual block device size.

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Tested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/raw-posix.c

index 7b42f37d83ad918c98a930a0dc36a55a7549669c..e474c179748f645e4feafe805d5549d25ba1f0bc 100644 (file)
@@ -1375,7 +1375,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) {