diff --git a/kernel/include/kernel/FS/DevFS/FileSystem.h b/kernel/include/kernel/FS/DevFS/FileSystem.h index 3e7feee7..a27c606e 100644 --- a/kernel/include/kernel/FS/DevFS/FileSystem.h +++ b/kernel/include/kernel/FS/DevFS/FileSystem.h @@ -18,6 +18,8 @@ namespace Kernel void initialize_device_updater(); void add_device(BAN::RefPtr); + void remove_device(BAN::RefPtr); + void add_inode(BAN::StringView path, BAN::RefPtr); void initiate_sync(bool should_block); diff --git a/kernel/kernel/FS/DevFS/FileSystem.cpp b/kernel/kernel/FS/DevFS/FileSystem.cpp index 92c40ec2..902700c5 100644 --- a/kernel/kernel/FS/DevFS/FileSystem.cpp +++ b/kernel/kernel/FS/DevFS/FileSystem.cpp @@ -112,6 +112,21 @@ namespace Kernel MUST(m_devices.push_back(device)); } + void DevFileSystem::remove_device(BAN::RefPtr device) + { + LockGuard _(m_device_lock); + ASSERT(!device->name().contains('/')); + MUST(static_cast(root_inode().ptr())->unlink(device->name())); + for (size_t i = 0; i < m_devices.size(); i++) + { + if (m_devices[i] == device) + { + m_devices.remove(i); + break; + } + } + } + void DevFileSystem::add_inode(BAN::StringView path, BAN::RefPtr inode) { ASSERT(!inode->is_device()); diff --git a/kernel/kernel/USB/HID/HIDDriver.cpp b/kernel/kernel/USB/HID/HIDDriver.cpp index 19f878b3..ec895361 100644 --- a/kernel/kernel/USB/HID/HIDDriver.cpp +++ b/kernel/kernel/USB/HID/HIDDriver.cpp @@ -78,7 +78,10 @@ namespace Kernel {} USBHIDDriver::~USBHIDDriver() - {} + { + if (m_hid_device) + DevFileSystem::get().remove_device(m_hid_device); + } BAN::ErrorOr USBHIDDriver::initialize() {