mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:47:45 +00:00
Kernel: Make major and minor numbers to be DistinctNumerics
This helps avoid confusion in general, and make constructors, methods and code patterns much more clean and understandable.
This commit is contained in:
parent
6d14940053
commit
9eb08bdb0f
24 changed files with 70 additions and 52 deletions
|
@ -13,8 +13,8 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
ATADevice::ATADevice(const ATAController& controller, ATADevice::Address ata_address, unsigned minor_number, u16 capabilities, u16 logical_sector_size, u64 max_addressable_block, NonnullOwnPtr<KString> early_storage_name)
|
||||
: StorageDevice(StorageManagement::major_number(), minor_number, logical_sector_size, max_addressable_block, move(early_storage_name))
|
||||
ATADevice::ATADevice(const ATAController& controller, ATADevice::Address ata_address, MinorNumber minor_number, u16 capabilities, u16 logical_sector_size, u64 max_addressable_block, NonnullOwnPtr<KString> early_storage_name)
|
||||
: StorageDevice(StorageManagement::storage_type_major_number(), minor_number, logical_sector_size, max_addressable_block, move(early_storage_name))
|
||||
, m_controller(controller)
|
||||
, m_ata_address(ata_address)
|
||||
, m_capabilities(capabilities)
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
const Address& ata_address() const { return m_ata_address; }
|
||||
|
||||
protected:
|
||||
ATADevice(const ATAController&, Address, unsigned, u16, u16, u64, NonnullOwnPtr<KString>);
|
||||
ATADevice(const ATAController&, Address, MinorNumber, u16, u16, u64, NonnullOwnPtr<KString>);
|
||||
|
||||
WeakPtr<ATAController> m_controller;
|
||||
const Address m_ata_address;
|
||||
|
|
|
@ -16,10 +16,10 @@ namespace Kernel {
|
|||
|
||||
NonnullRefPtr<ATADiskDevice> ATADiskDevice::create(const ATAController& controller, ATADevice::Address ata_address, u16 capabilities, u16 logical_sector_size, u64 max_addressable_block)
|
||||
{
|
||||
auto minor_device_number = StorageManagement::minor_number();
|
||||
auto minor_device_number = StorageManagement::generate_storage_minor_number();
|
||||
|
||||
// FIXME: We need a way of formatting strings with KString.
|
||||
auto device_name = String::formatted("hd{:c}", 'a' + minor_device_number);
|
||||
auto device_name = String::formatted("hd{:c}", 'a' + minor_device_number.value());
|
||||
auto device_name_kstring = KString::must_create(device_name.view());
|
||||
|
||||
auto disk_device_or_error = DeviceManagement::try_create_device<ATADiskDevice>(controller, ata_address, minor_device_number, capabilities, logical_sector_size, max_addressable_block, move(device_name_kstring));
|
||||
|
@ -28,7 +28,7 @@ NonnullRefPtr<ATADiskDevice> ATADiskDevice::create(const ATAController& controll
|
|||
return disk_device_or_error.release_value();
|
||||
}
|
||||
|
||||
ATADiskDevice::ATADiskDevice(const ATAController& controller, ATADevice::Address ata_address, unsigned minor_number, u16 capabilities, u16 logical_sector_size, u64 max_addressable_block, NonnullOwnPtr<KString> early_storage_name)
|
||||
ATADiskDevice::ATADiskDevice(const ATAController& controller, ATADevice::Address ata_address, MinorNumber minor_number, u16 capabilities, u16 logical_sector_size, u64 max_addressable_block, NonnullOwnPtr<KString> early_storage_name)
|
||||
: ATADevice(controller, ata_address, minor_number, capabilities, logical_sector_size, max_addressable_block, move(early_storage_name))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
virtual CommandSet command_set() const override { return CommandSet::ATA; }
|
||||
|
||||
private:
|
||||
ATADiskDevice(const ATAController&, Address, unsigned, u16, u16, u64, NonnullOwnPtr<KString>);
|
||||
ATADiskDevice(const ATAController&, Address, MinorNumber, u16, u16, u64, NonnullOwnPtr<KString>);
|
||||
|
||||
// ^DiskDevice
|
||||
virtual StringView class_name() const override;
|
||||
|
|
|
@ -16,19 +16,19 @@ namespace Kernel {
|
|||
|
||||
NonnullRefPtr<ATAPIDiscDevice> ATAPIDiscDevice::create(const ATAController& controller, ATADevice::Address ata_address, u16 capabilities, u64 max_addressable_block)
|
||||
{
|
||||
auto minor_device_number = StorageManagement::minor_number();
|
||||
auto minor_device_number = StorageManagement::generate_storage_minor_number();
|
||||
|
||||
// FIXME: We need a way of formatting strings with KString.
|
||||
auto device_name = String::formatted("hd{:c}", 'a' + minor_device_number);
|
||||
auto device_name = String::formatted("hd{:c}", 'a' + minor_device_number.value());
|
||||
auto device_name_kstring = KString::must_create(device_name.view());
|
||||
|
||||
auto disc_device_or_error = DeviceManagement::try_create_device<ATAPIDiscDevice>(controller, ata_address, minor_device_number, capabilities, max_addressable_block, move(device_name_kstring));
|
||||
auto disc_device_or_error = DeviceManagement::try_create_device<ATAPIDiscDevice>(controller, ata_address, minor_device_number.value(), capabilities, max_addressable_block, move(device_name_kstring));
|
||||
// FIXME: Find a way to propagate errors
|
||||
VERIFY(!disc_device_or_error.is_error());
|
||||
return disc_device_or_error.release_value();
|
||||
}
|
||||
|
||||
ATAPIDiscDevice::ATAPIDiscDevice(const ATAController& controller, ATADevice::Address ata_address, unsigned minor_number, u16 capabilities, u64 max_addressable_block, NonnullOwnPtr<KString> early_storage_name)
|
||||
ATAPIDiscDevice::ATAPIDiscDevice(const ATAController& controller, ATADevice::Address ata_address, MinorNumber minor_number, u16 capabilities, u64 max_addressable_block, NonnullOwnPtr<KString> early_storage_name)
|
||||
: ATADevice(controller, ata_address, minor_number, capabilities, 0, max_addressable_block, move(early_storage_name))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
virtual CommandSet command_set() const override { return CommandSet::SCSI; }
|
||||
|
||||
private:
|
||||
ATAPIDiscDevice(const ATAController&, Address, unsigned, u16, u64, NonnullOwnPtr<KString>);
|
||||
ATAPIDiscDevice(const ATAController&, Address, MinorNumber, u16, u64, NonnullOwnPtr<KString>);
|
||||
|
||||
// ^DiskDevice
|
||||
virtual StringView class_name() const override;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
StorageDevice::StorageDevice(int major, int minor, size_t sector_size, u64 max_addressable_block, NonnullOwnPtr<KString> device_name)
|
||||
StorageDevice::StorageDevice(MajorNumber major, MinorNumber minor, size_t sector_size, u64 max_addressable_block, NonnullOwnPtr<KString> device_name)
|
||||
: BlockDevice(major, minor, sector_size)
|
||||
, m_early_storage_device_name(move(device_name))
|
||||
, m_max_addressable_block(max_addressable_block)
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) final;
|
||||
|
||||
protected:
|
||||
StorageDevice(int, int, size_t, u64, NonnullOwnPtr<KString>);
|
||||
StorageDevice(MajorNumber, MinorNumber, size_t, u64, NonnullOwnPtr<KString>);
|
||||
// ^DiskDevice
|
||||
virtual StringView class_name() const override;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
namespace Kernel {
|
||||
|
||||
static Singleton<StorageManagement> s_the;
|
||||
static Atomic<size_t> s_device_minor_number;
|
||||
static Atomic<u32> s_device_minor_number;
|
||||
|
||||
static constexpr StringView partition_uuid_prefix = "PARTUUID="sv;
|
||||
|
||||
|
@ -179,11 +179,11 @@ RefPtr<BlockDevice> StorageManagement::boot_block_device() const
|
|||
return m_boot_block_device.strong_ref();
|
||||
}
|
||||
|
||||
int StorageManagement::major_number()
|
||||
MajorNumber StorageManagement::storage_type_major_number()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
int StorageManagement::minor_number()
|
||||
MinorNumber StorageManagement::generate_storage_minor_number()
|
||||
{
|
||||
auto minor_number = s_device_minor_number.load();
|
||||
s_device_minor_number++;
|
||||
|
|
|
@ -29,8 +29,8 @@ public:
|
|||
|
||||
NonnullRefPtr<FileSystem> root_filesystem() const;
|
||||
|
||||
static int major_number();
|
||||
static int minor_number();
|
||||
static MajorNumber storage_type_major_number();
|
||||
static MinorNumber generate_storage_minor_number();
|
||||
|
||||
void remove_device(StorageDevice&);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue