mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
Kernel: Export both interface type and command set of a StorageDevice
This commit is contained in:
parent
6ff1aeb64d
commit
7db6b77e75
Notes:
sideshowbarker
2024-07-17 08:56:28 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/7db6b77e75 Pull-request: https://github.com/SerenityOS/serenity/pull/13779
|
@ -26,6 +26,7 @@ public:
|
|||
virtual CommandSet command_set() const override { return CommandSet::ATA; }
|
||||
|
||||
private:
|
||||
virtual InterfaceType interface_type() const override { return InterfaceType::ATA; }
|
||||
ATADiskDevice(ATAController const&, Address, MinorNumber, u16, u16, u64, NonnullOwnPtr<KString>);
|
||||
|
||||
// ^DiskDevice
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
virtual CommandSet command_set() const override { return CommandSet::SCSI; }
|
||||
|
||||
private:
|
||||
virtual InterfaceType interface_type() const override { return InterfaceType::ATA; }
|
||||
ATAPIDiscDevice(ATAController const&, Address, MinorNumber, u16, u64, NonnullOwnPtr<KString>);
|
||||
|
||||
// ^DiskDevice
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
void start_request(AsyncBlockDeviceRequest& request) override;
|
||||
|
||||
private:
|
||||
virtual InterfaceType interface_type() const override { return InterfaceType::NVMe; }
|
||||
u16 m_nsid;
|
||||
NonnullRefPtrVector<NVMeQueue> m_queues;
|
||||
};
|
||||
|
|
|
@ -32,6 +32,7 @@ private:
|
|||
|
||||
// ^StorageDevice
|
||||
virtual CommandSet command_set() const override { return CommandSet::PlainMemory; }
|
||||
virtual InterfaceType interface_type() const override { return InterfaceType::PlainMemory; }
|
||||
|
||||
Mutex m_lock { "RamdiskDevice"sv };
|
||||
|
||||
|
|
|
@ -27,6 +27,40 @@ StringView StorageDevice::class_name() const
|
|||
return "StorageDevice"sv;
|
||||
}
|
||||
|
||||
StringView StorageDevice::command_set_to_string_view() const
|
||||
{
|
||||
switch (command_set()) {
|
||||
case CommandSet::PlainMemory:
|
||||
return "memory"sv;
|
||||
case CommandSet::SCSI:
|
||||
return "scsi"sv;
|
||||
case CommandSet::ATA:
|
||||
return "ata"sv;
|
||||
case CommandSet::NVMe:
|
||||
return "nvme"sv;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
StringView StorageDevice::interface_type_to_string_view() const
|
||||
{
|
||||
switch (interface_type()) {
|
||||
case InterfaceType::PlainMemory:
|
||||
return "memory"sv;
|
||||
case InterfaceType::SCSI:
|
||||
return "scsi"sv;
|
||||
case InterfaceType::ATA:
|
||||
return "ata"sv;
|
||||
case InterfaceType::NVMe:
|
||||
return "nvme"sv;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
ErrorOr<size_t> StorageDevice::read(OpenFileDescription&, u64 offset, UserOrKernelBuffer& outbuf, size_t len)
|
||||
{
|
||||
u64 index = offset >> block_size_log();
|
||||
|
|
|
@ -33,6 +33,18 @@ public:
|
|||
NVMe,
|
||||
};
|
||||
|
||||
// Note: this attribute describes the interface type of a Storage device.
|
||||
// For example, an ordinary harddrive utilizes the ATA command set, while
|
||||
// an ATAPI device (e.g. Optical drive) that is connected to the ATA bus,
|
||||
// is actually using SCSI commands (packets) encapsulated inside an ATA command.
|
||||
// Therefore, an ATAPI device is still using the ATA interface.
|
||||
enum class InterfaceType {
|
||||
PlainMemory,
|
||||
SCSI,
|
||||
ATA,
|
||||
NVMe,
|
||||
};
|
||||
|
||||
public:
|
||||
virtual u64 max_addressable_block() const { return m_max_addressable_block; }
|
||||
|
||||
|
@ -52,6 +64,9 @@ public:
|
|||
|
||||
virtual CommandSet command_set() const = 0;
|
||||
|
||||
StringView interface_type_to_string_view() const;
|
||||
StringView command_set_to_string_view() const;
|
||||
|
||||
// ^File
|
||||
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) final;
|
||||
|
||||
|
@ -61,6 +76,7 @@ protected:
|
|||
virtual StringView class_name() const override;
|
||||
|
||||
private:
|
||||
virtual InterfaceType interface_type() const = 0;
|
||||
mutable IntrusiveListNode<StorageDevice, RefPtr<StorageDevice>> m_list_node;
|
||||
NonnullRefPtrVector<DiskPartition> m_partitions;
|
||||
|
||||
|
|
Loading…
Reference in a new issue