ladybird/Kernel/ProcFileSystem.cpp
Andreas Kling bca4b71bfa Lots of hacking to make a very simple "ls" utility.
I added a dead-simple malloc that only allows allocations < 4096 bytes.
It just forwards the request to mmap() every time.

I also added simplified versions of opendir() and readdir().
2018-10-24 12:50:07 +02:00

49 lines
1.3 KiB
C++

#include "ProcFileSystem.h"
#include "Task.h"
RetainPtr<ProcFileSystem> ProcFileSystem::create()
{
return adopt(*new ProcFileSystem);
}
ProcFileSystem::ProcFileSystem()
{
}
ProcFileSystem::~ProcFileSystem()
{
}
bool ProcFileSystem::initialize()
{
SyntheticFileSystem::initialize();
addFile(createGeneratedFile("summary", [] {
InterruptDisabler disabler;
auto tasks = Task::allTasks();
char* buffer;
auto stringImpl = StringImpl::createUninitialized(tasks.size() * 256, buffer);
memset(buffer, 0, stringImpl->length());
char* ptr = buffer;
ptr += ksprintf(ptr, "PID OWNER STATE NSCHED FDS NAME\n");
for (auto* task : tasks) {
ptr += ksprintf(ptr, "%w %w:%w %b %w %w %s\n",
task->pid(),
task->uid(),
task->gid(),
task->state(),
task->timesScheduled(),
task->fileHandleCount(),
task->name().characters());
}
ptr += ksprintf(ptr, "kmalloc: alloc: %u / free: %u\n", sum_alloc, sum_free);
*ptr = '\0';
return ByteBuffer::copy((byte*)buffer, ptr - buffer);
}));
return true;
}
const char* ProcFileSystem::className() const
{
return "procfs";
}