Kernel: Have devices automagically register themselves with the VFS.

This commit is contained in:
Andreas Kling 2019-02-17 10:38:07 +01:00
parent e74c833af3
commit b6bf26430d
Notes: sideshowbarker 2024-07-19 15:40:54 +09:00
4 changed files with 11 additions and 24 deletions

View File

@ -1,8 +1,16 @@
#include "CharacterDevice.h"
#include <LibC/errno_numbers.h>
Device::Device(unsigned major, unsigned minor)
: m_major(major)
, m_minor(minor)
{
VFS::the().register_device(*this);
}
Device::~Device()
{
VFS::the().unregister_device(*this);
}
RetainPtr<FileDescriptor> Device::open(int& error, int options)

View File

@ -39,7 +39,7 @@ public:
virtual bool is_character_device() const { return false; }
protected:
Device(unsigned major, unsigned minor) : m_major(major), m_minor(minor) { }
Device(unsigned major, unsigned minor);
void set_uid(uid_t uid) { m_uid = uid; }
void set_gid(gid_t gid) { m_gid = gid; }

View File

@ -10,7 +10,6 @@ SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
{
set_uid(current->uid());
set_gid(current->gid());
VFS::the().register_device(*this);
DevPtsFS::the().register_slave_pty(*this);
set_size(80, 25);
}
@ -19,7 +18,6 @@ SlavePTY::~SlavePTY()
{
dbgprintf("~SlavePTY(%u)\n", m_index);
DevPtsFS::the().unregister_slave_pty(*this);
VFS::the().unregister_device(*this);
}
String SlavePTY::tty_name() const

View File

@ -66,28 +66,9 @@ VFS* vfs;
Syscall::initialize();
auto dev_zero = make<ZeroDevice>();
vfs->register_device(*dev_zero);
vfs->register_device(*dev_null);
auto dev_full = make<FullDevice>();
vfs->register_device(*dev_full);
auto dev_random = make<RandomDevice>();
vfs->register_device(*dev_random);
auto dev_ptmx = make<PTYMultiplexer>();
vfs->register_device(*dev_ptmx);
vfs->register_device(*keyboard);
vfs->register_device(*ps2mouse);
vfs->register_device(*tty0);
vfs->register_device(*tty1);
vfs->register_device(*tty2);
vfs->register_device(*tty3);
vfs->register_device(BXVGADevice::the());
auto dev_hd0 = IDEDiskDevice::create();
auto e2fs = Ext2FS::create(dev_hd0.copy_ref());
e2fs->initialize();
@ -145,6 +126,8 @@ VFS* vfs;
kmalloc_init();
init_ksyms();
vfs = new VFS;
auto console = make<Console>();
RTC::initialize();
@ -152,8 +135,6 @@ VFS* vfs;
gdt_init();
idt_init();
vfs = new VFS;
keyboard = new KeyboardDevice;
ps2mouse = new PS2MouseDevice;
dev_null = new NullDevice;