tmpfs: make the root inode a DirInode instead of a FileInode

This commit is contained in:
apio 2023-02-25 19:08:55 +01:00
parent cca4743a51
commit 9248a5b3cc
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 14 additions and 1 deletions

View File

@ -48,6 +48,8 @@ namespace VFS
virtual Result<SharedPtr<Inode>> create_file_inode() = 0;
virtual Result<SharedPtr<Inode>> create_dir_inode() = 0;
virtual ~FileSystem() = default;
};

View File

@ -7,7 +7,7 @@ namespace TmpFS
Result<SharedPtr<VFS::FileSystem>> FileSystem::create()
{
SharedPtr<FileSystem> fs = TRY(adopt_shared(new (std::nothrow) FileSystem()));
SharedPtr<VFS::Inode> root = TRY(fs->create_file_inode());
SharedPtr<VFS::Inode> root = TRY(fs->create_dir_inode());
fs->set_root(root);
return (SharedPtr<VFS::FileSystem>)fs;
}
@ -22,6 +22,16 @@ namespace TmpFS
return (SharedPtr<VFS::Inode>)inode;
}
Result<SharedPtr<VFS::Inode>> FileSystem::create_dir_inode()
{
SharedPtr<DirInode> inode = TRY(make_shared<DirInode>());
inode->set_fs(*this, {});
inode->set_inode_number(m_next_inode_number, {});
TRY(m_inodes.try_append(inode));
m_next_inode_number++;
return (SharedPtr<VFS::Inode>)inode;
}
void FileSystem::set_root(SharedPtr<VFS::Inode> root)
{
m_root_inode = root;

View File

@ -15,6 +15,7 @@ namespace TmpFS
}
Result<SharedPtr<VFS::Inode>> create_file_inode() override;
Result<SharedPtr<VFS::Inode>> create_dir_inode() override;
static Result<SharedPtr<VFS::FileSystem>> create();