浏览代码

Kernel: Use global mechanism to determine minor number of Storage Device

Liav A 4 年之前
父节点
当前提交
b59e45e65c

+ 2 - 2
Kernel/Storage/IDEChannel.cpp

@@ -381,9 +381,9 @@ UNMAP_AFTER_INIT void IDEChannel::detect_disks()
         dbgln("IDEChannel: {} {} device found: Type={}, Name={}, C/H/Spt={}/{}/{}, Capabilities=0x{:04x}", channel_type_string(), channel_string(i), interface_type == PATADiskDevice::InterfaceType::ATA ? "ATA" : "ATAPI", ((char*)bbuf.data() + 54), cyls, heads, spt, capabilities);
 
         if (i == 0) {
-            m_master = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Master, interface_type, cyls, heads, spt, capabilities, 3, (m_channel_type == ChannelType::Primary) ? 0 : 2);
+            m_master = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Master, interface_type, cyls, heads, spt, capabilities);
         } else {
-            m_slave = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Slave, interface_type, cyls, heads, spt, capabilities, 3, (m_channel_type == ChannelType::Primary) ? 1 : 3);
+            m_slave = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Slave, interface_type, cyls, heads, spt, capabilities);
         }
     }
 }

+ 4 - 4
Kernel/Storage/PATADiskDevice.cpp

@@ -33,13 +33,13 @@
 
 namespace Kernel {
 
-UNMAP_AFTER_INIT NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 cylinders, u16 heads, u16 spt, u16 capabilities, int major, int minor)
+UNMAP_AFTER_INIT NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 cylinders, u16 heads, u16 spt, u16 capabilities)
 {
-    return adopt(*new PATADiskDevice(controller, channel, type, interface_type, cylinders, heads, spt, capabilities, major, minor));
+    return adopt(*new PATADiskDevice(controller, channel, type, interface_type, cylinders, heads, spt, capabilities));
 }
 
-UNMAP_AFTER_INIT PATADiskDevice::PATADiskDevice(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 cylinders, u16 heads, u16 spt, u16 capabilities, int major, int minor)
-    : StorageDevice(controller, major, minor, 512, 0)
+UNMAP_AFTER_INIT PATADiskDevice::PATADiskDevice(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 cylinders, u16 heads, u16 spt, u16 capabilities)
+    : StorageDevice(controller, 512, 0)
     , m_cylinders(cylinders)
     , m_heads(heads)
     , m_sectors_per_track(spt)

+ 2 - 2
Kernel/Storage/PATADiskDevice.h

@@ -57,7 +57,7 @@ public:
     };
 
 public:
-    static NonnullRefPtr<PATADiskDevice> create(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u16, u16, u16, int major, int minor);
+    static NonnullRefPtr<PATADiskDevice> create(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u16, u16, u16);
     virtual ~PATADiskDevice() override;
 
     // ^StorageDevice
@@ -69,7 +69,7 @@ public:
     virtual String device_name() const override;
 
 private:
-    PATADiskDevice(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u16, u16, u16, int major, int minor);
+    PATADiskDevice(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u16, u16, u16);
 
     // ^DiskDevice
     virtual const char* class_name() const override;

+ 8 - 0
Kernel/Storage/StorageDevice.cpp

@@ -29,9 +29,17 @@
 #include <Kernel/Debug.h>
 #include <Kernel/FileSystem/FileDescription.h>
 #include <Kernel/Storage/StorageDevice.h>
+#include <Kernel/Storage/StorageManagement.h>
 
 namespace Kernel {
 
+StorageDevice::StorageDevice(const StorageController& controller, size_t sector_size, size_t max_addressable_block)
+    : BlockDevice(StorageManagement::major_number(), StorageManagement::minor_number(), sector_size)
+    , m_storage_controller(controller)
+    , m_max_addressable_block(max_addressable_block)
+{
+}
+
 StorageDevice::StorageDevice(const StorageController& controller, int major, int minor, size_t sector_size, size_t max_addressable_block)
     : BlockDevice(major, minor, sector_size)
     , m_storage_controller(controller)

+ 1 - 0
Kernel/Storage/StorageDevice.h

@@ -61,6 +61,7 @@ public:
     virtual mode_t required_mode() const override { return 0600; }
 
 protected:
+    StorageDevice(const StorageController&, size_t, size_t);
     StorageDevice(const StorageController&, int, int, size_t, size_t);
     // ^DiskDevice
     virtual const char* class_name() const override;

+ 11 - 0
Kernel/Storage/StorageManagement.cpp

@@ -40,6 +40,7 @@
 namespace Kernel {
 
 static StorageManagement* s_the;
+static size_t s_device_minor_number;
 
 UNMAP_AFTER_INIT StorageManagement::StorageManagement(String boot_argument, bool force_pio)
     : m_boot_argument(boot_argument)
@@ -47,6 +48,7 @@ UNMAP_AFTER_INIT StorageManagement::StorageManagement(String boot_argument, bool
     , m_storage_devices(enumerate_storage_devices())
     , m_disk_partitions(enumerate_disk_partitions())
 {
+    s_device_minor_number = 0;
     if (!boot_argument_contains_partition_uuid()) {
         determine_boot_device();
         return;
@@ -177,6 +179,15 @@ RefPtr<BlockDevice> StorageManagement::boot_block_device() const
     return m_boot_block_device;
 }
 
+int StorageManagement::major_number()
+{
+    return 3;
+}
+int StorageManagement::minor_number()
+{
+    return s_device_minor_number++;
+}
+
 NonnullRefPtr<FS> StorageManagement::root_filesystem() const
 {
     auto boot_device_description = boot_block_device();

+ 3 - 0
Kernel/Storage/StorageManagement.h

@@ -48,6 +48,9 @@ public:
 
     NonnullRefPtr<FS> root_filesystem() const;
 
+    static int major_number();
+    static int minor_number();
+
     NonnullRefPtrVector<StorageController> ide_controllers() const;
 
 private: