diff --git a/FileSystem/FS/ustar.cpp b/FileSystem/FS/ustar.cpp index b97e145..f79654b 100644 --- a/FileSystem/FS/ustar.cpp +++ b/FileSystem/FS/ustar.cpp @@ -76,15 +76,29 @@ namespace VirtualFileSystem .Seek = USTAR_Seek, }; - USTAR::USTAR(uintptr_t Address, Virtual *vfs_ctx) + bool USTAR::TestArchive(uintptr_t Address) { - trace("Initializing USTAR with address %#llx", Address); + if (!Memory::Virtual().Check((void *)Address)) + { + error("Address %#lx is not mapped!", Address); + return false; + } if (memcmp(((FileHeader *)(uintptr_t)Address)->signature, "ustar", 5) != 0) { error("ustar signature invalid!"); - return; + return false; } + return true; + } + + void USTAR::ReadArchive(uintptr_t Address, Virtual *vfs_ctx) + { + trace("Initializing USTAR with address %#llx", Address); + + if (!this->TestArchive(Address)) + return; /* Check whether the archive is deflated */ + debug("USTAR signature valid! Name:%s Signature:%s Mode:%c Size:%lu", ((FileHeader *)Address)->name, ((FileHeader *)Address)->signature, @@ -168,5 +182,7 @@ namespace VirtualFileSystem } } - USTAR::~USTAR() { warn("Destroyed"); } + USTAR::USTAR() {} + + USTAR::~USTAR() {} } diff --git a/Kernel.cpp b/Kernel.cpp index f81541d..9a792bc 100644 --- a/Kernel.cpp +++ b/Kernel.cpp @@ -412,7 +412,11 @@ EXTERNC NIF void Main() debug("Found initrd at %p", bInfo.Modules[i].Address); static char initrd = 0; if (!initrd++) - new VirtualFileSystem::USTAR((uintptr_t)bInfo.Modules[i].Address, vfs); + { + uintptr_t initrdAddress = (uintptr_t)bInfo.Modules[i].Address; + VirtualFileSystem::USTAR *ustar = new VirtualFileSystem::USTAR; + ustar->ReadArchive(initrdAddress, vfs); + } } } diff --git a/include/filesystem/ustar.hpp b/include/filesystem/ustar.hpp index 220932c..72ec83d 100644 --- a/include/filesystem/ustar.hpp +++ b/include/filesystem/ustar.hpp @@ -80,7 +80,9 @@ namespace VirtualFileSystem } public: - USTAR(uintptr_t Address, Virtual *vfs_ctx); + bool TestArchive(uintptr_t Address); + void ReadArchive(uintptr_t Address, Virtual *vfs_ctx); + USTAR(); ~USTAR(); }; }