forked from Bananymous/banan-os
Kernel: You don't have to check whether VFS is initialized or not
VFS now returns Error when attempting to traverse inodes if it did not find root partition
This commit is contained in:
parent
fc58baf54d
commit
8940ff8002
|
@ -11,7 +11,7 @@ namespace Kernel
|
|||
public:
|
||||
static BAN::ErrorOr<void> initialize();
|
||||
static VirtualFileSystem& get();
|
||||
static bool is_initialized();
|
||||
virtual ~VirtualFileSystem() {};
|
||||
|
||||
virtual const BAN::RefPtr<Inode> root_inode() const override { return m_root_inode; }
|
||||
|
||||
|
|
|
@ -33,11 +33,6 @@ namespace Kernel
|
|||
return *s_instance;
|
||||
}
|
||||
|
||||
bool VirtualFileSystem::is_initialized()
|
||||
{
|
||||
return s_instance != nullptr;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> VirtualFileSystem::initialize_impl()
|
||||
{
|
||||
// Initialize all storage controllers
|
||||
|
@ -115,9 +110,9 @@ namespace Kernel
|
|||
}
|
||||
}
|
||||
|
||||
if (m_root_inode)
|
||||
if (m_root_inode.empty())
|
||||
derrorln("Could not locate root partition");
|
||||
return {};
|
||||
return BAN::Error::from_c_string("Could not locate root partition");
|
||||
}
|
||||
|
||||
BAN::ErrorOr<BAN::RefPtr<Inode>> 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)
|
||||
|
|
|
@ -25,9 +25,6 @@ namespace Kernel
|
|||
|
||||
BAN::ErrorOr<Font> 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());
|
||||
|
|
|
@ -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'");
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue