From 28b40a477bef959bc0a2c4502f9da07b9ceeacdd Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 17 Oct 2022 15:15:09 -0300 Subject: [PATCH] initrd: unallocate as files are dumped --- src/fs/initrd.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/fs/initrd.c b/src/fs/initrd.c index 3f71c893..2108950b 100644 --- a/src/fs/initrd.c +++ b/src/fs/initrd.c @@ -4,6 +4,9 @@ #include #include #include +#include +#include + #define TAR_BLOCKSIZE 512 @@ -138,8 +141,20 @@ void initrd_parse(){ memset(entry.name, 0, 256); memset(entry.link, 0, 101); + void* base = addr; + size_t bytespassed = 0; + 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); @@ -164,10 +179,12 @@ void initrd_parse(){ printf("Failed creating %s: ERROR %lu\n", entry.name, err); break; } - + + + bytespassed += TAR_BLOCKSIZE; if(entry.type != TAR_FILE) continue; - + vnode_t *node; int error; vfs_open(&node, vfs_root(), entry.name); @@ -176,6 +193,8 @@ void initrd_parse(){ _panic("Failed to write from initrd", 0); } vfs_close(node); + + bytespassed += entry.size / TAR_BLOCKSIZE * TAR_BLOCKSIZE + (entry.size % TAR_BLOCKSIZE > 0 ? TAR_BLOCKSIZE : 0); }