Skip to content

Commit b6bf264

Browse files
committed
Kernel: Have devices automagically register themselves with the VFS.
1 parent e74c833 commit b6bf264

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

Kernel/Device.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#include "CharacterDevice.h"
22
#include <LibC/errno_numbers.h>
33

4+
Device::Device(unsigned major, unsigned minor)
5+
: m_major(major)
6+
, m_minor(minor)
7+
{
8+
VFS::the().register_device(*this);
9+
}
10+
411
Device::~Device()
512
{
13+
VFS::the().unregister_device(*this);
614
}
715

816
RetainPtr<FileDescriptor> Device::open(int& error, int options)

Kernel/Device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Device : public Retainable<Device> {
3939
virtual bool is_character_device() const { return false; }
4040

4141
protected:
42-
Device(unsigned major, unsigned minor) : m_major(major), m_minor(minor) { }
42+
Device(unsigned major, unsigned minor);
4343
void set_uid(uid_t uid) { m_uid = uid; }
4444
void set_gid(gid_t gid) { m_gid = gid; }
4545

Kernel/SlavePTY.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
1010
{
1111
set_uid(current->uid());
1212
set_gid(current->gid());
13-
VFS::the().register_device(*this);
1413
DevPtsFS::the().register_slave_pty(*this);
1514
set_size(80, 25);
1615
}
@@ -19,7 +18,6 @@ SlavePTY::~SlavePTY()
1918
{
2019
dbgprintf("~SlavePTY(%u)\n", m_index);
2120
DevPtsFS::the().unregister_slave_pty(*this);
22-
VFS::the().unregister_device(*this);
2321
}
2422

2523
String SlavePTY::tty_name() const

Kernel/init.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,9 @@ VFS* vfs;
6666
Syscall::initialize();
6767

6868
auto dev_zero = make<ZeroDevice>();
69-
vfs->register_device(*dev_zero);
70-
71-
vfs->register_device(*dev_null);
72-
7369
auto dev_full = make<FullDevice>();
74-
vfs->register_device(*dev_full);
75-
7670
auto dev_random = make<RandomDevice>();
77-
vfs->register_device(*dev_random);
78-
7971
auto dev_ptmx = make<PTYMultiplexer>();
80-
vfs->register_device(*dev_ptmx);
81-
82-
vfs->register_device(*keyboard);
83-
vfs->register_device(*ps2mouse);
84-
vfs->register_device(*tty0);
85-
vfs->register_device(*tty1);
86-
vfs->register_device(*tty2);
87-
vfs->register_device(*tty3);
88-
89-
vfs->register_device(BXVGADevice::the());
90-
9172
auto dev_hd0 = IDEDiskDevice::create();
9273
auto e2fs = Ext2FS::create(dev_hd0.copy_ref());
9374
e2fs->initialize();
@@ -145,15 +126,15 @@ VFS* vfs;
145126
kmalloc_init();
146127
init_ksyms();
147128

129+
vfs = new VFS;
130+
148131
auto console = make<Console>();
149132

150133
RTC::initialize();
151134
PIC::initialize();
152135
gdt_init();
153136
idt_init();
154137

155-
vfs = new VFS;
156-
157138
keyboard = new KeyboardDevice;
158139
ps2mouse = new PS2MouseDevice;
159140
dev_null = new NullDevice;

0 commit comments

Comments
 (0)