aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/fs
diff options
context:
space:
mode:
authorMarvin Borner2020-04-25 15:31:09 +0200
committerMarvin Borner2020-04-25 15:31:09 +0200
commit30601e14f216488ee3a36dc44ab0ed56da7ccdb2 (patch)
tree3bef128513ce569b64788853d688179ac7562096 /src/kernel/fs
parent24175ce2a37d6f5d9ba367f942fabce681ee9e4a (diff)
Working ext2 filereader
As soon as I implement indirect block pointers, the resources will hopefully work again :)
Diffstat (limited to 'src/kernel/fs')
-rw-r--r--src/kernel/fs/ext2.c52
-rw-r--r--src/kernel/fs/ext2.h6
-rw-r--r--src/kernel/fs/load.c28
3 files changed, 40 insertions, 46 deletions
diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c
index 3ab2f89..1d531de 100644
--- a/src/kernel/fs/ext2.c
+++ b/src/kernel/fs/ext2.c
@@ -24,10 +24,10 @@ void ext2_init_fs()
struct ext2_inode root_inode;
read_inode(&root_inode, ROOT_INODE);
- log("Creation time = %d", root_inode.creation_time);
- log("UID = %d", root_inode.uid);
- log("Type & perms = 0x%x", root_inode.type_and_permissions);
- log("Size = %d", root_inode.size);
+ log("Creation time: %d", root_inode.creation_time);
+ log("UID: %d", root_inode.uid);
+ log("Type & perms: 0x%x", root_inode.type_and_permissions);
+ log("Size: %d", root_inode.size);
log("Files:");
@@ -39,13 +39,6 @@ void ext2_init_fs()
log("Inode %d, name '%s'", dirent.inode_num, dirent.name);
kfree(file.buf);
-
- log("Looking for file '/test'...");
- uint32_t inode = ext2_look_up_path("/test");
- if (inode == 0)
- log("File not found");
- else
- log("Found: inode = %d", inode);
}
static void read_block(uint32_t block_num, void *buf)
@@ -67,13 +60,14 @@ static void load_superblock()
num_groups = superblock.total_blocks / superblock.blocks_per_group;
assert(superblock.signature == EXT2_SIGNATURE);
- log("Total inodes = 0x%x", superblock.total_inodes);
- log("Total blocks = 0x%x", superblock.total_blocks);
- log("Block size = %d", block_size);
- log("Num blocks = %d", superblock.total_blocks);
- log("Blocks/group = %d", superblock.blocks_per_group);
- log("Inodes/group = %d", superblock.inodes_per_group);
- log("Num groups = %d", num_groups);
+ log("Total inodes: 0x%x", superblock.total_inodes);
+ log("Total blocks: 0x%x", superblock.total_blocks);
+ log("Block size: %d", block_size);
+ log("Num blocks: %d", superblock.total_blocks);
+ log("Blocks/group: %d", superblock.blocks_per_group);
+ log("Inodes/group: %d", superblock.inodes_per_group);
+ log("Num groups: %d", num_groups);
+ log("Creator OS: %s", superblock.creator_os_id == 0 ? "Linux" : "Other");
}
static void load_bgdt()
@@ -208,7 +202,7 @@ uint32_t ext2_look_up_path(char *path)
path++;
uint32_t curr_dir_inode = ROOT_INODE;
- for (;;) {
+ while (1) {
size_t j;
for (j = 0; path[j] != '/' && path[j] != '\0'; j++)
;
@@ -232,3 +226,23 @@ uint32_t ext2_look_up_path(char *path)
return inode;
}
+
+// Implementations
+
+uint8_t *read_file(char *path)
+{
+ uint32_t inode = ext2_look_up_path(path);
+ struct ext2_file file;
+ ext2_open_inode(inode, &file);
+ if (inode != 0) {
+ size_t size = file.inode.size;
+ log("%d", size);
+ uint8_t *buf = kmalloc(size);
+ ext2_read(&file, buf, size);
+ kfree(file.buf);
+ buf[size - 1] = '\0';
+ return buf;
+ } else {
+ return NULL;
+ }
+}
diff --git a/src/kernel/fs/ext2.h b/src/kernel/fs/ext2.h
index f9c977c..7fbe493 100644
--- a/src/kernel/fs/ext2.h
+++ b/src/kernel/fs/ext2.h
@@ -33,12 +33,12 @@ struct ext2_superblock {
uint16_t mounts_since_fsck;
uint16_t max_mounts_since_fsck;
uint16_t signature;
- uint16_t state;
+ uint16_t state; // 1 clean; 2 errors
uint16_t error_action;
uint16_t minor_version;
uint32_t last_fsck_time;
uint32_t max_time_since_fsck;
- uint32_t creator_OS_id;
+ uint32_t creator_os_id;
uint32_t major_version;
uint16_t res_block_uid;
uint16_t res_block_gid;
@@ -137,4 +137,6 @@ bool ext2_next_dirent(struct ext2_file *file, struct ext2_dirent *dir);
uint32_t ext2_find_in_dir(uint32_t dir_inode, const char *name);
uint32_t ext2_look_up_path(char *path);
+uint8_t *read_file(char *path);
+
#endif
diff --git a/src/kernel/fs/load.c b/src/kernel/fs/load.c
index 9aca1c3..974c3fe 100644
--- a/src/kernel/fs/load.c
+++ b/src/kernel/fs/load.c
@@ -6,30 +6,8 @@
void load_binaries()
{
- userspace = (uint32_t)kmalloc(10000);
- font = (struct font *)kmalloc(100000); // High quality shit
+ //userspace = (uint32_t)read_file("/bin/user.bin");
+ font = (struct font *)read_file("/bin/font.bin");
- /*if (multiboot_header->boot_device != 0xE0FFFFFF) {
- panic("Unsupported boot drive!");
- } else {
- char *font_p[] = { "FONT.BIN" };
- struct iso9660_entity *font_e = ISO9660_get(font_p, 1);
- if (!font_e)
- panic("Font not found!");
- ATAPI_granular_read(1 + (font_e->length / 2048), font_e->lba, (uint8_t *)font);
- kfree(font_e);
-
- char *user_p[] = { "USER.BIN" };
- struct iso9660_entity *user_e = ISO9660_get(user_p, 1);
- if (!user_e)
- panic("Userspace binary not found!");
- ATAPI_granular_read(1 + (user_e->length / 2048), user_e->lba, (uint8_t *)userspace);
- kfree(user_e);
-
- if (font->magic != 0xf0f0f0f0) {
- warn("0x%x: WRONG FONT MAGIC!", font->magic);
- halt_loop();
- }
- }*/
log("Successfully loaded binaries");
-} \ No newline at end of file
+}