Luna/kernel/src/fs/ext2/FileSystem.cpp

29 lines
1.0 KiB
C++
Raw Normal View History

#include "fs/ext2/FileSystem.h"
namespace Ext2
{
FileSystem::FileSystem()
{
}
Result<SharedPtr<VFS::Inode>> FileSystem::find_inode_by_number(ino_t inode)
{
auto maybe_inode = m_inode_cache.try_get(inode);
if (maybe_inode.has_value()) return maybe_inode.value();
// TODO: Locate the inode's block group descriptor and find it in the block group's inode table.
return err(ENOENT);
}
Result<SharedPtr<VFS::FileSystem>> FileSystem::create(SharedPtr<Device> host_device)
{
SharedPtr<FileSystem> fs = TRY(adopt_shared_if_nonnull(new (std::nothrow) FileSystem()));
const usize nread = TRY(host_device->read((u8*)&fs->m_superblock, 1024, 1024));
if (nread != 1024) return err(EINVAL); // Source had an invalid superblock.
if (fs->m_superblock.signature != EXT2_MAGIC) return err(EINVAL); // Source had an invalid superblock.
// TODO: Implement basic Ext2 reading, enough to be able to mount a volume.
return err(ENOTSUP);
}
}