瀏覽代碼

Kernel: Have devices automagically register themselves with the VFS.

Andreas Kling 6 年之前
父節點
當前提交
b6bf26430d
共有 4 個文件被更改,包括 11 次插入24 次删除
  1. 8 0
      Kernel/Device.cpp
  2. 1 1
      Kernel/Device.h
  3. 0 2
      Kernel/SlavePTY.cpp
  4. 2 21
      Kernel/init.cpp

+ 8 - 0
Kernel/Device.cpp

@@ -1,8 +1,16 @@
 #include "CharacterDevice.h"
 #include "CharacterDevice.h"
 #include <LibC/errno_numbers.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()
 Device::~Device()
 {
 {
+    VFS::the().unregister_device(*this);
 }
 }
 
 
 RetainPtr<FileDescriptor> Device::open(int& error, int options)
 RetainPtr<FileDescriptor> Device::open(int& error, int options)

+ 1 - 1
Kernel/Device.h

@@ -39,7 +39,7 @@ public:
     virtual bool is_character_device() const { return false; }
     virtual bool is_character_device() const { return false; }
 
 
 protected:
 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_uid(uid_t uid) { m_uid = uid; }
     void set_gid(gid_t gid) { m_gid = gid; }
     void set_gid(gid_t gid) { m_gid = gid; }
 
 

+ 0 - 2
Kernel/SlavePTY.cpp

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

+ 2 - 21
Kernel/init.cpp

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