From 3af70cb0fcaddbf1d9888608496a474ab0f36c1b Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 16 Jul 2022 10:39:57 +0300 Subject: Kernel/Devices: Abstract SysFS Device add/remove methods more properly It is starting to get a little messy with how each device can try to add or remove itself to either /sys/dev/block or /sys/dev/char directories. To better do this, we introduce 4 virtual methods to take care of that, so until we ensure all nodes in /sys/dev/block and /sys/dev/char are actual symlinks, we allow the Device base class to call virtual methods upon insertion or before being destroying, so it add itself elegantly to either of these directories or remove itself when needed. For special cases where we need to create symlinks, we have two virtual methods to be called otherwise to do almost the same thing mentioned before, but to use symlinks instead. --- Kernel/Graphics/DisplayConnector.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'Kernel/Graphics/DisplayConnector.cpp') diff --git a/Kernel/Graphics/DisplayConnector.cpp b/Kernel/Graphics/DisplayConnector.cpp index 9cf8f327b8..4f117b8490 100644 --- a/Kernel/Graphics/DisplayConnector.cpp +++ b/Kernel/Graphics/DisplayConnector.cpp @@ -62,10 +62,8 @@ void DisplayConnector::will_be_destroyed() GraphicsManagement::the().detach_display_connector({}, *this); VERIFY(m_symlink_sysfs_component); - VERIFY(!is_block_device()); - SysFSCharacterDevicesDirectory::the().m_child_components.with([&](auto& list) -> void { - list.remove(*m_symlink_sysfs_component); - }); + before_will_be_destroyed_remove_symlink_from_device_identifier_directory(); + m_symlink_sysfs_component.clear(); SysFSDisplayConnectorsDirectory::the().unplug({}, *m_sysfs_device_directory); before_will_be_destroyed_remove_from_device_management(); @@ -80,10 +78,7 @@ void DisplayConnector::after_inserting() 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()); - SysFSCharacterDevicesDirectory::the().m_child_components.with([&](auto& list) -> void { - list.append(*m_symlink_sysfs_component); - }); + after_inserting_add_symlink_to_device_identifier_directory(); auto rounded_size = MUST(Memory::page_round_up(m_framebuffer_resource_size)); -- cgit v1.2.3