initrd: unallocate as files are dumped

This commit is contained in:
Matheus
2022-10-17 15:15:09 -03:00
parent 3d6098f9a9
commit 28b40a477b
+19
View File
@@ -4,6 +4,9 @@
#include <limine.h> #include <limine.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <kernel/pmm.h>
#include <kernel/vmm.h>
#define TAR_BLOCKSIZE 512 #define TAR_BLOCKSIZE 512
@@ -138,8 +141,20 @@ void initrd_parse(){
memset(entry.name, 0, 256); memset(entry.name, 0, 256);
memset(entry.link, 0, 101); memset(entry.link, 0, 101);
void* base = addr;
size_t bytespassed = 0;
for(;;){ for(;;){
// free files already dumped
if(bytespassed >= PAGE_SIZE){
size_t pagec = bytespassed / PAGE_SIZE;
pmm_hhdmfree(base, pagec);
base += bytespassed / PAGE_SIZE * PAGE_SIZE;
bytespassed %= PAGE_SIZE;
}
buildentry(&entry, addr); buildentry(&entry, addr);
@@ -166,6 +181,8 @@ void initrd_parse(){
} }
bytespassed += TAR_BLOCKSIZE;
if(entry.type != TAR_FILE) continue; if(entry.type != TAR_FILE) continue;
vnode_t *node; vnode_t *node;
@@ -177,6 +194,8 @@ void initrd_parse(){
} }
vfs_close(node); vfs_close(node);
bytespassed += entry.size / TAR_BLOCKSIZE * TAR_BLOCKSIZE + (entry.size % TAR_BLOCKSIZE > 0 ? TAR_BLOCKSIZE : 0);
} }
} }