From 4dd148f07c64fbcaad05d83813feb54ccafdee33 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 27 Nov 2022 23:50:28 +0100 Subject: [PATCH] Kernel: Add File::is_regular_file() This makes it easy and expressive to check if a File is a regular file. --- Kernel/FileSystem/File.h | 2 ++ Kernel/FileSystem/InodeFile.cpp | 5 +++++ Kernel/FileSystem/InodeFile.h | 2 ++ 3 files changed, 9 insertions(+) diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index 9b2a4bb817..4e1145bdae 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -115,6 +115,8 @@ public: virtual bool is_socket() const { return false; } virtual bool is_inode_watcher() const { return false; } + virtual bool is_regular_file() const { return false; } + virtual FileBlockerSet& blocker_set() { return m_blocker_set; } size_t attach_count() const { return m_attach_count; } diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index f32823d9b3..d1406b51b0 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -120,4 +120,9 @@ ErrorOr InodeFile::chmod(Credentials const& credentials, OpenFileDescripti return VirtualFileSystem::the().chmod(credentials, *description.custody(), mode); } +bool InodeFile::is_regular_file() const +{ + return inode().metadata().is_regular_file(); +} + } diff --git a/Kernel/FileSystem/InodeFile.h b/Kernel/FileSystem/InodeFile.h index 5da7cbdce5..4336166c3f 100644 --- a/Kernel/FileSystem/InodeFile.h +++ b/Kernel/FileSystem/InodeFile.h @@ -49,6 +49,8 @@ public: virtual bool is_inode() const override { return true; } private: + virtual bool is_regular_file() const override; + explicit InodeFile(NonnullLockRefPtr&&); NonnullLockRefPtr m_inode; };