got file loading working properly

This commit is contained in:
Benji Dial 2020-05-25 15:35:45 -04:00
parent c99a319d34
commit 44c0352f0d
6 changed files with 67 additions and 20 deletions

View file

@ -1,7 +1,6 @@
0x0001.0000 - 0x0001.ffff: unused
0x0002.0000 - 0x0002.7fff: fat
0x0002.8000 - 0x0002.bfff: unused
0x0002.c000 - 0x0002.ffff: file buffers
0x0003.0000 - 0x0003.7fff: kernel
0x0003.8000 - 0x0003.ffff: stack
0x0004.0000 - 0x000f.ffff: unused
0x0001.0000 - 0x0001.ffff (64k): unused
0x0002.0000 - 0x0002.7fff (32k): fat
0x0002.8000 - 0x0002.bfff (16k): unused
0x0002.c000 - 0x0002.ffff (16k): 32 file buffers
0x0003.0000 - 0x0003.7fff (32k): kernel
0x0003.8000 - 0x0003.ffff (32k): kernel stack

1
fs/bleh.txt Normal file
View file

@ -0,0 +1 @@
blah

View file

@ -1,4 +1,4 @@
disk: kernel boot
disk: kernel boot fs-
mkdir -p obj out
/sbin/mkfs.fat -C -f 1 -F 16 -n "PORTLAND OS" -R 17 -s 1 -S 512 obj/shadow.img 8192
echo -n -e '\xeb\x3c' > obj/jmp.bin
@ -6,13 +6,17 @@ disk: kernel boot
dd if=out/boot.bin of=obj/shadow.img obs=1 seek=62 conv=notrunc
dd if=out/kernel.bin of=obj/shadow.img seek=1 conv=notrunc
mv obj/shadow.img out/disk.img
mcopy -i out/disk.img -s out/fs/bleh.txt ::/
vdi-file: disk
VBoxManage convertfromraw out/disk.img out/disk.vdi --uuid a61929ed-3bf2-45ff-b98a-44f87c616dba
debug: vdi-file
debug: disk
gdb -x qemu-debug.gdb
fs-:
cp -r fs out/fs
kgccargs = -m32 -ffreestanding -fno-asynchronous-unwind-tables
kernel:
mkdir -p obj/kernel out

View file

@ -2,5 +2,6 @@ target remote | qemu-system-i386 -S -gdb stdio out/disk.img
add-symbol-file obj/kernel.elf
set disassembly-flavor intel
layout reg
break *0x30000
break main
break panic
cont

View file

@ -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));
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;

View file

@ -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();
}