diff options
author | Liav A <liavalb@gmail.com> | 2021-03-13 12:01:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-29 20:53:59 +0200 |
commit | 92c0dab5ab45ff0db8317439ea2f8bc3d96158c4 (patch) | |
tree | c2f13dc2ba91ebef415d3369867836eb4256b0ca /Kernel/SystemExposed.cpp | |
parent | dc6defa7af6ee0a4fe9331bf46311ba29f3df01b (diff) | |
download | serenity-92c0dab5ab45ff0db8317439ea2f8bc3d96158c4.zip |
Kernel: Introduce the new SysFS
The intention is to add dynamic mechanism for notifying the userspace
about hotplug events. Currently, the DMI (SMBIOS) blobs and ACPI tables
are exposed in the new filesystem.
Diffstat (limited to 'Kernel/SystemExposed.cpp')
-rw-r--r-- | Kernel/SystemExposed.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Kernel/SystemExposed.cpp b/Kernel/SystemExposed.cpp new file mode 100644 index 0000000000..12598dad7d --- /dev/null +++ b/Kernel/SystemExposed.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <Kernel/FileSystem/SysFS.h> +#include <Kernel/SystemExposed.h> + +namespace Kernel { + +static SpinLock<u8> s_index_lock; +static InodeIndex s_next_inode_index { 0 }; + +static size_t allocate_inode_index() +{ + ScopedSpinLock lock(s_index_lock); + s_next_inode_index = s_next_inode_index.value() + 1; + VERIFY(s_next_inode_index > 0); + return s_next_inode_index.value(); +} + +SystemExposedComponent::SystemExposedComponent(StringView name) + : m_name(KString::try_create(name).release_nonnull()) + , m_component_index(allocate_inode_index()) +{ +} + +KResult SystemExposedFolder::traverse_as_directory(unsigned fsid, Function<bool(const FS::DirectoryEntryView&)> callback) const +{ + Locker locker(SystemRegistrar::the().m_lock); + VERIFY(m_parent_folder); + callback({ ".", { fsid, component_index() }, 0 }); + callback({ "..", { fsid, m_parent_folder->component_index() }, 0 }); + + for (auto& component : m_components) { + InodeIdentifier identifier = { fsid, component.component_index() }; + callback({ component.name(), identifier, 0 }); + } + return KSuccess; +} + +RefPtr<SystemExposedComponent> SystemExposedFolder::lookup(StringView name) +{ + for (auto& component : m_components) { + if (component.name() == name) { + return component; + } + } + return {}; +} + +SystemExposedFolder::SystemExposedFolder(String name) + : SystemExposedComponent(name) +{ +} + +SystemExposedFolder::SystemExposedFolder(String name, const SystemExposedFolder& parent_folder) + : SystemExposedComponent(name) + , m_parent_folder(parent_folder) +{ +} + +NonnullRefPtr<Inode> SystemExposedFolder::to_inode(const SysFS& sysfs_instance) const +{ + return SysFSDirectoryInode::create(sysfs_instance, *this); +} + +NonnullRefPtr<Inode> SystemExposedComponent::to_inode(const SysFS& sysfs_instance) const +{ + return SysFSInode::create(sysfs_instance, *this); +} + +} |