diff options
author | relan <relan@users.noreply.github.com> | 2014-06-01 19:28:12 +0000 |
---|---|---|
committer | relan <relan@users.noreply.github.com> | 2015-08-24 08:26:16 +0300 |
commit | a7da4aa7fd048ef07d9cc2ee796c6eb0a8385c68 (patch) | |
tree | 7d004c79b4ce96b77e50b9e36138572ce307ccda | |
parent | 7f46abf86d25e38d19f3b653ac3fa0fecd6e0e0a (diff) | |
download | android_external_exfat-a7da4aa7fd048ef07d9cc2ee796c6eb0a8385c68.tar.gz android_external_exfat-a7da4aa7fd048ef07d9cc2ee796c6eb0a8385c68.tar.bz2 android_external_exfat-a7da4aa7fd048ef07d9cc2ee796c6eb0a8385c68.zip |
Set errno to EROFS on failure to open the device in RW mode.
-rw-r--r-- | libexfat/io.c | 12 |
1 files 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 |