summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenji Dial <benji3.141@gmail.com>2020-05-25 15:35:45 -0400
committerBenji Dial <benji3.141@gmail.com>2020-05-25 15:35:45 -0400
commit44c0352f0d4124d7c367352e4de746a51b9db42b (patch)
tree65ad0862c92c4e2d134585b48fbfcc5bead165ea /src
parentc99a319d3405d4ac76881cae288c29624fa34a44 (diff)
downloadportland-os-44c0352f0d4124d7c367352e4de746a51b9db42b.tar.gz
got file loading working properly
Diffstat (limited to 'src')
-rw-r--r--src/kernel/fat.c48
-rw-r--r--src/kernel/main.c14
2 files changed, 52 insertions, 10 deletions
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;
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 194ce93..92e778c 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -54,5 +54,19 @@ void main() {
u32_dec(e.length, nbuf);
vga_printsz(nbuf);
}
+ fs_close(root);
+ if (root = fs_open("BLEH.TXT")) {
+ vga_printsz("\n\nContents of BLEH.TXT:");
+ uint8_t l;
+ uint8_t line[82];
+ line[0] = '\n';
+ line[1] = ' ';
+ line[2] = ' ';
+ while (l = fs_read(root, 78, line + 3)) {
+ line[l + 3] = 0;
+ vga_printsz(line);
+ }
+ fs_close(root);
+ }
halt();
} \ No newline at end of file