mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:07:45 +00:00
Kernel/SysFS: Add /sys/devices/storage directory
This change in fact does the following: 1. Use support for symlinks between /sys/dev/block/ storage device identifier nodes and devices in /sys/devices/storage/{LUN}. 2. Add basic nodes in a /sys/devices/storage/{LUN} directory, to let userspace to know about the device and its details.
This commit is contained in:
parent
22335e53e0
commit
1dbd32488f
19 changed files with 450 additions and 1 deletions
|
@ -7,7 +7,12 @@
|
|||
#include <AK/Memory.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/Debug.h>
|
||||
#include <Kernel/Devices/DeviceManagement.h>
|
||||
#include <Kernel/FileSystem/OpenFileDescription.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/SymbolicLinkDeviceComponent.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Devices/Storage/DeviceDirectory.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Devices/Storage/Directory.h>
|
||||
#include <Kernel/Storage/StorageDevice.h>
|
||||
#include <Kernel/Storage/StorageManagement.h>
|
||||
#include <LibC/sys/ioctl_numbers.h>
|
||||
|
@ -23,6 +28,33 @@ StorageDevice::StorageDevice(LUNAddress logical_unit_number_address, MajorNumber
|
|||
{
|
||||
}
|
||||
|
||||
void StorageDevice::after_inserting()
|
||||
{
|
||||
after_inserting_add_to_device_management();
|
||||
auto sysfs_storage_device_directory = StorageDeviceSysFSDirectory::create(SysFSStorageDirectory::the(), *this);
|
||||
m_sysfs_device_directory = sysfs_storage_device_directory;
|
||||
SysFSStorageDirectory::the().plug({}, *sysfs_storage_device_directory);
|
||||
VERIFY(!m_symlink_sysfs_component);
|
||||
auto sys_fs_component = MUST(SysFSSymbolicLinkDeviceComponent::try_create(SysFSDeviceIdentifiersDirectory::the(), *this, *m_sysfs_device_directory));
|
||||
m_symlink_sysfs_component = sys_fs_component;
|
||||
VERIFY(is_block_device());
|
||||
SysFSBlockDevicesDirectory::the().m_child_components.with([&](auto& list) -> void {
|
||||
list.append(sys_fs_component);
|
||||
});
|
||||
}
|
||||
|
||||
void StorageDevice::will_be_destroyed()
|
||||
{
|
||||
VERIFY(m_symlink_sysfs_component);
|
||||
VERIFY(is_block_device());
|
||||
SysFSBlockDevicesDirectory::the().m_child_components.with([&](auto& list) -> void {
|
||||
list.remove(*m_symlink_sysfs_component);
|
||||
});
|
||||
m_symlink_sysfs_component.clear();
|
||||
SysFSStorageDirectory::the().unplug({}, *m_sysfs_device_directory);
|
||||
before_will_be_destroyed_remove_from_device_management();
|
||||
}
|
||||
|
||||
StringView StorageDevice::class_name() const
|
||||
{
|
||||
return "StorageDevice"sv;
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace Kernel {
|
|||
|
||||
class StorageDevice : public BlockDevice {
|
||||
friend class StorageManagement;
|
||||
friend class DeviceManagement;
|
||||
|
||||
public:
|
||||
// Note: this attribute describes the internal command set of a Storage device.
|
||||
|
@ -92,6 +93,9 @@ protected:
|
|||
virtual StringView class_name() const override;
|
||||
|
||||
private:
|
||||
virtual void after_inserting() override;
|
||||
virtual void will_be_destroyed() override;
|
||||
|
||||
virtual InterfaceType interface_type() const = 0;
|
||||
mutable IntrusiveListNode<StorageDevice, RefPtr<StorageDevice>> m_list_node;
|
||||
NonnullRefPtrVector<DiskPartition> m_partitions;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue