diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2017-03-23 14:36:28 +0000 |
---|---|---|
committer | Max Reitz <mreitz@redhat.com> | 2017-03-27 17:28:34 +0200 |
commit | 700f9ce0f9f49675818ac95c8953cbc65aa1d112 (patch) | |
tree | cea7e24f4550df6cd8b930cf42a4a7234973b752 /block/file-posix.c | |
parent | e5bcf967fb80ff9cf4d0c0d643e985ec5ff94e91 (diff) |
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>
Diffstat (limited to 'block/file-posix.c')
-rw-r--r-- | block/file-posix.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/block/file-posix.c b/block/file-posix.c index beb7a4f728..0841a08785 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -220,28 +220,28 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p) { unsigned int sector_size; bool success = false; + int i; errno = ENOTSUP; - - /* Try a few ioctls to get the right size */ + static const unsigned long ioctl_list[] = { #ifdef BLKSSZGET - if (ioctl(fd, BLKSSZGET, §or_size) >= 0) { - *sector_size_p = sector_size; - success = true; - } + BLKSSZGET, #endif #ifdef DKIOCGETBLOCKSIZE - if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >= 0) { - *sector_size_p = sector_size; - success = true; - } + DKIOCGETBLOCKSIZE, #endif #ifdef DIOCGSECTORSIZE - if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >= 0) { - *sector_size_p = sector_size; - success = true; - } + DIOCGSECTORSIZE, #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; } |