mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 18:15:07 +00:00
Add a /dev/pts filesystem and make PTY allocation dynamic.
You can now open as many PTY pairs as you like. Well, it's actually capped at 8 for now, but it's just a constant and trivial to change. Unregistering a PTY pair is untested because I didn't want to start mucking with that in Terminal right now.
This commit is contained in:
parent
c30e2c8d44
commit
e9b948103d
12 changed files with 124 additions and 20 deletions
67
Kernel/DevPtsFS.cpp
Normal file
67
Kernel/DevPtsFS.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "DevPtsFS.h"
|
||||
#include <Kernel/VirtualFileSystem.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
||||
static DevPtsFS* s_the;
|
||||
|
||||
DevPtsFS& DevPtsFS::the()
|
||||
{
|
||||
ASSERT(s_the);
|
||||
return *s_the;
|
||||
}
|
||||
|
||||
RetainPtr<DevPtsFS> DevPtsFS::create()
|
||||
{
|
||||
return adopt(*new DevPtsFS);
|
||||
}
|
||||
|
||||
DevPtsFS::DevPtsFS()
|
||||
{
|
||||
s_the = this;
|
||||
}
|
||||
|
||||
DevPtsFS::~DevPtsFS()
|
||||
{
|
||||
}
|
||||
|
||||
bool DevPtsFS::initialize()
|
||||
{
|
||||
SynthFS::initialize();
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* DevPtsFS::class_name() const
|
||||
{
|
||||
return "DevPtsFS";
|
||||
}
|
||||
|
||||
RetainPtr<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
|
||||
{
|
||||
auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
|
||||
|
||||
StringBuilder builder;
|
||||
builder.appendf("%u", index);
|
||||
file->m_name = builder.build();
|
||||
|
||||
file->m_metadata.size = 0;
|
||||
file->m_metadata.uid = 0;
|
||||
file->m_metadata.gid = 0;
|
||||
file->m_metadata.mode = 0020666;
|
||||
file->m_metadata.majorDevice = 11;
|
||||
file->m_metadata.minorDevice = index;
|
||||
file->m_metadata.mtime = mepoch;
|
||||
return file;
|
||||
}
|
||||
|
||||
void DevPtsFS::register_slave_pty(SlavePTY& slave_pty)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
auto inode_id = add_file(create_slave_pty_device_file(slave_pty.index()));
|
||||
slave_pty.set_devpts_inode_id(inode_id);
|
||||
}
|
||||
|
||||
void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
remove_file(slave_pty.devpts_inode_id().index());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue