Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Begin Cleanup of Ext2 Code, Added Panic
Browse files Browse the repository at this point in the history
  • Loading branch information
xing1357 committed Oct 26, 2022
1 parent 544a80d commit ccc7379
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 204 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DEFINES=

# qemu
QEMU= qemu-system-i386
QEMU_FLAGS= -cdrom out/SimpleOS.iso -drive file=ext2.img,format=raw
QEMU_FLAGS= -m 64 -cdrom out/SimpleOS.iso -drive file=ext2.img,format=raw

# assembler flags
ASM_FLAGS = -f elf32
Expand Down Expand Up @@ -54,7 +54,8 @@ OBJECTS=$(ASM_OBJ)/entry.o $(ASM_OBJ)/load_gdt.o\
$(OBJ)/pmm.o\
$(OBJ)/bios32.o\
$(OBJ)/vesa.o\
$(OBJ)/bitmap.o
$(OBJ)/bitmap.o\
$(OBJ)/panic.o\

all: $(OBJECTS)
@printf "[ linking... ]\n"
Expand Down Expand Up @@ -203,9 +204,14 @@ $(OBJ)/bitmap.o : $(SRC)/bitmap.c
$(CC) $(CC_FLAGS) -c $(SRC)/bitmap.c -o $(OBJ)/bitmap.o
@printf "\n"

$(OBJ)/panic.o : $(SRC)/panic.c
@printf "[ $(SRC)/panic.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/panic.c -o $(OBJ)/panic.o
@printf "\n"

run:
$(QEMU) $(QEMU_FLAGS)

clean:
rm -f $(OBJ)/*.o
rm -f $(ASM_OBJ)/*.o
rm -f $(ASM_OBJ)/*
50 changes: 32 additions & 18 deletions include/ext2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define EXT2_H
#include "types.h"

#define EXT2_SUPER 1

#define INODE_SIZE 256 //Hardcoded here cause im lazy @TODO read the actual superblock field dummy

#define INODE_TYPE_FIFO 1
Expand All @@ -16,33 +18,46 @@
#define FILE_NOT_FOUND 0

typedef struct ext2_superblock {
uint32 inode_num;
uint32 block_num;
uint32 reserved_blocks;
uint32 unalloc_blocks;
uint32 unalloc_inodes;
uint32 sb_block_num;
uint32 block_size;
uint32 fragment_size;
uint32 blocks_per_group;
uint32 fragments_per_group;
uint32 inodes_per_group;
uint32 inodes_count; // Total # of inodes
uint32 blocks_count; // Total # of blocks
uint32 r_blocks_count; // # of reserved blocks for superuser
uint32 free_blocks_count;
uint32 free_inodes_count;
uint32 first_data_block;
uint32 log_block_size; // 1024 << Log2 block size = block size
uint32 log_frag_size;
uint32 blocks_per_group;
uint32 frags_per_group;
uint32 inodes_per_group;
uint32 mtime; // Last mount time, in POSIX time
uint32 wtime; // Last write time, in POSIX time
uint16 mnt_count; // # of mounts since last check
uint16 max_mnt_count; // # of mounts before fsck must be done
uint16 magic; // 0xEF53
uint16 state;
uint16 errors;
uint16 minor_rev_level;
uint32 lastcheck;
uint32 checkinterval;
uint32 creator_os;
uint32 rev_level;
uint16 def_resuid;
uint16 def_resgid;
}ext2_superblock;

typedef struct ext2_bgdt {
uint32 blk_bmap;
uint32 inode_bmap;
uint32 inode_table_start;
uint32 unalloc_blocks;
uint32 unalloc_inodes;
uint32 num_of_dirs;
uint16 unalloc_blocks;
uint16 unalloc_inodes;
uint16 num_of_dirs;
uint16 pad[7];
}ext2_bgdt;

typedef struct ext2_inode
{
unsigned short type_perm;
uint32 type;
uint32 perm;
unsigned short user_id;
unsigned int size_low;
unsigned int last_access_time;
Expand Down Expand Up @@ -74,8 +89,7 @@ typedef struct ext2_dirent
char* name;
} ext2_dirent;

ext2_superblock sb;
ext2_bgdt bgdt;
ext2_superblock* sb;

void read_superblock();
void ext2_init();
Expand Down
6 changes: 6 additions & 0 deletions include/panic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef PANIC_H
#define PANIC_H

void panic(char *message);

#endif
12 changes: 11 additions & 1 deletion mkdisk.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#!/bin/bash
dd if=/dev/zero of=ext2.img bs=1024 count=8192 > /dev/zero
printf "Creating Disk...\n"
dd if=/dev/zero of=ext2.img bs=1024 count=10000 > /dev/zero
mkfs -t ext2 -i 1024 -b 1024 -F ext2.img > /dev/zero
printf "Mounting...\n"
rm -rf /mnt/ext2
mkdir /mnt/ext2
mount ext2.img /mnt/ext2
printf "MOUNTED!\n"
cp -r rootfs/* /mnt/ext2
umount ext2.img
printf "Done!\n"




Binary file modified obj/ext2.o
Binary file not shown.
Binary file modified obj/kernel.o
Binary file not shown.
Binary file added obj/panic.o
Binary file not shown.
Binary file modified out/SimpleOS.iso
Binary file not shown.
Binary file modified out/isodir/boot/SimpleOS.bin
Binary file not shown.
1 change: 1 addition & 0 deletions rootfs/test/subdir/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello there
Loading

0 comments on commit ccc7379

Please sign in to comment.