diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-10-10 11:53:07 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-10-10 11:53:07 +0200 |
commit | 5a300551574451fbf509685d11095bda4fcb20be (patch) | |
tree | 7bd68b5b0bc9daab6899be52dc694b7162dc6b89 /VirtualFileSystem/FileSystem.cpp | |
download | serenity-5a300551574451fbf509685d11095bda4fcb20be.zip |
Import all this stuff into a single repo called Serenity.
Diffstat (limited to 'VirtualFileSystem/FileSystem.cpp')
-rw-r--r-- | VirtualFileSystem/FileSystem.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/VirtualFileSystem/FileSystem.cpp b/VirtualFileSystem/FileSystem.cpp new file mode 100644 index 0000000000..4deada6972 --- /dev/null +++ b/VirtualFileSystem/FileSystem.cpp @@ -0,0 +1,45 @@ +#include <AK/Assertions.h> +#include <AK/HashMap.h> +#include "FileSystem.h" + +static dword s_lastFileSystemID = 0; + +static HashMap<dword, FileSystem*>& fileSystems() +{ + static auto* map = new HashMap<dword, FileSystem*>(); + return *map; +} + +FileSystem::FileSystem() + : m_id(++s_lastFileSystemID) +{ + fileSystems().set(m_id, this); +} + +FileSystem::~FileSystem() +{ + // FIXME: Needs HashMap::remove()! + //fileSystems().remove(m_id); +} + +FileSystem* FileSystem::fromID(dword id) +{ + auto it = fileSystems().find(id); + if (it != fileSystems().end()) + return (*it).value; + return nullptr; +} + +InodeIdentifier FileSystem::childOfDirectoryInodeWithName(InodeIdentifier inode, const String& name) +{ + InodeIdentifier foundInode; + enumerateDirectoryInode(inode, [&] (const DirectoryEntry& entry) { + if (entry.name == name) { + foundInode = entry.inode; + return false; + } + return true; + }); + return foundInode; +} + |