From a7da4aa7fd048ef07d9cc2ee796c6eb0a8385c68 Mon Sep 17 00:00:00 2001 From: relan Date: Sun, 1 Jun 2014 19:28:12 +0000 Subject: [PATCH] Set errno to EROFS on failure to open the device in RW mode. --- libexfat/io.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libexfat/io.c b/libexfat/io.c index 2bdfc43..ad71036 100644 --- a/libexfat/io.c +++ b/libexfat/io.c @@ -65,12 +65,20 @@ static int open_rw(const char* spec) int ro = 0; /* - This ioctl is needed because after "blockdev --setro" kernel still + This code is needed because after "blockdev --setro" kernel still allows to open the device in read-write mode but fails writes. */ - if (fd != -1 && ioctl(fd, BLKROGET, &ro) == 0 && ro) + if (fd == -1) + return -1; + if (ioctl(fd, BLKROGET, &ro) != 0) + { + close(fd); + return -1; + } + if (ro) { close(fd); + errno = EROFS; return -1; } #endif -- 2.11.0