2022-12-23 10:33:23 +00:00
|
|
|
#include "InitRD.h"
|
|
|
|
#include "arch/MMU.h"
|
|
|
|
#include "boot/bootboot.h"
|
2023-03-11 09:23:46 +00:00
|
|
|
#include "fs/VFS.h"
|
2022-12-23 10:33:23 +00:00
|
|
|
|
|
|
|
TarStream g_initrd;
|
|
|
|
extern const BOOTBOOT bootboot;
|
|
|
|
|
|
|
|
void InitRD::initialize()
|
|
|
|
{
|
2023-02-27 12:27:21 +00:00
|
|
|
u64 virtual_initrd_address = MMU::translate_physical_address(bootboot.initrd_ptr);
|
2022-12-23 10:33:23 +00:00
|
|
|
|
|
|
|
g_initrd.initialize((void*)virtual_initrd_address, bootboot.initrd_size);
|
2023-01-02 12:07:29 +00:00
|
|
|
}
|
2023-03-11 09:23:46 +00:00
|
|
|
|
|
|
|
static Result<void> vfs_create_dir_if_not_exists(const char* path)
|
|
|
|
{
|
|
|
|
auto rc = VFS::create_directory(path);
|
|
|
|
if (rc.has_error())
|
|
|
|
{
|
|
|
|
if (rc.error() == EEXIST) return {};
|
|
|
|
return rc.release_error();
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> InitRD::populate_vfs()
|
|
|
|
{
|
|
|
|
TarStream::Entry entry;
|
|
|
|
while (TRY(g_initrd.read_next_entry(entry)))
|
|
|
|
{
|
|
|
|
if (entry.type == TarStream::EntryType::RegularFile)
|
|
|
|
{
|
|
|
|
auto file = TRY(VFS::create_file(entry.name));
|
|
|
|
file->write(entry.data(), 0, entry.size);
|
|
|
|
}
|
|
|
|
else if (entry.type == TarStream::EntryType::Directory) { TRY(vfs_create_dir_if_not_exists(entry.name)); }
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|