Kernel: Implement DevFileSystem::remove_device

This function cleanly removes the devices from the whole filesystem.

USB devices are now removed from the filesystem as soon as they are
destroyed.
This commit is contained in:
Bananymous 2024-07-15 22:09:21 +03:00
parent 0578d41500
commit 9d7f97ccd5
3 changed files with 21 additions and 1 deletions

View File

@ -18,6 +18,8 @@ namespace Kernel
void initialize_device_updater();
void add_device(BAN::RefPtr<Device>);
void remove_device(BAN::RefPtr<Device>);
void add_inode(BAN::StringView path, BAN::RefPtr<TmpInode>);
void initiate_sync(bool should_block);

View File

@ -112,6 +112,21 @@ namespace Kernel
MUST(m_devices.push_back(device));
}
void DevFileSystem::remove_device(BAN::RefPtr<Device> device)
{
LockGuard _(m_device_lock);
ASSERT(!device->name().contains('/'));
MUST(static_cast<TmpDirectoryInode*>(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<TmpInode> inode)
{
ASSERT(!inode->is_device());

View File

@ -78,7 +78,10 @@ namespace Kernel
{}
USBHIDDriver::~USBHIDDriver()
{}
{
if (m_hid_device)
DevFileSystem::get().remove_device(m_hid_device);
}
BAN::ErrorOr<void> USBHIDDriver::initialize()
{