From 0a45cfee01f016f905c4c53b41a7897eb276afe8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 12 Feb 2021 15:42:51 +0100 Subject: [PATCH] DevFS: Use strongly typed InodeIndex Also add an assertion for the DevFS inode index allocator overflowing. --- Kernel/FileSystem/DevFS.cpp | 8 +++++--- Kernel/FileSystem/DevFS.h | 7 ++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp index f12b5b66d34..1019eb5b42c 100644 --- a/Kernel/FileSystem/DevFS.cpp +++ b/Kernel/FileSystem/DevFS.cpp @@ -57,10 +57,12 @@ void DevFS::notify_new_device(Device& device) m_root_inode->m_devices.append(new_device_inode); } -size_t DevFS::get_new_inode_index() +size_t DevFS::allocate_inode_index() { LOCKER(m_lock); - return 1 + (++m_inode_index); + m_next_inode_index = m_next_inode_index.value() + 1; + ASSERT(m_next_inode_index > 0); + return 1 + m_next_inode_index.value(); } void DevFS::notify_device_removal(Device&) @@ -95,7 +97,7 @@ RefPtr DevFS::get_inode(InodeIdentifier inode_id) const } DevFSInode::DevFSInode(DevFS& fs) - : Inode(fs, fs.get_new_inode_index()) + : Inode(fs, fs.allocate_inode_index()) { } ssize_t DevFSInode::read_bytes(off_t, ssize_t, UserOrKernelBuffer&, FileDescription*) const diff --git a/Kernel/FileSystem/DevFS.h b/Kernel/FileSystem/DevFS.h index ab12a605db6..4800055ea9f 100644 --- a/Kernel/FileSystem/DevFS.h +++ b/Kernel/FileSystem/DevFS.h @@ -60,12 +60,12 @@ public: private: DevFS(); RefPtr get_inode(InodeIdentifier) const; - size_t get_new_inode_index(); + size_t allocate_inode_index(); NonnullRefPtr m_root_inode; NonnullRefPtrVector m_nodes; - size_t m_inode_index { 0 }; + InodeIndex m_next_inode_index { 0 }; }; class DevFSInode : public Inode { @@ -89,9 +89,6 @@ protected: virtual KResult chmod(mode_t) override; virtual KResult chown(uid_t, gid_t) override; virtual KResult truncate(u64) override; - -private: - size_t m_index; }; class DevFSDeviceInode : public DevFSInode {