Received: from eggs.gnu.org ([2001:4830:134:3::10]:60789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJmoV-00073t-OJ for qemu-devel@nongnu.org; Fri, 06 Feb 2015 12:35:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJmoQ-0005dr-0W for qemu-devel@nongnu.org; Fri, 06 Feb 2015 12:35:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39260) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJmoP-0005dn-MH for qemu-devel@nongnu.org; Fri, 06 Feb 2015 12:35:25 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t16HZOXs007327 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 6 Feb 2015 12:35:25 -0500 From: Kevin Wolf Date: Fri, 6 Feb 2015 18:35:07 +0100 Message-Id: <1423244107-21403-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1423244107-21403-1-git-send-email-kwolf@redhat.com> References: <1423244107-21403-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL v2 47/47] block/raw-posix.c: Fix raw_getlength() on Mac OS X block devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Programmingkid 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 Reviewed-by: Stefan Hajnoczi Tested-by: Peter Maydell Signed-off-by: Kevin Wolf --- block/raw-posix.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 7b42f37..e474c17 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, §ors) == 0 + && ioctl(fd, DKIOCGETBLOCKSIZE, §or_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) { -- 1.8.3.1