1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add ENOMEDIUM.

This commit is contained in:
Jonas 'Sortie' Termansen 2021-05-29 00:37:23 +02:00
parent 18ba2d2fe3
commit 1c9233e0c9
5 changed files with 7 additions and 3 deletions

View file

@ -224,7 +224,7 @@ static bool prepare_block_device(void* ctx, const char* path)
} }
if ( !harddisk_inspect_blockdevice(hd) ) if ( !harddisk_inspect_blockdevice(hd) )
{ {
if ( errno == ENOTBLK ) if ( errno == ENOTBLK || errno == ENOMEDIUM )
return true; return true;
if ( errno == EINVAL ) if ( errno == EINVAL )
return warning("%s: %m", path), true; return warning("%s: %m", path), true;

View file

@ -107,6 +107,7 @@
#define EPROTO 97 #define EPROTO 97
#define ETXTBSY 98 #define ETXTBSY 98
#define ENOMOUNT 99 #define ENOMOUNT 99
#define ENOMEDIUM 100
#define EOPNOTSUPP ENOTSUP #define EOPNOTSUPP ENOTSUP
#define EWOULDBLOCK EAGAIN #define EWOULDBLOCK EAGAIN

View file

@ -110,6 +110,7 @@ const char* sortix_strerror(int errnum)
case EPROTO: return "Protocol error"; case EPROTO: return "Protocol error";
case ETXTBSY: return "Text file busy"; case ETXTBSY: return "Text file busy";
case ENOMOUNT: return "No such mountpoint"; case ENOMOUNT: return "No such mountpoint";
case ENOMEDIUM: return "No medium found";
default: return "Unknown error condition"; default: return "Unknown error condition";
} }
} }

View file

@ -107,7 +107,7 @@ static bool devices_iterate_open_callback(void* ctx_ptr, const char* path)
} }
if ( !harddisk_inspect_blockdevice(hd) ) if ( !harddisk_inspect_blockdevice(hd) )
{ {
bool success = errno == ENOTBLK; bool success = errno == ENOTBLK || errno == ENOMEDIUM;
harddisk_close(hd); harddisk_close(hd);
return success; return success;
} }

View file

@ -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 * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * 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; return harddisk_close(hd), false;
hd->sectors = (uint16_t) strtoul(str, NULL, 10); hd->sectors = (uint16_t) strtoul(str, NULL, 10);
free(str); free(str);
if ( !hd->logical_block_size )
return errno = ENOMEDIUM, false;
// TODO: To avoid potential overflow bugs (assuming malicious filesystem), // TODO: To avoid potential overflow bugs (assuming malicious filesystem),
// reject ridiculous block sizes. // reject ridiculous block sizes.
if ( 65536 < hd->logical_block_size ) if ( 65536 < hd->logical_block_size )