Kernel: Shell can now mount partitions

This commit is contained in:
Bananymous
2023-03-30 15:06:41 +03:00
parent 30c33b55e3
commit 8e68d2e3ea
9 changed files with 50 additions and 5 deletions

View File

@@ -35,6 +35,18 @@ namespace Kernel
return *s_instance;
}
BAN::ErrorOr<void> VirtualFileSystem::mount(BAN::StringView partition, BAN::StringView target)
{
auto partition_file = TRY(file_from_absolute_path(partition));
if (partition_file.inode->inode_type() != Inode::InodeType::Device)
return BAN::Error::from_c_string("Not a partition");
Device* device = (Device*)partition_file.inode.ptr();
if (device->device_type() != Device::DeviceType::Partition)
return BAN::Error::from_c_string("Not a partition");
auto* file_system = TRY(Ext2FS::create(*(Partition*)device));
return mount(file_system, target);
}
BAN::ErrorOr<void> VirtualFileSystem::mount(FileSystem* file_system, BAN::StringView path)
{
auto file = TRY(file_from_absolute_path(path));

View File

@@ -97,6 +97,13 @@ namespace Kernel
return {};
}
BAN::ErrorOr<void> Process::mount(BAN::StringView partition, BAN::StringView path)
{
LockGuard _(m_lock);
TRY(VirtualFileSystem::get().mount(partition, path));
return {};
}
BAN::ErrorOr<void> Process::fstat(int fd, struct stat* out)
{
LockGuard _(m_lock);

View File

@@ -508,6 +508,12 @@ argument_done:
TTY_PRINTLN("{} {} {}", crc32, total_read, arguments[i]);
}
}
else if (arguments.front() == "mount")
{
if (arguments.size() != 3)
return BAN::Error::from_c_string("usage: 'mount partition directory'");
TRY(Process::current()->mount(arguments[1], arguments[2]));
}
else if (arguments.front() == "loadfont")
{
if (arguments.size() != 2)