DevFS: Use strongly typed InodeIndex

Also add an assertion for the DevFS inode index allocator overflowing.
This commit is contained in:
Andreas Kling 2021-02-12 15:42:51 +01:00
parent 4717009e3e
commit 0a45cfee01
Notes: sideshowbarker 2024-07-18 22:24:18 +09:00
2 changed files with 7 additions and 8 deletions

View File

@ -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

View File

@ -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 {