diff --git a/init/init.c b/init/init.c index 4667c289..30735bc2 100644 --- a/init/init.c +++ b/init/init.c @@ -224,7 +224,7 @@ static bool prepare_block_device(void* ctx, const char* path) } if ( !harddisk_inspect_blockdevice(hd) ) { - if ( errno == ENOTBLK ) + if ( errno == ENOTBLK || errno == ENOMEDIUM ) return true; if ( errno == EINVAL ) return warning("%s: %m", path), true; diff --git a/libc/include/errno.h b/libc/include/errno.h index 7cfd61ec..2806cb90 100644 --- a/libc/include/errno.h +++ b/libc/include/errno.h @@ -107,6 +107,7 @@ #define EPROTO 97 #define ETXTBSY 98 #define ENOMOUNT 99 +#define ENOMEDIUM 100 #define EOPNOTSUPP ENOTSUP #define EWOULDBLOCK EAGAIN diff --git a/libc/string/strerror.c b/libc/string/strerror.c index fa4729dd..39df8060 100644 --- a/libc/string/strerror.c +++ b/libc/string/strerror.c @@ -110,6 +110,7 @@ const char* sortix_strerror(int errnum) case EPROTO: return "Protocol error"; case ETXTBSY: return "Text file busy"; case ENOMOUNT: return "No such mountpoint"; + case ENOMEDIUM: return "No medium found"; default: return "Unknown error condition"; } } diff --git a/libmount/devices.c b/libmount/devices.c index 74ab7ecc..93fff444 100644 --- a/libmount/devices.c +++ b/libmount/devices.c @@ -107,7 +107,7 @@ static bool devices_iterate_open_callback(void* ctx_ptr, const char* path) } if ( !harddisk_inspect_blockdevice(hd) ) { - bool success = errno == ENOTBLK; + bool success = errno == ENOTBLK || errno == ENOMEDIUM; harddisk_close(hd); return success; } diff --git a/libmount/harddisk.c b/libmount/harddisk.c index c9939117..d9435338 100644 --- a/libmount/harddisk.c +++ b/libmount/harddisk.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2015, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -97,6 +97,8 @@ bool harddisk_inspect_blockdevice(struct harddisk* hd) return harddisk_close(hd), false; hd->sectors = (uint16_t) strtoul(str, NULL, 10); free(str); + if ( !hd->logical_block_size ) + return errno = ENOMEDIUM, false; // TODO: To avoid potential overflow bugs (assuming malicious filesystem), // reject ridiculous block sizes. if ( 65536 < hd->logical_block_size )