diff --git a/kernel/include/kernel/FS/VirtualFileSystem.h b/kernel/include/kernel/FS/VirtualFileSystem.h index bb6d189549..7ce1c7a2c8 100644 --- a/kernel/include/kernel/FS/VirtualFileSystem.h +++ b/kernel/include/kernel/FS/VirtualFileSystem.h @@ -11,7 +11,7 @@ namespace Kernel public: static BAN::ErrorOr initialize(); static VirtualFileSystem& get(); - static bool is_initialized(); + virtual ~VirtualFileSystem() {}; virtual const BAN::RefPtr root_inode() const override { return m_root_inode; } diff --git a/kernel/kernel/FS/VirtualFileSystem.cpp b/kernel/kernel/FS/VirtualFileSystem.cpp index fcd285ed2e..9d357e454d 100644 --- a/kernel/kernel/FS/VirtualFileSystem.cpp +++ b/kernel/kernel/FS/VirtualFileSystem.cpp @@ -33,11 +33,6 @@ namespace Kernel return *s_instance; } - bool VirtualFileSystem::is_initialized() - { - return s_instance != nullptr; - } - BAN::ErrorOr VirtualFileSystem::initialize_impl() { // Initialize all storage controllers @@ -115,9 +110,9 @@ namespace Kernel } } - if (m_root_inode) - return {}; - return BAN::Error::from_c_string("Could not locate root partition"); + if (m_root_inode.empty()) + derrorln("Could not locate root partition"); + return {}; } BAN::ErrorOr> VirtualFileSystem::from_absolute_path(BAN::StringView path) @@ -126,6 +121,9 @@ namespace Kernel return BAN::Error::from_c_string("Path must be an absolute path"); auto inode = root_inode(); + if (!inode) + return BAN::Error::from_c_string("No root inode available"); + auto path_parts = TRY(path.split('/')); for (BAN::StringView part : path_parts) diff --git a/kernel/kernel/Font.cpp b/kernel/kernel/Font.cpp index 36e49e873c..20b65f912a 100644 --- a/kernel/kernel/Font.cpp +++ b/kernel/kernel/Font.cpp @@ -25,9 +25,6 @@ namespace Kernel BAN::ErrorOr Font::load(BAN::StringView path) { - if (!VirtualFileSystem::is_initialized()) - return BAN::Error::from_c_string("Virtual Filesystem is not initialized"); - auto inode = TRY(VirtualFileSystem::get().from_absolute_path(path)); auto file_data = TRY(inode->read_all()); diff --git a/kernel/kernel/Shell.cpp b/kernel/kernel/Shell.cpp index e7d7805867..842b168c92 100644 --- a/kernel/kernel/Shell.cpp +++ b/kernel/kernel/Shell.cpp @@ -265,9 +265,6 @@ argument_done: } else if (arguments.front() == "ls") { - if (!VirtualFileSystem::is_initialized()) - return BAN::Error::from_c_string("VFS not initialized :("); - if (arguments.size() > 2) return BAN::Error::from_c_string("usage: 'ls [path]'"); @@ -304,9 +301,6 @@ argument_done: } else if (arguments.front() == "cat") { - if (!VirtualFileSystem::is_initialized()) - return BAN::Error::from_c_string("VFS not initialized :("); - if (arguments.size() != 2) return BAN::Error::from_c_string("usage: 'cat path'"); @@ -316,9 +310,6 @@ argument_done: } else if (arguments.front() == "loadfont") { - if (!VirtualFileSystem::is_initialized()) - return BAN::Error::from_c_string("VFS not initialized :("); - if (arguments.size() != 2) return BAN::Error::from_c_string("usage: 'loadfont font_path'"); diff --git a/kernel/kernel/kernel.cpp b/kernel/kernel/kernel.cpp index b7ed4bf8ae..9011fb24d4 100644 --- a/kernel/kernel/kernel.cpp +++ b/kernel/kernel/kernel.cpp @@ -127,11 +127,7 @@ extern "C" void kernel_main() MUST(scheduler.add_thread(MUST(Thread::create( [terminal_driver] { - if (auto error = VirtualFileSystem::initialize(); error.is_error()) - { - derrorln("{}", error.error()); - return; - } + MUST(VirtualFileSystem::initialize()); auto font_or_error = Font::load("/usr/share/fonts/zap-ext-vga16.psf"); if (font_or_error.is_error())