diff --git a/kernel/src/fs/VFS.h b/kernel/src/fs/VFS.h index 843ad15c..92c4d98e 100644 --- a/kernel/src/fs/VFS.h +++ b/kernel/src/fs/VFS.h @@ -48,6 +48,8 @@ namespace VFS virtual Result> create_file_inode() = 0; + virtual Result> create_dir_inode() = 0; + virtual ~FileSystem() = default; }; diff --git a/kernel/src/fs/tmpfs/FileSystem.cpp b/kernel/src/fs/tmpfs/FileSystem.cpp index 934e8437..3d55ffa7 100644 --- a/kernel/src/fs/tmpfs/FileSystem.cpp +++ b/kernel/src/fs/tmpfs/FileSystem.cpp @@ -7,7 +7,7 @@ namespace TmpFS Result> FileSystem::create() { SharedPtr fs = TRY(adopt_shared(new (std::nothrow) FileSystem())); - SharedPtr root = TRY(fs->create_file_inode()); + SharedPtr root = TRY(fs->create_dir_inode()); fs->set_root(root); return (SharedPtr)fs; } @@ -22,6 +22,16 @@ namespace TmpFS return (SharedPtr)inode; } + Result> FileSystem::create_dir_inode() + { + SharedPtr inode = TRY(make_shared()); + inode->set_fs(*this, {}); + inode->set_inode_number(m_next_inode_number, {}); + TRY(m_inodes.try_append(inode)); + m_next_inode_number++; + return (SharedPtr)inode; + } + void FileSystem::set_root(SharedPtr root) { m_root_inode = root; diff --git a/kernel/src/fs/tmpfs/FileSystem.h b/kernel/src/fs/tmpfs/FileSystem.h index 817af741..c6ac85ae 100644 --- a/kernel/src/fs/tmpfs/FileSystem.h +++ b/kernel/src/fs/tmpfs/FileSystem.h @@ -15,6 +15,7 @@ namespace TmpFS } Result> create_file_inode() override; + Result> create_dir_inode() override; static Result> create();