disk: Check for ENOMEDIUM when partition is required

This commit is contained in:
Pali Rohár committed 2016-12-23 10:13:23 +01:00
1 parent b7c28b2c1b
commit 82de19bee1
1 file changed
+11 -1
+11 -1
View File
@@ -131,9 +131,19 @@ int disk_open_dev(int maj, int min, int partition, int readonly) {
if ( stat(blkdev, &st) != 0 || ! S_ISBLK(st.st_mode) ) { if ( stat(blkdev, &st) != 0 || ! S_ISBLK(st.st_mode) ) {
memcpy(blkdev+len, "1", 2); memcpy(blkdev+len, "1", 2);
if ( stat(blkdev, &st) != 0 || ! S_ISBLK(st.st_mode) ) { if ( stat(blkdev, &st) != 0 || ! S_ISBLK(st.st_mode) ) {
ERROR("Block device has partitions"); blkdev[len] = 0;
fd = open(blkdev, O_RDONLY);
if ( fd < 0 ) {
if ( errno != ENOMEDIUM ) {
ERROR_INFO("Cannot open block device %s", blkdev);
return -1; return -1;
} }
} else {
close(fd);
ERROR("Block device does not have partitions");
return -1;
}
}
} }
printf("Found block device %s for partition %d\n", blkdev, partition); printf("Found block device %s for partition %d\n", blkdev, partition);