diff options
author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2023-12-15 16:10:22 +0100 |
---|---|---|
committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2023-12-15 16:11:38 +0100 |
commit | 2298d17186cb0e58a96d285384de431902da9b1e (patch) | |
tree | 635d642931d9f55e701639ee3b3707e0e28a805e /stage3/fs.c | |
parent | 8a25a2935a60e65fcb3e2b715bada858f5fcd6a2 (diff) | |
download | cuddles-2298d17186cb0e58a96d285384de431902da9b1e.tar.xz |
big chungus
* fix a heap corruption bug
* add qemu support
* add an ATA driver
* add an USTAR read-only file system
* boot from disk instead of floppy
* font rendering
* image rendering
* PCI enumeration
* init script
Diffstat (limited to 'stage3/fs.c')
-rw-r--r-- | stage3/fs.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/stage3/fs.c b/stage3/fs.c new file mode 100644 index 0000000..9f7ea51 --- /dev/null +++ b/stage3/fs.c @@ -0,0 +1,31 @@ +#include "fs.h" +#include "ata.h" +#include "string.h" +#include "memory.h" +#include "heap.h" + +file fs_read(const char *filename) +{ + u64 start = (*(u32 *) (0x1000-10-8))/512; + + for (;;) { + u8 *info = ata_read_full(start, 1); + + if (memcmp(info+257, "ustar", 5) != 0) { + free(info); + return (file) { .len = 0, .data = nil }; + } + + u8 *infop = info+124; + usize fsize = parse_num(&infop, 8, 11); + usize fsect = (fsize+511)/512; + + if (memcmp(info, filename, strlen(filename) + 1) == 0) { + free(info); + return (file) { .len = fsize, .data = ata_read_full(start+1, fsect) }; + } else { + free(info); + start += 1 + fsect; + } + } +} |