mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
Kernel: Use global mechanism to determine minor number of Storage Device
This commit is contained in:
parent
566c10b8b8
commit
b59e45e65c
7 changed files with 31 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -48,6 +48,9 @@ public:
|
|||
|
||||
NonnullRefPtr<FS> root_filesystem() const;
|
||||
|
||||
static int major_number();
|
||||
static int minor_number();
|
||||
|
||||
NonnullRefPtrVector<StorageController> ide_controllers() const;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue