diff --git a/kernel/src/fs/VFS.h b/kernel/src/fs/VFS.h index 5e5e6387..ac1ec564 100644 --- a/kernel/src/fs/VFS.h +++ b/kernel/src/fs/VFS.h @@ -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> create_file_inode() = 0; + virtual ~FileSystem() = default; }; diff --git a/kernel/src/fs/tmpfs/FileSystem.cpp b/kernel/src/fs/tmpfs/FileSystem.cpp index 45631fc4..eefac905 100644 --- a/kernel/src/fs/tmpfs/FileSystem.cpp +++ b/kernel/src/fs/tmpfs/FileSystem.cpp @@ -5,29 +5,24 @@ namespace TmpFS { Result> FileSystem::create() { - SharedPtr root = TRY(make_shared()); SharedPtr fs = TRY(adopt_shared(new (std::nothrow) FileSystem())); - root->set_fs(*fs, {}); - TRY(fs->set_root(root)); + SharedPtr root = TRY(fs->create_file_inode()); + fs->set_root(root); return (SharedPtr)fs; } - FileSystem::FileSystem() + Result> FileSystem::create_file_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; } - Result FileSystem::set_root(SharedPtr root) + void FileSystem::set_root(SharedPtr root) { m_root_inode = root; - return m_inodes.try_append(root); - } - - Inode::Inode() - { - } - - void Inode::set_fs(FileSystem& fs, Badge) - { - m_fs = &fs; } } diff --git a/kernel/src/fs/tmpfs/FileSystem.h b/kernel/src/fs/tmpfs/FileSystem.h index 2b41105f..75929143 100644 --- a/kernel/src/fs/tmpfs/FileSystem.h +++ b/kernel/src/fs/tmpfs/FileSystem.h @@ -13,34 +13,52 @@ namespace TmpFS return *m_root_inode; } + Result> create_file_inode() override; + static Result> create(); virtual ~FileSystem() = default; private: - FileSystem(); + FileSystem() = default; - Result set_root(SharedPtr root); + void set_root(SharedPtr root); SharedPtr m_root_inode; Vector> m_inodes; + + usize m_next_inode_number { 2 }; }; class Inode : public VFS::FileInode { public: - Inode(); + Inode() = default; - void set_fs(FileSystem& fs, Badge); + void set_fs(FileSystem& fs, Badge) + { + m_fs = &fs; + } + + void set_inode_number(usize inum, Badge) + { + 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; }; } diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index b743d553..f0c83f7b 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -58,6 +58,9 @@ Result 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))) {