Add ext2 superblock, document file system
diff --git a/src/kernel/Jmk b/src/kernel/Jmk
index a821bae..3b718b8 100644
--- a/src/kernel/Jmk
+++ b/src/kernel/Jmk
@@ -14,17 +14,20 @@
depends(ata_pio, dri/ata_pio, ata_pio.a)
depends(pci, dri/pci, pci.a)
depends(ide, dri/ide, ide.a)
+depends(ext2, dri/fs/ext2, ext2.a)
# AHCI not yet implemented
# depends(ahci, dri/ahci, ahci.a)
TEST ?=
test_defines = $(TEST:%=-DTEST_%)
+FS ?= ext2
+
CFLAGS += -I $(ROOT)/include/kernel $(test_defines)
LDFLAGS += -Tlink.ld -melf_i386
ASMFLAGS += -felf -Fdwarf
-QEMUFLAGS = -d cpu_reset -hda hd0.img
+QEMUFLAGS = -d cpu_reset -hda hd0_$(FS).img
OBJECTS = boot.o \
main.o \
@@ -49,6 +52,7 @@
task.o \
task_api.o \
faults.o \
+ lib(ext2) \
lib(ata_pio) \
lib(pci) \
lib(ide)
@@ -64,12 +68,12 @@
gdb $<
@pkill qemu-system-i38
-hd0.img:
+hd0_%.img:
status_log(MKFS, $@)
@dd bs=4M count=8 if=/dev/zero of=$@
- @mkfs.ext2 $@
+ @$(patsubst hd0_%.img,mkfs.%,$@) $@
-qemu: kernel.elf hd0.img
+qemu: kernel.elf hd0_$(FS).img
qemu-system-i386 $(QEMUFLAGS) -monitor stdio -kernel kernel.elf -no-reboot
qemu-iso: install
@@ -78,11 +82,11 @@
scan_codes.c: gen_scan_codes.py scan_codes.tsv
python3 $< > $@
-mount: hd0.img
+mount: hd0_$(FS).img
status_log(MOUNT, $^ $(ROOT)/mnt)
+ @if [ $(whoami) = root ]; then echo "DON'T RUN THIS AS ROOT" && exit 1; fi
@mkdir -p $(ROOT)/mnt
- @mount $^ $(ROOT)/mnt
- @if [ $$(whoami) = root ]; then echo 'You ran this as root, you probably want to chown $(ROOT)/mnt now.'; fi
+ @sudo mount $^ $(ROOT)/mnt -o rw,uid=$$(id -u),gid=$$(id -g)
umount:
status_log(UMOUNT, $(ROOT)/mnt)
diff --git a/src/kernel/boot.s b/src/kernel/boot.s
index 043c42c..047b326 100644
--- a/src/kernel/boot.s
+++ b/src/kernel/boot.s
@@ -100,7 +100,7 @@
[extern kmain] ; C code
start equ (_start)
-
+
_start:
;; First set up GDT
mov eax, (gdt_pointer - KERNEL_VIRTUAL_BASE)
diff --git a/src/kernel/dri/fs/ext2/Jmk b/src/kernel/dri/fs/ext2/Jmk
index b0da0c3..aac4c5c 100644
--- a/src/kernel/dri/fs/ext2/Jmk
+++ b/src/kernel/dri/fs/ext2/Jmk
@@ -8,7 +8,7 @@
archetype(c)
-CFLAGS += -I/include/kernel
+CFLAGS += -I$(ROOT)/include/kernel
OBJECTS = ext2.o
diff --git a/src/kernel/dri/fs/ext2/ext2.c b/src/kernel/dri/fs/ext2/ext2.c
index eb6842b..31ed7fe 100644
--- a/src/kernel/dri/fs/ext2/ext2.c
+++ b/src/kernel/dri/fs/ext2/ext2.c
@@ -1,7 +1,20 @@
#include <dri/fs/ext2/ext2.h>
+#include <dri/ata_pio/ata_pio.h>
#include <kint.h>
+#include <log.h>
+
+struct ext2_superblock ext2_read_superblock()
+{
+ uchar buffer[512 * 2];
+ ata_pio_read_sectors(buffer, 2, 2);
+
+ struct ext2_superblock *sb = (void *)(buffer);
+ return *sb;
+}
void ext2_mount(struct fs_node *where)
{
- // TODO
+ struct ext2_superblock sb = ext2_read_superblock();
+
+ kprintf("Magic = 0x%x\n", sb.signature);
}
diff --git a/src/kernel/main.c b/src/kernel/main.c
index b973b41..0fef9c5 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -13,6 +13,7 @@
#include <dri/ata_pio/ata_pio.h>
#include <dri/pci/pci.h>
#include <dri/ide/ide.h>
+#include <dri/fs/ext2/ext2.h>
void greet()
{
@@ -77,10 +78,7 @@
asm("sti");
- kprintf("initializing tasks\n");
init_tasks();
- kprintf("\ndone initializing tasks\n");
-
pci_init();
// Register PCI drivers
@@ -94,15 +92,17 @@
greet();
#endif
-#ifdef TEST_ATA_PIO
- test_ata_pio();
-#endif
-
#ifdef TEST_PCI
pci_print_devices();
pci_print_drivers();
#endif
+#ifdef TEST_ATA_PIO
+ test_ata_pio();
+#endif
+
+ ext2_mount(&root);
+
while (true)
asm("hlt");
diff --git a/src/kernel/task.c b/src/kernel/task.c
index b8ce525..c8068c4 100644
--- a/src/kernel/task.c
+++ b/src/kernel/task.c
@@ -27,8 +27,6 @@
void _init_tasks(uint kernel_esp, uint kernel_ebp, uint kernel_eip)
{
- kprintf("_init_tasks\n");
-
processes[0] = (struct process){
.exists = true,
.id = 0,
@@ -44,7 +42,6 @@
.last_stack_pos = 0xFFFFF000,
};
strcpy(processes[0].name, "kernel");
- kprintf("in _init_tasks, strlen of 'kernel' is %d\n", strlen("kernel"));
first_task = last_task = current_task = malloc(sizeof(struct ll_task_i));
@@ -58,8 +55,6 @@
.id = next_task_id++,
};
- kprintf("Returning from _init_tasks\n");
-
tasks_initialized = true;
}