diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2016-12-23 10:13:23 +0100 |
---|---|---|
committer | Pali Rohár <pali.rohar@gmail.com> | 2016-12-23 10:13:23 +0100 |
commit | 82de19bee10d24737eca3b3ada1dd5863f492442 (patch) | |
tree | 561123474fa95d17c6772d81b4bbd1348efbbd63 | |
parent | b7c28b2c1bfab4783d6da431bef8288e32fdb136 (diff) | |
download | 0xFFFF-82de19bee10d24737eca3b3ada1dd5863f492442.tar.bz2 |
disk: Check for ENOMEDIUM when partition is required
-rw-r--r-- | src/disk.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -131,8 +131,18 @@ int disk_open_dev(int maj, int min, int partition, int readonly) { if ( stat(blkdev, &st) != 0 || ! S_ISBLK(st.st_mode) ) { memcpy(blkdev+len, "1", 2); if ( stat(blkdev, &st) != 0 || ! S_ISBLK(st.st_mode) ) { - ERROR("Block device has partitions"); - return -1; + blkdev[len] = 0; + fd = open(blkdev, O_RDONLY); + if ( fd < 0 ) { + if ( errno != ENOMEDIUM ) { + ERROR_INFO("Cannot open block device %s", blkdev); + return -1; + } + } else { + close(fd); + ERROR("Block device does not have partitions"); + return -1; + } } } |