From e8a0eeb0b42cb2224b2c504cdc859cc570c2d29c Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 30 Sep 2023 19:51:14 +0300 Subject: [PATCH] Kernel: RamInode verifies that you have not specified mode type This is kinda weird behaviour, but it ensures the user cannot create e.g. CharacterDevice with mode having IFLNK. The Inode overrider is the only one setting the mode. --- kernel/include/kernel/Device/Device.h | 8 ++++---- kernel/include/kernel/FS/RamFS/Inode.h | 4 +++- kernel/kernel/FS/RamFS/Inode.cpp | 3 --- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/kernel/include/kernel/Device/Device.h b/kernel/include/kernel/Device/Device.h index 6211c1e05c..df445eece8 100644 --- a/kernel/include/kernel/Device/Device.h +++ b/kernel/include/kernel/Device/Device.h @@ -25,9 +25,9 @@ namespace Kernel { protected: BlockDevice(mode_t mode, uid_t uid, gid_t gid) - : Device(Mode::IFBLK | mode, uid, gid) + : Device(mode, uid, gid) { - ASSERT(Device::mode().ifblk()); + m_inode_info.mode |= Inode::Mode::IFBLK; } }; @@ -35,9 +35,9 @@ namespace Kernel { protected: CharacterDevice(mode_t mode, uid_t uid, gid_t gid) - : Device(Mode::IFCHR | mode, uid, gid) + : Device(mode, uid, gid) { - ASSERT(Device::mode().ifchr()); + m_inode_info.mode |= Inode::Mode::IFCHR; } }; diff --git a/kernel/include/kernel/FS/RamFS/Inode.h b/kernel/include/kernel/FS/RamFS/Inode.h index 2b81923834..6a80925db1 100644 --- a/kernel/include/kernel/FS/RamFS/Inode.h +++ b/kernel/include/kernel/FS/RamFS/Inode.h @@ -52,7 +52,9 @@ namespace Kernel RamInode(RamFileSystem& fs, const FullInodeInfo& inode_info) : m_fs(fs) , m_inode_info(inode_info) - {} + { + ASSERT((inode_info.mode & Inode::Mode::TYPE_MASK) == 0); + } protected: RamFileSystem& m_fs; diff --git a/kernel/kernel/FS/RamFS/Inode.cpp b/kernel/kernel/FS/RamFS/Inode.cpp index 528dec4fa5..4615b3e585 100644 --- a/kernel/kernel/FS/RamFS/Inode.cpp +++ b/kernel/kernel/FS/RamFS/Inode.cpp @@ -45,7 +45,6 @@ namespace Kernel RamFileInode::RamFileInode(RamFileSystem& fs, const FullInodeInfo& inode_info) : RamInode(fs, inode_info) { - ASSERT((m_inode_info.mode & Inode::Mode::TYPE_MASK) == 0); m_inode_info.mode |= Inode::Mode::IFREG; } @@ -108,7 +107,6 @@ namespace Kernel : RamInode(fs, inode_info) , m_parent(parent) { - ASSERT((m_inode_info.mode & Inode::Mode::TYPE_MASK) == 0); m_inode_info.mode |= Inode::Mode::IFDIR; } @@ -263,7 +261,6 @@ namespace Kernel : RamInode(fs, inode_info) , m_target(BAN::move(target)) { - ASSERT((m_inode_info.mode & Inode::Mode::TYPE_MASK) == 0); m_inode_info.mode |= Inode::Mode::IFLNK; }