summaryrefslogtreecommitdiff
path: root/Kernel/Storage
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2022-04-22 16:15:41 +0300
committerAndreas Kling <kling@serenityos.org>2022-07-15 12:29:23 +0200
commit7db6b77e7545f4224a4ebd2f0a97b753d291b4de (patch)
treea776cd3a2af9724b7143ab0a2cea21515a782025 /Kernel/Storage
parent6ff1aeb64dd4790598b108f77abbf7e8fed163a0 (diff)
downloadserenity-7db6b77e7545f4224a4ebd2f0a97b753d291b4de.zip
Kernel: Export both interface type and command set of a StorageDevice
Diffstat (limited to 'Kernel/Storage')
-rw-r--r--Kernel/Storage/ATA/ATADiskDevice.h1
-rw-r--r--Kernel/Storage/ATA/ATAPIDiscDevice.h1
-rw-r--r--Kernel/Storage/NVMe/NVMeNameSpace.h1
-rw-r--r--Kernel/Storage/Ramdisk/Device.h1
-rw-r--r--Kernel/Storage/StorageDevice.cpp34
-rw-r--r--Kernel/Storage/StorageDevice.h16
6 files changed, 54 insertions, 0 deletions
diff --git a/Kernel/Storage/ATA/ATADiskDevice.h b/Kernel/Storage/ATA/ATADiskDevice.h
index 4f08973ca8..5d611e0120 100644
--- a/Kernel/Storage/ATA/ATADiskDevice.h
+++ b/Kernel/Storage/ATA/ATADiskDevice.h
@@ -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
diff --git a/Kernel/Storage/ATA/ATAPIDiscDevice.h b/Kernel/Storage/ATA/ATAPIDiscDevice.h
index bfb80befe9..daed2e9c7e 100644
--- a/Kernel/Storage/ATA/ATAPIDiscDevice.h
+++ b/Kernel/Storage/ATA/ATAPIDiscDevice.h
@@ -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
diff --git a/Kernel/Storage/NVMe/NVMeNameSpace.h b/Kernel/Storage/NVMe/NVMeNameSpace.h
index b36cf2aa61..1890d71460 100644
--- a/Kernel/Storage/NVMe/NVMeNameSpace.h
+++ b/Kernel/Storage/NVMe/NVMeNameSpace.h
@@ -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;
};
diff --git a/Kernel/Storage/Ramdisk/Device.h b/Kernel/Storage/Ramdisk/Device.h
index 0e4ef6cca9..dc398281a8 100644
--- a/Kernel/Storage/Ramdisk/Device.h
+++ b/Kernel/Storage/Ramdisk/Device.h
@@ -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 };
diff --git a/Kernel/Storage/StorageDevice.cpp b/Kernel/Storage/StorageDevice.cpp
index 339b61cb31..6c8cc784cb 100644
--- a/Kernel/Storage/StorageDevice.cpp
+++ b/Kernel/Storage/StorageDevice.cpp
@@ -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();
diff --git a/Kernel/Storage/StorageDevice.h b/Kernel/Storage/StorageDevice.h
index 2b178bc744..a7747b1a11 100644
--- a/Kernel/Storage/StorageDevice.h
+++ b/Kernel/Storage/StorageDevice.h
@@ -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;