This commit is contained in:
parent
9097400c32
commit
5f0830cd41
@ -76,6 +76,7 @@ set(SOURCES
|
||||
src/fs/devices/PTYMultiplexer.cpp
|
||||
src/fs/devices/MasterPTY.cpp
|
||||
src/fs/devices/SlavePTY.cpp
|
||||
src/fs/devices/TTYLink.cpp
|
||||
src/fs/InitRD.cpp
|
||||
src/binfmt/ELF.cpp
|
||||
src/binfmt/BinaryFormat.cpp
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "fs/devices/MouseDevice.h"
|
||||
#include "fs/devices/NullDevice.h"
|
||||
#include "fs/devices/PTYMultiplexer.h"
|
||||
#include "fs/devices/TTYLink.h"
|
||||
#include "fs/devices/UARTDevice.h"
|
||||
#include "fs/devices/ZeroDevice.h"
|
||||
#include "fs/tmpfs/FileSystem.h"
|
||||
@ -99,6 +100,12 @@ namespace DeviceRegistry
|
||||
|
||||
TRY(fs->root_inode()->add_entry(multiplexer, "ptmx"));
|
||||
|
||||
auto ttylink = TRY(make_shared<TTYLink>());
|
||||
ttylink->set_fs(*fs);
|
||||
ttylink->set_inode_number(TRY(fs->allocate_inode_number()));
|
||||
|
||||
TRY(fs->root_inode()->add_entry(ttylink, "tty"));
|
||||
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ Result<SharedPtr<VFS::Inode>> MasterPTY::create_pair(int index)
|
||||
master->m_window.ws_row = 25;
|
||||
|
||||
slave->m_master = master.ptr();
|
||||
slave->m_metadata.devid = luna_dev_makedev(DeviceRegistry::Terminal, index + 1);
|
||||
slave->m_metadata.devid = luna_dev_makedev(DeviceRegistry::Terminal, index + 2);
|
||||
slave->m_metadata.uid = Scheduler::current()->auth.euid;
|
||||
slave->m_metadata.gid = Scheduler::current()->auth.egid;
|
||||
slave->m_metadata.mode = 0620;
|
||||
|
15
kernel/src/fs/devices/TTYLink.cpp
Normal file
15
kernel/src/fs/devices/TTYLink.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "fs/devices/TTYLink.h"
|
||||
#include "thread/Scheduler.h"
|
||||
|
||||
TTYLink::TTYLink()
|
||||
{
|
||||
m_metadata.devid = luna_dev_makedev(DeviceRegistry::Terminal, 1);
|
||||
m_metadata.mode = 0666;
|
||||
}
|
||||
|
||||
Result<SharedPtr<VFS::Inode>> TTYLink::open()
|
||||
{
|
||||
if (!Scheduler::current()->controlling_terminal) return err(ENXIO);
|
||||
|
||||
return Scheduler::current()->controlling_terminal;
|
||||
}
|
75
kernel/src/fs/devices/TTYLink.h
Normal file
75
kernel/src/fs/devices/TTYLink.h
Normal file
@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
#include "fs/VFS.h"
|
||||
#include "fs/devices/DeviceRegistry.h"
|
||||
#include "fs/devices/MasterPTY.h"
|
||||
#include <luna/Bitset.h>
|
||||
|
||||
/* /dev/tty implementation. */
|
||||
class TTYLink : public VFS::DeviceInode
|
||||
{
|
||||
public:
|
||||
TTYLink();
|
||||
|
||||
VFS::InodeType type() const override
|
||||
{
|
||||
return VFS::InodeType::CharacterDevice;
|
||||
}
|
||||
|
||||
void set_fs(VFS::FileSystem& fs)
|
||||
{
|
||||
m_fs = &fs;
|
||||
}
|
||||
|
||||
void set_inode_number(usize inum)
|
||||
{
|
||||
m_metadata.inum = inum;
|
||||
}
|
||||
|
||||
Result<u64> query_shared_memory(off_t, usize) override
|
||||
{
|
||||
unreachable();
|
||||
}
|
||||
|
||||
Result<SharedPtr<VFS::Inode>> open() override;
|
||||
|
||||
VFS::FileSystem* fs() const override
|
||||
{
|
||||
return m_fs;
|
||||
}
|
||||
|
||||
Result<usize> read(u8*, usize, usize) const override
|
||||
{
|
||||
unreachable();
|
||||
}
|
||||
|
||||
Result<usize> write(const u8*, usize, usize) override
|
||||
{
|
||||
unreachable();
|
||||
}
|
||||
|
||||
Result<void> truncate(usize) override
|
||||
{
|
||||
// POSIX says truncate is for regular files, but doesn't tell us what error to return for non-regular files.
|
||||
return err(EINVAL);
|
||||
}
|
||||
|
||||
bool will_block_if_read() const override
|
||||
{
|
||||
unreachable();
|
||||
}
|
||||
|
||||
void did_link() override
|
||||
{
|
||||
m_metadata.nlinks++;
|
||||
}
|
||||
|
||||
void did_unlink() override
|
||||
{
|
||||
m_metadata.nlinks--;
|
||||
}
|
||||
|
||||
virtual ~TTYLink() = default;
|
||||
|
||||
private:
|
||||
VFS::FileSystem* m_fs;
|
||||
};
|
@ -110,6 +110,8 @@ struct Thread : public LinkedListNode<Thread>
|
||||
Bitset<sigset_t> pending_signals { 0 };
|
||||
bool interrupted { false };
|
||||
|
||||
SharedPtr<VFS::Inode> controlling_terminal;
|
||||
|
||||
bool unrestricted_task { false };
|
||||
|
||||
FPData fp_data;
|
||||
|
Loading…
Reference in New Issue
Block a user