Kernel: Add procfs that contains only pids

This commit is contained in:
Bananymous
2023-09-30 21:19:36 +03:00
parent 56bb419884
commit 8f630a97df
9 changed files with 135 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
#include <kernel/FS/ProcFS/FileSystem.h>
#include <kernel/FS/ProcFS/Inode.h>
#include <kernel/FS/RamFS/Inode.h>
#include <kernel/LockGuard.h>
namespace Kernel
{
static ProcFileSystem* s_instance = nullptr;
void ProcFileSystem::initialize()
{
ASSERT(s_instance == nullptr);
s_instance = new ProcFileSystem(1024 * 1024);
ASSERT(s_instance);
s_instance->m_root_inode = MUST(RamDirectoryInode::create(*s_instance, 0, 0555, 0, 0));
MUST(s_instance->set_root_inode(s_instance->m_root_inode));
}
ProcFileSystem& ProcFileSystem::get()
{
ASSERT(s_instance);
return *s_instance;
}
ProcFileSystem::ProcFileSystem(size_t size)
: RamFileSystem(size)
{
}
BAN::ErrorOr<void> ProcFileSystem::on_process_create(Process& process)
{
auto path = BAN::String::formatted("{}", process.pid());
auto inode = TRY(ProcPidInode::create(process, *this, 0555, 0, 0));
TRY(m_root_inode->add_inode(path, inode));
return {};
}
void ProcFileSystem::on_process_delete(Process& process)
{
auto path = BAN::String::formatted("{}", process.pid());
MUST(m_root_inode->delete_inode(path));
}
}

View File

@@ -0,0 +1,26 @@
#include <kernel/FS/ProcFS/Inode.h>
namespace Kernel
{
BAN::ErrorOr<BAN::RefPtr<ProcPidInode>> ProcPidInode::create(Process& process, RamFileSystem& fs, mode_t mode, uid_t uid, gid_t gid)
{
FullInodeInfo inode_info(fs, mode, uid, gid);
auto* inode_ptr = new ProcPidInode(process, fs, inode_info);
if (inode_ptr == nullptr)
return BAN::Error::from_errno(ENOMEM);
auto inode = BAN::RefPtr<ProcPidInode>::adopt(inode_ptr);
TRY(inode->add_inode("meminfo"sv, MUST(ProcMemInode::create(process, fs, 0755, 0, 0))));
return inode;
}
ProcPidInode::ProcPidInode(Process& process, RamFileSystem& fs, const FullInodeInfo& inode_info)
: RamDirectoryInode(fs, inode_info, fs.root_inode()->ino())
, m_process(process)
{
}
}