diff options
author | Liav A <liavalb@gmail.com> | 2022-04-23 11:48:40 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-07-15 12:29:23 +0200 |
commit | 1dbd32488f746a27c6a98f84abb96bdfd8578444 (patch) | |
tree | 69028bb07608696b8537f966218cd74a2b15acd2 /Kernel/Storage/StorageDevice.cpp | |
parent | 22335e53e0a3bfde31bb48514301eabcd17468c6 (diff) | |
download | serenity-1dbd32488f746a27c6a98f84abb96bdfd8578444.zip |
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.
Diffstat (limited to 'Kernel/Storage/StorageDevice.cpp')
-rw-r--r-- | Kernel/Storage/StorageDevice.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Kernel/Storage/StorageDevice.cpp b/Kernel/Storage/StorageDevice.cpp index 8ca455ea81..991962878c 100644 --- a/Kernel/Storage/StorageDevice.cpp +++ b/Kernel/Storage/StorageDevice.cpp @@ -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; |