fix(kernel/vfs): 🎉 a complete rewrite of the vfs

This is the fourth time re-writing the VFS, hope this will be the last. Tried to make it as modular as possible so this won't be necessary in the future. 🙏

This change required the entire kernel code to be modified.
This commit is contained in:
2025-05-13 15:59:12 +00:00
parent 83a7f83f81
commit 557c7e6235
83 changed files with 3252 additions and 2487 deletions

View File

@ -17,7 +17,7 @@
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <fs/vfs.hpp>
#include <acpi.hpp>
#include "../../kernel.h"
@ -38,9 +38,41 @@ void cmd_dump(const char *args)
*strLen = '\0';
strLen++;
void *Address = (void *)strtoul(strAddr, nullptr, 16);
void *Address;
unsigned long Length = strtoul(strLen, nullptr, 10);
Node root = fs->GetRoot(0);
Node fileNode = fs->Lookup(root, strAddr);
if (fileNode && !fileNode->IsDirectory() && !fileNode->IsFIFO() && !fileNode->IsSocket())
{
kstat stat;
int status = fs->Stat(fileNode, &stat);
if (status != 0)
{
printf("cannot get stat: %s\n", strerror(status));
return;
}
size_t size = stat.Size > (off_t)Length ? Length : stat.Size;
Address = new char[size]; /* FIXME: memory leak */
size_t read = fs->Read(fileNode, Address, size, 0);
if (read < Length)
{
debug("clamp %lu to %lu", Length, read);
Length = read;
}
}
else
{
if (fileNode)
{
printf("file %s cannot be dumped\n", strAddr);
return;
}
Address = (void *)strtoul(strAddr, nullptr, 16);
debug("address %s", strAddr);
}
{
unsigned char *AddressChar = (unsigned char *)Address;
unsigned char Buffer[17];
@ -74,4 +106,4 @@ void cmd_dump(const char *args)
}
putchar('\n');
}
}
}