From 8ba571a30ee83ac7353072e8f7cd2371e9534704 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 27 Feb 2023 15:04:29 +0100 Subject: [PATCH] TmpFS: Use a fixed char array in DirInode's Entry instead of OwnedStringView --- kernel/src/fs/VFS.h | 2 +- kernel/src/fs/tmpfs/FileSystem.cpp | 12 ++++++++---- kernel/src/fs/tmpfs/FileSystem.h | 4 ++-- kernel/src/main.cpp | 4 ++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/kernel/src/fs/VFS.h b/kernel/src/fs/VFS.h index 9c89f273..70e2fb12 100644 --- a/kernel/src/fs/VFS.h +++ b/kernel/src/fs/VFS.h @@ -57,7 +57,7 @@ namespace VFS virtual Result> create_file_inode() = 0; - virtual Result> create_dir_inode() = 0; + virtual Result> create_dir_inode(SharedPtr parent) = 0; virtual ~FileSystem() = default; }; diff --git a/kernel/src/fs/tmpfs/FileSystem.cpp b/kernel/src/fs/tmpfs/FileSystem.cpp index 4606743e..76e095bd 100644 --- a/kernel/src/fs/tmpfs/FileSystem.cpp +++ b/kernel/src/fs/tmpfs/FileSystem.cpp @@ -1,5 +1,6 @@ #include "fs/tmpfs/FileSystem.h" #include +#include #include namespace TmpFS @@ -7,7 +8,7 @@ namespace TmpFS Result> FileSystem::create() { SharedPtr fs = TRY(adopt_shared(new (std::nothrow) FileSystem())); - SharedPtr root = TRY(fs->create_dir_inode()); + SharedPtr root = TRY(fs->create_dir_inode({})); fs->set_root(root); return (SharedPtr)fs; } @@ -22,10 +23,11 @@ namespace TmpFS return (SharedPtr)inode; } - Result> FileSystem::create_dir_inode() + Result> FileSystem::create_dir_inode(SharedPtr parent) { SharedPtr inode = TRY(make_shared()); TRY(inode->add_entry(inode, ".")); + TRY(inode->add_entry(parent ? parent : (SharedPtr)inode, "..")); inode->set_fs(*this, {}); inode->set_inode_number(m_next_inode_number, {}); @@ -43,7 +45,7 @@ namespace TmpFS { for (const auto& entry : m_entries) { - if (!strcmp(name, entry.name.chars())) return entry.inode; + if (!strcmp(name, entry.name)) return entry.inode; } return err(ENOENT); @@ -51,7 +53,9 @@ namespace TmpFS Result DirInode::add_entry(SharedPtr inode, const char* name) { - Entry entry = { inode, TRY(OwnedStringView::from_string_literal(name)) }; + Entry entry; + entry.inode = inode; + strlcpy(entry.name, name, sizeof(entry.name)); TRY(m_entries.try_append(move(entry))); diff --git a/kernel/src/fs/tmpfs/FileSystem.h b/kernel/src/fs/tmpfs/FileSystem.h index 044a26a5..63cf7abe 100644 --- a/kernel/src/fs/tmpfs/FileSystem.h +++ b/kernel/src/fs/tmpfs/FileSystem.h @@ -16,7 +16,7 @@ namespace TmpFS } Result> create_file_inode() override; - Result> create_dir_inode() override; + Result> create_dir_inode(SharedPtr parent) override; static Result> create(); @@ -110,7 +110,7 @@ namespace TmpFS struct Entry { SharedPtr inode; - OwnedStringView name; + char name[128]; }; Vector m_entries; diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 3427cf6e..09964795 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -61,7 +61,11 @@ Result init() VFS::Inode& root_inode = VFS::root_inode(); kinfoln("root inode number: %zu", root_inode.inode_number()); + kinfoln("root inode's '.' entry inode number: %zu", TRY(root_inode.find("."))->inode_number()); + kinfoln("root inode's '..' entry inode number: %zu", TRY(root_inode.find(".."))->inode_number()); + TRY(root_inode.create_file("usr")); + kinfoln("root inode's 'usr' entry inode number: %zu", TRY(root_inode.find("usr"))->inode_number()); TarStream::Entry entry;