summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2020-01-12 18:28:23 +0300
committerAndreas Kling <awesomekling@gmail.com>2020-01-12 20:02:11 +0100
commit3393b786238b43ac1faef20fb393d4efd3d8ce3c (patch)
tree7184bcb1785271f55f752858e4e33678f8b1123f /Kernel/FileSystem
parent35b0f10f202c80cdc51661d11c0a9affb3d71a58 (diff)
downloadserenity-3393b786238b43ac1faef20fb393d4efd3d8ce3c.zip
Kernel: Allow getting a Device from a FileDescription
Like we already do for other kinds of files.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r--Kernel/FileSystem/FileDescription.cpp14
-rw-r--r--Kernel/FileSystem/FileDescription.h2
2 files changed, 16 insertions, 0 deletions
diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp
index 13c3850ffd..ad7be299f7 100644
--- a/Kernel/FileSystem/FileDescription.cpp
+++ b/Kernel/FileSystem/FileDescription.cpp
@@ -172,6 +172,20 @@ bool FileDescription::is_device() const
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
{
return m_file->is_tty();
diff --git a/Kernel/FileSystem/FileDescription.h b/Kernel/FileSystem/FileDescription.h
index 8d7f5b499a..d56d8f3619 100644
--- a/Kernel/FileSystem/FileDescription.h
+++ b/Kernel/FileSystem/FileDescription.h
@@ -71,6 +71,8 @@ public:
const File& file() const { return *m_file; }
bool is_device() const;
+ const Device* device() const;
+ Device* device();
bool is_tty() const;
const TTY* tty() const;