mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-31 14:02:05 -06:00
block/file-posix.c: Fix unused variable warning on OpenBSD
On OpenBSD none of the ioctls probe_logical_blocksize() tries exist, so the variable sector_size is unused. Refactor the code to avoid this (and reduce the duplicated code). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Jeff Cody <jcody@redhat.com> Message-id: 1490279788-12995-1-git-send-email-peter.maydell@linaro.org Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
e5bcf967fb
commit
700f9ce0f9
1 changed files with 14 additions and 14 deletions
|
@ -220,28 +220,28 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
|
||||||
{
|
{
|
||||||
unsigned int sector_size;
|
unsigned int sector_size;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
int i;
|
||||||
|
|
||||||
errno = ENOTSUP;
|
errno = ENOTSUP;
|
||||||
|
static const unsigned long ioctl_list[] = {
|
||||||
/* Try a few ioctls to get the right size */
|
|
||||||
#ifdef BLKSSZGET
|
#ifdef BLKSSZGET
|
||||||
if (ioctl(fd, BLKSSZGET, §or_size) >= 0) {
|
BLKSSZGET,
|
||||||
*sector_size_p = sector_size;
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef DKIOCGETBLOCKSIZE
|
#ifdef DKIOCGETBLOCKSIZE
|
||||||
if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >= 0) {
|
DKIOCGETBLOCKSIZE,
|
||||||
*sector_size_p = sector_size;
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef DIOCGSECTORSIZE
|
#ifdef DIOCGSECTORSIZE
|
||||||
if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >= 0) {
|
DIOCGSECTORSIZE,
|
||||||
*sector_size_p = sector_size;
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Try a few ioctls to get the right size */
|
||||||
|
for (i = 0; i < (int)ARRAY_SIZE(ioctl_list); i++) {
|
||||||
|
if (ioctl(fd, ioctl_list[i], §or_size) >= 0) {
|
||||||
|
*sector_size_p = sector_size;
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return success ? 0 : -errno;
|
return success ? 0 : -errno;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue