提交 728dacbd 编写于 作者: P Programmingkid 提交者: Kevin Wolf

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: NJohn Arbuckle <programmingkidx@gmail.com>
Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
Tested-by: NPeter Maydell <peter.maydell@linaro.org>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 8333c0df
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册