diff options
author | Liav A <liavalb@gmail.com> | 2021-12-23 20:08:18 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-23 23:02:39 +0100 |
commit | 9eb08bdb0f7460eb9874a5d16f6f3808f3d8a8f0 (patch) | |
tree | 79c20875f3cd0977fc809964f2e5f7a771ce1428 /Kernel/Storage | |
parent | 6d149400534643d2d4549853b257c136c3a8d47c (diff) | |
download | serenity-9eb08bdb0f7460eb9874a5d16f6f3808f3d8a8f0.zip |
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.
Diffstat (limited to 'Kernel/Storage')
-rw-r--r-- | Kernel/Storage/ATA/ATADevice.cpp | 4 | ||||
-rw-r--r-- | Kernel/Storage/ATA/ATADevice.h | 2 | ||||
-rw-r--r-- | Kernel/Storage/ATA/ATADiskDevice.cpp | 6 | ||||
-rw-r--r-- | Kernel/Storage/ATA/ATADiskDevice.h | 2 | ||||
-rw-r--r-- | Kernel/Storage/ATA/ATAPIDiscDevice.cpp | 8 | ||||
-rw-r--r-- | Kernel/Storage/ATA/ATAPIDiscDevice.h | 2 | ||||
-rw-r--r-- | Kernel/Storage/StorageDevice.cpp | 2 | ||||
-rw-r--r-- | Kernel/Storage/StorageDevice.h | 2 | ||||
-rw-r--r-- | Kernel/Storage/StorageManagement.cpp | 6 | ||||
-rw-r--r-- | Kernel/Storage/StorageManagement.h | 4 |
10 files changed, 19 insertions, 19 deletions
diff --git a/Kernel/Storage/ATA/ATADevice.cpp b/Kernel/Storage/ATA/ATADevice.cpp index 7e24a0cc68..c40f5b4eec 100644 --- a/Kernel/Storage/ATA/ATADevice.cpp +++ b/Kernel/Storage/ATA/ATADevice.cpp @@ -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) diff --git a/Kernel/Storage/ATA/ATADevice.h b/Kernel/Storage/ATA/ATADevice.h index 9c32d2d110..e469dcfe8c 100644 --- a/Kernel/Storage/ATA/ATADevice.h +++ b/Kernel/Storage/ATA/ATADevice.h @@ -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; diff --git a/Kernel/Storage/ATA/ATADiskDevice.cpp b/Kernel/Storage/ATA/ATADiskDevice.cpp index 3d7af895be..09e867164f 100644 --- a/Kernel/Storage/ATA/ATADiskDevice.cpp +++ b/Kernel/Storage/ATA/ATADiskDevice.cpp @@ -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)) { } diff --git a/Kernel/Storage/ATA/ATADiskDevice.h b/Kernel/Storage/ATA/ATADiskDevice.h index 6a5492f838..c71672321e 100644 --- a/Kernel/Storage/ATA/ATADiskDevice.h +++ b/Kernel/Storage/ATA/ATADiskDevice.h @@ -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; diff --git a/Kernel/Storage/ATA/ATAPIDiscDevice.cpp b/Kernel/Storage/ATA/ATAPIDiscDevice.cpp index 7c60f54a14..984312bf08 100644 --- a/Kernel/Storage/ATA/ATAPIDiscDevice.cpp +++ b/Kernel/Storage/ATA/ATAPIDiscDevice.cpp @@ -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)) { } diff --git a/Kernel/Storage/ATA/ATAPIDiscDevice.h b/Kernel/Storage/ATA/ATAPIDiscDevice.h index 0556fb97d1..12a18bde33 100644 --- a/Kernel/Storage/ATA/ATAPIDiscDevice.h +++ b/Kernel/Storage/ATA/ATAPIDiscDevice.h @@ -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; diff --git a/Kernel/Storage/StorageDevice.cpp b/Kernel/Storage/StorageDevice.cpp index 52e304e005..dc126b379b 100644 --- a/Kernel/Storage/StorageDevice.cpp +++ b/Kernel/Storage/StorageDevice.cpp @@ -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) diff --git a/Kernel/Storage/StorageDevice.h b/Kernel/Storage/StorageDevice.h index a34908c6c7..8472009669 100644 --- a/Kernel/Storage/StorageDevice.h +++ b/Kernel/Storage/StorageDevice.h @@ -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; diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp index e14aae4bb7..c64571846e 100644 --- a/Kernel/Storage/StorageManagement.cpp +++ b/Kernel/Storage/StorageManagement.cpp @@ -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++; diff --git a/Kernel/Storage/StorageManagement.h b/Kernel/Storage/StorageManagement.h index 656a5f5a71..131d23b90b 100644 --- a/Kernel/Storage/StorageManagement.h +++ b/Kernel/Storage/StorageManagement.h @@ -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&); |