Browse Source

DevFS: Use strongly typed InodeIndex

Also add an assertion for the DevFS inode index allocator overflowing.
Andreas Kling 4 years ago
parent
commit
0a45cfee01
2 changed files with 7 additions and 8 deletions
  1. 5 3
      Kernel/FileSystem/DevFS.cpp
  2. 2 5
      Kernel/FileSystem/DevFS.h

+ 5 - 3
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<Inode> 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

+ 2 - 5
Kernel/FileSystem/DevFS.h

@@ -60,12 +60,12 @@ public:
 private:
     DevFS();
     RefPtr<Inode> get_inode(InodeIdentifier) const;
-    size_t get_new_inode_index();
+    size_t allocate_inode_index();
 
     NonnullRefPtr<DevFSRootDirectoryInode> m_root_inode;
     NonnullRefPtrVector<DevFSInode> 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 {