aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorProgrammingkid <programmingkidx@gmail.com>2015-01-19 17:12:55 -0500
committerKevin Wolf <kwolf@redhat.com>2015-02-06 18:00:53 +0100
commit728dacbda817b2ca259e9d337fab06bcf14e94a6 (patch)
treec2b7137760bea1deb16296e159ccda497918b9ed
parent8333c0dff14a8a16c8ad3a95c6ea09f9d6f395b3 (diff)
block/raw-posix.c: Fix raw_getlength() on Mac OS X block devices
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>
-rw-r--r--block/raw-posix.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 7b42f37d83..e474c17974 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -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) {