1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:07:34 +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:
Sergey Bugaev 2019-08-18 14:48:15 +03:00 committed by Andreas Kling
parent d5352b87b7
commit acccf9ccda
6 changed files with 38 additions and 32 deletions

View file

@ -69,7 +69,7 @@ RefPtr<Inode> DevPtsFS::get_inode(InodeIdentifier inode_id) const
return m_root_inode;
unsigned pty_index = inode_index_to_pty_index(inode_id.index());
auto* device = VFS::the().get_device(11, pty_index);
auto* device = Device::get_device(11, pty_index);
ASSERT(device);
auto inode = adopt(*new DevPtsFSInode(const_cast<DevPtsFS&>(*this), inode_id.index()));

View file

@ -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
{

View file

@ -79,9 +79,6 @@ public:
KResult mknod(StringView path, mode_t, dev_t, Custody& base);
KResultOr<NonnullRefPtr<Custody>> open_directory(StringView path, Custody& base);
void register_device(Badge<Device>, Device&);
void unregister_device(Badge<Device>, Device&);
size_t mount_count() const { return m_mounts.size(); }
void for_each_mount(Function<void(const Mount&)>) const;
@ -89,8 +86,6 @@ public:
void sync();
Device* get_device(unsigned major, unsigned minor);
Custody& root_custody();
KResultOr<NonnullRefPtr<Custody>> resolve_path(StringView path, Custody& base, RefPtr<Custody>* parent = nullptr, int options = 0);
@ -110,7 +105,6 @@ private:
RefPtr<Inode> m_root_inode;
NonnullOwnPtrVector<Mount> m_mounts;
HashMap<u32, Device*> m_devices;
RefPtr<Custody> m_root_custody;
};