forked from Bananymous/banan-os
Kernel: Shell can now mount partitions
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user