summaryrefslogtreecommitdiffhomepage
path: root/src/loader/inc
diff options
context:
space:
mode:
Diffstat (limited to 'src/loader/inc')
-rw-r--r--src/loader/inc/dev.h3
-rw-r--r--src/loader/inc/dsk.h21
-rw-r--r--src/loader/inc/fs.h15
-rw-r--r--src/loader/inc/fs/ext2.h98
-rw-r--r--src/loader/inc/ide.h5
-rw-r--r--src/loader/inc/lib.h1
6 files changed, 121 insertions, 22 deletions
diff --git a/src/loader/inc/dev.h b/src/loader/inc/dev.h
index 7ea3147..6fcbf25 100644
--- a/src/loader/inc/dev.h
+++ b/src/loader/inc/dev.h
@@ -4,7 +4,7 @@
#define DEV_H
#include <def.h>
-#include <fs.h>
+#include <dsk.h>
enum dev_type {
DEV_DISK,
@@ -22,7 +22,6 @@ struct dev {
struct fs fs;
u32 data; // Optional (device-specific) data/information
- u8 exists : 1;
};
struct dev *dev_get(u8 id);
diff --git a/src/loader/inc/dsk.h b/src/loader/inc/dsk.h
new file mode 100644
index 0000000..5b2dec9
--- /dev/null
+++ b/src/loader/inc/dsk.h
@@ -0,0 +1,21 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#ifndef DSK_H
+#define DSK_H
+
+#include <def.h>
+
+// General disk assumptions
+#define BLOCK_SIZE 1024
+#define BLOCK_COUNT 256 // BLOCK_SIZE / sizeof(u32)
+#define SECTOR_SIZE 512
+#define SECTOR_COUNT (BLOCK_SIZE / SECTOR_SIZE) // 2
+
+struct dev;
+struct fs {
+ s32 (*read)(const char *, void *, u32, u32, struct dev *);
+};
+
+void dsk_detect(struct dev *dev);
+
+#endif
diff --git a/src/loader/inc/fs.h b/src/loader/inc/fs.h
deleted file mode 100644
index 84cd2d7..0000000
--- a/src/loader/inc/fs.h
+++ /dev/null
@@ -1,15 +0,0 @@
-// MIT License, Copyright (c) 2021 Marvin Borner
-
-#ifndef FS_H
-#define FS_H
-
-#include <def.h>
-struct dev;
-
-struct fs {
- s32 (*read)(void *, u32, u32, struct dev *);
-};
-
-void fs_detect(struct dev *dev);
-
-#endif
diff --git a/src/loader/inc/fs/ext2.h b/src/loader/inc/fs/ext2.h
new file mode 100644
index 0000000..10650cd
--- /dev/null
+++ b/src/loader/inc/fs/ext2.h
@@ -0,0 +1,98 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#ifndef EXT2_H
+#define EXT2_H
+
+#include <def.h>
+#include <dev.h>
+
+#define EXT2_BOOT 0
+#define EXT2_SUPER 1
+#define EXT2_ROOT 2
+#define EXT2_MAGIC 0xef53
+
+#define EXT2_INODE_SIZE (sizeof(struct ext2_inode))
+
+struct ext2_superblock {
+ u32 total_inodes;
+ u32 total_blocks;
+ u32 su_res_blocks; // Superuser reserved
+ u32 free_blocks;
+ u32 free_inodes;
+ u32 superblock_block_num;
+ u32 log2_block_size;
+ u32 log2_frag_size;
+ u32 blocks_per_group;
+ u32 frags_per_group;
+ u32 inodes_per_group;
+ u32 last_mount_time;
+ u32 last_write_time;
+ u16 mounts_since_fsck;
+ u16 max_mounts_since_fsck;
+ u16 magic;
+ u16 state; // 1 clean; 2 errors
+ u16 error_action;
+ u16 minor_version;
+ u32 last_fsck_time;
+ u32 max_time_since_fsck;
+ u32 creator_os_id;
+ u32 major_version;
+ u16 res_block_uid;
+ u16 res_block_gid;
+};
+
+struct ext2_bgd {
+ u32 block_bitmap;
+ u32 inode_bitmap;
+ u32 inode_table;
+ u16 free_blocks;
+ u16 free_inodes;
+ u16 used_dirs;
+ u16 pad;
+ u8 bg_reserved[12];
+};
+
+struct ext2_inode {
+ u16 mode;
+ u16 uid;
+ u32 size;
+
+ u32 last_access_time;
+ u32 creation_time;
+ u32 last_modification_time;
+ u32 deletion_time;
+
+ u16 gid;
+ u16 link_count;
+ u32 blocks;
+ u32 flags;
+ u32 os_specific_val1;
+ u32 block[15];
+ u32 generation;
+
+ u32 reserved1;
+ u32 reserved2;
+
+ u32 fragment_addr;
+ u8 os_specific_val2[12];
+};
+
+struct ext2_dirent {
+ u32 inode_num;
+ u16 total_len;
+ u8 name_len;
+ u8 type_indicator;
+ u8 name[];
+};
+
+struct ext2_file {
+ struct ext2_inode inode;
+ u32 pos;
+ u8 block_index;
+ u8 *buf;
+ u32 curr_block_pos;
+};
+
+u8 ext2_detect(struct dev *dev);
+
+#endif
diff --git a/src/loader/inc/ide.h b/src/loader/inc/ide.h
index 24b4eb1..7faee03 100644
--- a/src/loader/inc/ide.h
+++ b/src/loader/inc/ide.h
@@ -3,11 +3,6 @@
#ifndef IDE_H
#define IDE_H
-#define BLOCK_SIZE 1024
-#define BLOCK_COUNT 256 // BLOCK_SIZE / sizeof(u32)
-#define SECTOR_SIZE 512
-#define SECTOR_COUNT (BLOCK_SIZE / SECTOR_SIZE)
-
#define ATA_PRIMARY_IO 0x1f0
#define ATA_SECONDARY_IO 0x170
diff --git a/src/loader/inc/lib.h b/src/loader/inc/lib.h
index d5984dd..e811670 100644
--- a/src/loader/inc/lib.h
+++ b/src/loader/inc/lib.h
@@ -8,6 +8,7 @@
u32 strlen(const char *str);
u32 strnlen(const char *s, u32 max);
u32 strlcpy(char *dst, const char *src, u32 size);
+s32 strncmp(const char *s1, const char *s2, u32 n);
void *memcpy(void *dest, const void *src, u32 n);
void *memset(void *dest, u32 val, u32 n);