mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-16 14:41:55 -06:00
block: try BSD disk size ioctls one after another
Try all the possible ioctls for disk size as long as they are supported, to keep the #if ladder simple. Extracted and cleaned up from a patch by Joelle van Dyne and Warner Losh. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
feccdceed2
commit
267cd53f5f
1 changed files with 16 additions and 18 deletions
|
@ -2327,39 +2327,37 @@ static int64_t raw_getlength(BlockDriverState *bs)
|
||||||
again:
|
again:
|
||||||
#endif
|
#endif
|
||||||
if (!fstat(fd, &sb) && (S_IFCHR & sb.st_mode)) {
|
if (!fstat(fd, &sb) && (S_IFCHR & sb.st_mode)) {
|
||||||
|
size = 0;
|
||||||
#ifdef DIOCGMEDIASIZE
|
#ifdef DIOCGMEDIASIZE
|
||||||
if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size))
|
if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) {
|
||||||
#elif defined(DIOCGPART)
|
size = 0;
|
||||||
{
|
}
|
||||||
struct partinfo pi;
|
#endif
|
||||||
if (ioctl(fd, DIOCGPART, &pi) == 0)
|
#ifdef DIOCGPART
|
||||||
size = pi.media_size;
|
if (size == 0) {
|
||||||
else
|
struct partinfo pi;
|
||||||
size = 0;
|
if (ioctl(fd, DIOCGPART, &pi) == 0) {
|
||||||
|
size = pi.media_size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (size == 0)
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
{
|
if (size == 0) {
|
||||||
uint64_t sectors = 0;
|
uint64_t sectors = 0;
|
||||||
uint32_t sector_size = 0;
|
uint32_t sector_size = 0;
|
||||||
|
|
||||||
if (ioctl(fd, DKIOCGETBLOCKCOUNT, §ors) == 0
|
if (ioctl(fd, DKIOCGETBLOCKCOUNT, §ors) == 0
|
||||||
&& ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) == 0) {
|
&& ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) == 0) {
|
||||||
size = sectors * sector_size;
|
size = sectors * sector_size;
|
||||||
} else {
|
|
||||||
size = lseek(fd, 0LL, SEEK_END);
|
|
||||||
if (size < 0) {
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#endif
|
||||||
size = lseek(fd, 0LL, SEEK_END);
|
if (size == 0) {
|
||||||
|
size = lseek(fd, 0LL, SEEK_END);
|
||||||
|
}
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
switch(s->type) {
|
switch(s->type) {
|
||||||
case FTYPE_CD:
|
case FTYPE_CD:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue