From 44c0352f0d4124d7c367352e4de746a51b9db42b Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 25 May 2020 15:35:45 -0400 Subject: got file loading working properly --- src/kernel/fat.c | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'src/kernel/fat.c') diff --git a/src/kernel/fat.c b/src/kernel/fat.c index e574da5..b8d1c3b 100644 --- a/src/kernel/fat.c +++ b/src/kernel/fat.c @@ -7,8 +7,28 @@ void load_fat() { read_sectors(FAT_INFO->reserved_sectors, FAT_INFO->sectors_per_fat, FAT); } -bool check_fat_name(uint8_t *fname, uint8_t *sname) { - panic("Not implemented (check_fat_name)"); +bool to_fat_name(uint8_t *sname, uint8_t *fname) { + uint8_t *sp = sname, *fp = fname; + while (*sp != '.') { + if (!*sp) { + while (fp != fname + 11) + *(fp++) = ' '; + return false; + } + if (sp == sname + 8) + return true; + *(fp++) = *(sp++); + } + while (fp != fname + 8) + *(fp++) = ' '; + while (*++sp) { + if (fp == fname + 11) + return true; + *(fp++) = *sp; + } + while (fp != fname + 11) + *(fp++) = ' '; + return false; } bool check_fat_names(uint8_t *lname, uint8_t *rname) { @@ -27,27 +47,35 @@ void load_root() { } struct directory_entry *load_subentry(uint8_t *name) { + uint8_t fname[11]; + if (to_fat_name(name, fname)) + return 0; struct directory_entry *ptr = buffer; uint16_t dir_current = dir_start; - do - if (((ptr == buffer + 16) && !read_sectors(buffer_from = dir_current++, 1, ptr = buffer)) || !ptr->name[0]) - return 0; - while (!check_fat_name(ptr->name, name)); - return ptr; + read_sectors(buffer_from = dir_current, 1, buffer); + while (*(uint8_t *)ptr) { + if (check_fat_names(ptr->name, fname)) + return ptr; + if (++ptr == buffer + 16) { + read_sectors(buffer_from = ++dir_current, 1, buffer); + ptr = buffer; + } + }; + return 0; } bool load_subdir(uint8_t *name) { struct directory_entry *e = load_subentry(name); if (!e) return true; - dir_start = e->first_cluster; + dir_start = CTOS(e->first_cluster); return false; } struct directory_entry *load_entry(uint8_t *path) { load_root(); - for (uint8_t *ptr = path; ptr; ++ptr) - if (*ptr = '/') { + for (uint8_t *ptr = path; *ptr; ++ptr) + if (*ptr == '/') { *ptr = 0; if (load_subdir(path)) return 0; -- cgit v1.2.3