summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2018-02-08 19:48:34 +0100
committerPali Rohár <pali.rohar@gmail.com>2018-02-08 19:48:34 +0100
commita6c20b5ee46c39cf5c9e86bc6cd938ba56909dff (patch)
treee2e50c43b264d7f9e03f6ca02c6de82db5ae8a9d
parente685787e67c431579f8e2cf717a19174f154fe6c (diff)
download0xFFFF-a6c20b5ee46c39cf5c9e86bc6cd938ba56909dff.tar.bz2
disk: Open whole block device with O_NONBLOCK
This would simplify handling of ENOMEDIUM error.
-rw-r--r--src/disk.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/disk.c b/src/disk.c
index bb8ae02..2db197b 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -118,10 +118,9 @@ int disk_open_dev(int maj, int min, int partition, int readonly) {
blkdev[len] = 0;
- fd = open(blkdev, (readonly ? O_RDONLY : O_RDWR) | O_EXCL);
+ fd = open(blkdev, (readonly ? O_RDONLY : O_RDWR) | O_EXCL | O_NONBLOCK);
if ( fd < 0 ) {
- if ( errno != ENOMEDIUM )
- ERROR_INFO("Cannot open block device %s", blkdev);
+ ERROR_INFO("Cannot open block device %s", blkdev);
return -1;
} else {
if ( fstat(fd, &st) != 0 || ! S_ISBLK(st.st_mode) || makedev(maj, min) != st.st_rdev ) {
@@ -155,10 +154,9 @@ int disk_open_dev(int maj, int min, int partition, int readonly) {
}
if ( fd < 0 && errno == ENOENT ) {
blkdev[len] = 0;
- fd = open(blkdev, O_RDONLY);
+ fd = open(blkdev, O_RDONLY | O_NONBLOCK);
if ( fd < 0 ) {
- if ( errno != ENOMEDIUM )
- ERROR_INFO("Cannot open block device %s", blkdev);
+ ERROR_INFO("Cannot open block device %s", blkdev);
} else {
close(fd);
ERROR("Block device %s does not have partitions", blkdev);