aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-03-20 17:39:17 +0000
committerPeter Maydell <peter.maydell@linaro.org>2017-03-20 17:39:17 +0000
commit06f7d23b78350e34c95f97b7cf386152ee370b31 (patch)
tree10a551bb8850eac2fb8a632ece02af44caa749c1
parent55104bfb884ebf3c350833837b4523ed21a5e129 (diff)
block/file-posix.c: Fix unused variable warning on OpenBSDbsd-fixes
On OpenBSD none of the ioctls probe_logical_blocksize() tries exist, so the variable sector_size is unused. Refactor the code to avoid this. Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--block/file-posix.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/block/file-posix.c b/block/file-posix.c
index 53febd3767..b980d23441 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -219,28 +219,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 */
+ unsigned long ioctl_list[] = {
#ifdef BLKSSZGET
- if (ioctl(fd, BLKSSZGET, &sector_size) >= 0) {
- *sector_size_p = sector_size;
- success = true;
- }
+ BLKSSZGET,
#endif
#ifdef DKIOCGETBLOCKSIZE
- if (ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size) >= 0) {
- *sector_size_p = sector_size;
- success = true;
- }
+ DKIOCGETBLOCKSIZE,
#endif
#ifdef DIOCGSECTORSIZE
- if (ioctl(fd, DIOCGSECTORSIZE, &sector_size) >= 0) {
- *sector_size_p = sector_size;
- success = true;
- }
+ DIOCGSECTORSIZE,
#endif
+ };
+
+ /* Try a few ioctls to get the right size */
+ for (i = 0; i < ARRAY_SIZE(ioctl_list); i++) {
+ if (ioctl(fd, ioctl_list[i], &sector_size) >= 0) {
+ *sector_size_p = sector_size;
+ success = true;
+ }
+ }
return success ? 0 : -errno;
}