mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 22:34:59 +00:00
Kernel: Move device lookup to Device class itself
Previously, VFS stored a list of all devices, and devices had to register and unregister themselves with it. This cleans up things a bit.
This commit is contained in:
parent
d5352b87b7
commit
acccf9ccda
6 changed files with 38 additions and 32 deletions
|
@ -216,11 +216,11 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options
|
|||
}
|
||||
|
||||
if (metadata.is_device()) {
|
||||
auto it = m_devices.find(encoded_device(metadata.major_device, metadata.minor_device));
|
||||
if (it == m_devices.end()) {
|
||||
auto device = Device::get_device(metadata.major_device, metadata.minor_device);
|
||||
if (device == nullptr) {
|
||||
return KResult(-ENODEV);
|
||||
}
|
||||
auto descriptor_or_error = (*it).value->open(options);
|
||||
auto descriptor_or_error = device->open(options);
|
||||
if (descriptor_or_error.is_error())
|
||||
return descriptor_or_error.error();
|
||||
descriptor_or_error.value()->set_original_inode({}, inode);
|
||||
|
@ -615,23 +615,6 @@ InodeIdentifier VFS::Mount::host() const
|
|||
return m_host_custody->inode().identifier();
|
||||
}
|
||||
|
||||
void VFS::register_device(Badge<Device>, Device& device)
|
||||
{
|
||||
m_devices.set(encoded_device(device.major(), device.minor()), &device);
|
||||
}
|
||||
|
||||
void VFS::unregister_device(Badge<Device>, Device& device)
|
||||
{
|
||||
m_devices.remove(encoded_device(device.major(), device.minor()));
|
||||
}
|
||||
|
||||
Device* VFS::get_device(unsigned major, unsigned minor)
|
||||
{
|
||||
auto it = m_devices.find(encoded_device(major, minor));
|
||||
if (it == m_devices.end())
|
||||
return nullptr;
|
||||
return (*it).value;
|
||||
}
|
||||
|
||||
void VFS::for_each_mount(Function<void(const Mount&)> callback) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue