Start working on a VFS implementation #22
@ -21,6 +21,8 @@ namespace VFS
|
||||
virtual ~Inode() = default;
|
||||
|
||||
virtual InodeType type() const = 0;
|
||||
|
||||
virtual usize inode_number() const = 0;
|
||||
};
|
||||
|
||||
class FileInode : Inode
|
||||
@ -44,6 +46,8 @@ namespace VFS
|
||||
public:
|
||||
virtual Inode& root() const = 0;
|
||||
|
||||
virtual Result<SharedPtr<Inode>> create_file_inode() = 0;
|
||||
|
||||
virtual ~FileSystem() = default;
|
||||
};
|
||||
|
||||
|
@ -5,29 +5,24 @@ namespace TmpFS
|
||||
{
|
||||
Result<SharedPtr<VFS::FileSystem>> FileSystem::create()
|
||||
{
|
||||
SharedPtr<Inode> root = TRY(make_shared<Inode>());
|
||||
SharedPtr<FileSystem> fs = TRY(adopt_shared(new (std::nothrow) FileSystem()));
|
||||
root->set_fs(*fs, {});
|
||||
TRY(fs->set_root(root));
|
||||
SharedPtr<VFS::Inode> root = TRY(fs->create_file_inode());
|
||||
fs->set_root(root);
|
||||
return (SharedPtr<VFS::FileSystem>)fs;
|
||||
}
|
||||
|
||||
FileSystem::FileSystem()
|
||||
Result<SharedPtr<VFS::Inode>> FileSystem::create_file_inode()
|
||||
{
|
||||
SharedPtr<Inode> inode = TRY(make_shared<Inode>());
|
||||
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;
|
||||
}
|
||||
|
||||
Result<void> FileSystem::set_root(SharedPtr<VFS::Inode> root)
|
||||
void FileSystem::set_root(SharedPtr<VFS::Inode> root)
|
||||
{
|
||||
m_root_inode = root;
|
||||
return m_inodes.try_append(root);
|
||||
}
|
||||
|
||||
Inode::Inode()
|
||||
{
|
||||
}
|
||||
|
||||
void Inode::set_fs(FileSystem& fs, Badge<FileSystem>)
|
||||
{
|
||||
m_fs = &fs;
|
||||
}
|
||||
}
|
||||
|
@ -13,34 +13,52 @@ namespace TmpFS
|
||||
return *m_root_inode;
|
||||
}
|
||||
|
||||
Result<SharedPtr<VFS::Inode>> create_file_inode() override;
|
||||
|
||||
static Result<SharedPtr<VFS::FileSystem>> create();
|
||||
|
||||
virtual ~FileSystem() = default;
|
||||
|
||||
private:
|
||||
FileSystem();
|
||||
FileSystem() = default;
|
||||
|
||||
Result<void> set_root(SharedPtr<VFS::Inode> root);
|
||||
void set_root(SharedPtr<VFS::Inode> root);
|
||||
|
||||
SharedPtr<VFS::Inode> m_root_inode;
|
||||
Vector<SharedPtr<VFS::Inode>> m_inodes;
|
||||
|
||||
usize m_next_inode_number { 2 };
|
||||
};
|
||||
|
||||
class Inode : public VFS::FileInode
|
||||
{
|
||||
public:
|
||||
Inode();
|
||||
Inode() = default;
|
||||
|
||||
void set_fs(FileSystem& fs, Badge<FileSystem>);
|
||||
void set_fs(FileSystem& fs, Badge<FileSystem>)
|
||||
{
|
||||
m_fs = &fs;
|
||||
}
|
||||
|
||||
void set_inode_number(usize inum, Badge<FileSystem>)
|
||||
{
|
||||
m_inode_number = inum;
|
||||
}
|
||||
|
||||
VFS::FileSystem& fs() const override
|
||||
{
|
||||
return *m_fs;
|
||||
}
|
||||
|
||||
usize inode_number() const override
|
||||
{
|
||||
return m_inode_number;
|
||||
}
|
||||
|
||||
virtual ~Inode() = default;
|
||||
|
||||
private:
|
||||
VFS::FileSystem* m_fs;
|
||||
usize m_inode_number;
|
||||
};
|
||||
}
|
||||
|
@ -58,6 +58,9 @@ Result<void> init()
|
||||
|
||||
VFS::root_fs = TRY(TmpFS::FileSystem::create());
|
||||
|
||||
VFS::Inode& root_inode = VFS::root_fs->root();
|
||||
kinfoln("root inode number: %zu", root_inode.inode_number());
|
||||
|
||||
TarStream::Entry entry;
|
||||
while (TRY(g_initrd.read_next_entry(entry)))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user