Browse Source

Kernel: Allow getting a Device from a FileDescription

Like we already do for other kinds of files.
Sergey Bugaev 5 years ago
parent
commit
3393b78623
2 changed files with 16 additions and 0 deletions
  1. 14 0
      Kernel/FileSystem/FileDescription.cpp
  2. 2 0
      Kernel/FileSystem/FileDescription.h

+ 14 - 0
Kernel/FileSystem/FileDescription.cpp

@@ -172,6 +172,20 @@ bool FileDescription::is_device() const
     return m_file->is_device();
     return m_file->is_device();
 }
 }
 
 
+const Device* FileDescription::device() const
+{
+    if (!is_device())
+        return nullptr;
+    return static_cast<const Device*>(m_file.ptr());
+}
+
+Device* FileDescription::device()
+{
+    if (!is_device())
+        return nullptr;
+    return static_cast<Device*>(m_file.ptr());
+}
+
 bool FileDescription::is_tty() const
 bool FileDescription::is_tty() const
 {
 {
     return m_file->is_tty();
     return m_file->is_tty();

+ 2 - 0
Kernel/FileSystem/FileDescription.h

@@ -71,6 +71,8 @@ public:
     const File& file() const { return *m_file; }
     const File& file() const { return *m_file; }
 
 
     bool is_device() const;
     bool is_device() const;
+    const Device* device() const;
+    Device* device();
 
 
     bool is_tty() const;
     bool is_tty() const;
     const TTY* tty() const;
     const TTY* tty() const;