Commit 700f9ce0 authored by Peter Maydell's avatar Peter Maydell Committed by Max Reitz
Browse files

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: default avatarPeter Maydell <peter.maydell@linaro.org>
Reviewed-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: default avatarJeff Cody <jcody@redhat.com>
Message-id: 1490279788-12995-1-git-send-email-peter.maydell@linaro.org
Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
parent e5bcf967
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -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, &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) {
        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], &sector_size) >= 0) {
            *sector_size_p = sector_size;
            success = true;
        }
#endif
    }

    return success ? 0 : -errno;
}