aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/fs
diff options
context:
space:
mode:
authorMarvin Borner2020-04-16 19:06:33 +0200
committerMarvin Borner2020-04-16 19:06:33 +0200
commit4014a36377ff69f6433e7b0af2144bc3a7d29ca7 (patch)
tree9440ac3749d406c6df9917d4bb3a19de6ea99655 /src/kernel/fs
parentfc26e84ef8c6255926811fe639e3e466b756e581 (diff)
Many fix attempts for the divide by zero exception
Diffstat (limited to 'src/kernel/fs')
-rw-r--r--src/kernel/fs/ata.c16
-rw-r--r--src/kernel/fs/ata.h6
-rw-r--r--src/kernel/fs/elf.c8
-rw-r--r--src/kernel/fs/ext2.c (renamed from src/kernel/fs/ext2/ext2.c)29
-rw-r--r--src/kernel/fs/ext2.h (renamed from src/kernel/fs/ext2/ext2.h)4
-rw-r--r--src/kernel/fs/vfs.c (renamed from src/kernel/fs/vfs/vfs.c)11
-rw-r--r--src/kernel/fs/vfs.h (renamed from src/kernel/fs/vfs/vfs.h)0
7 files changed, 36 insertions, 38 deletions
diff --git a/src/kernel/fs/ata.c b/src/kernel/fs/ata.c
index 817bb98..ac42275 100644
--- a/src/kernel/fs/ata.c
+++ b/src/kernel/fs/ata.c
@@ -8,7 +8,7 @@
#include <kernel/pci/pci.h>
#include <kernel/interrupts/interrupts.h>
-uint32_t ata_device;
+uint32_t ata_device = 0x00000000;
ata_dev_t primary_master = { .slave = 0 };
ata_dev_t primary_slave = { .slave = 1 };
@@ -30,7 +30,7 @@ void software_reset(ata_dev_t *dev)
outb(dev->control, CONTROL_ZERO);
}
-void ata_handler(struct regs *reg)
+void ata_handler(struct regs *r)
{
inb(primary_master.status);
inb(primary_master.BMR_STATUS);
@@ -240,14 +240,14 @@ void ata_device_detect(ata_dev_t *dev, int primary)
outb(dev->command, COMMAND_IDENTIFY);
if (!inb(dev->status)) {
- log("Device does not exist");
+ warn("Device does not exist: %s", dev->mountpoint);
return;
}
uint8_t lba_lo = inb(dev->lba_lo);
uint8_t lba_hi = inb(dev->lba_high);
if (lba_lo != 0 || lba_hi != 0) {
- log("Device is not ata-compatible");
+ warn("Device is not ata-compatible: %s", dev->mountpoint);
return;
}
uint8_t drq = 0, err = 0;
@@ -256,7 +256,7 @@ void ata_device_detect(ata_dev_t *dev, int primary)
err = inb(dev->status) & STATUS_ERR;
}
if (err) {
- log("Error while polling");
+ warn("Error while polling: %s", dev->mountpoint);
return;
}
@@ -283,10 +283,10 @@ void ata_init()
{
pci_scan(&ata_find, -1, &ata_device);
- irq_install_handler(32 + 14, ata_handler);
+ irq_install_handler(14, ata_handler);
ata_device_detect(&primary_master, 1);
ata_device_detect(&primary_slave, 1);
- ata_device_detect(&secondary_master, 0);
- ata_device_detect(&secondary_slave, 0);
+ /* ata_device_detect(&secondary_master, 0); */
+ /* ata_device_detect(&secondary_slave, 0); */
}
diff --git a/src/kernel/fs/ata.h b/src/kernel/fs/ata.h
index 72ded20..4a2951f 100644
--- a/src/kernel/fs/ata.h
+++ b/src/kernel/fs/ata.h
@@ -1,7 +1,7 @@
#ifndef ATA_DRIVER_H
#define ATA_DRIVER_H
-#include <kernel/fs/vfs/vfs.h>
+#include <kernel/fs/vfs.h>
#include <kernel/memory/paging.h>
#include <kernel/interrupts/interrupts.h>
@@ -56,7 +56,7 @@ typedef struct ata_dev {
char mountpoint[32];
} __attribute__((packed)) ata_dev_t;
-// ATA PCI info
+// ATA PCI info of QEMU // TODO: Remove Qemu based device id
#define ATA_VENDOR_ID 0x8086
#define ATA_DEVICE_ID 0x7010
@@ -116,4 +116,4 @@ void ata_device_detect(ata_dev_t *dev, int primary);
void ata_init();
-#endif \ No newline at end of file
+#endif
diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c
index b6d90c9..493bdac 100644
--- a/src/kernel/fs/elf.c
+++ b/src/kernel/fs/elf.c
@@ -40,16 +40,16 @@ uint32_t load_elf(char *elf_data)
v_begin = p_entry->vaddr;
v_end = p_entry->vaddr + p_entry->memsz;
if (v_begin < USER_OFFSET) {
- warn("load_elf(): can't load executable below %x\n", USER_OFFSET);
+ warn("load_elf(): can't load executable below %x", USER_OFFSET);
return 0;
}
if (v_end > USER_STACK) {
- warn("load_elf(): can't load executable above %x\n", USER_STACK);
+ warn("load_elf(): can't load executable above %x", USER_STACK);
return 0;
}
- printf("ELF: entry flags: %x (%d)\n", p_entry->flags, p_entry->flags);
+ log("ELF: entry flags: %x (%d)", p_entry->flags, p_entry->flags);
memcpy((uint8_t *)v_begin, (uint8_t *)(elf_data + p_entry->offset),
p_entry->filesz);
@@ -63,4 +63,4 @@ uint32_t load_elf(char *elf_data)
}
return hdr->entry;
-} \ No newline at end of file
+}
diff --git a/src/kernel/fs/ext2/ext2.c b/src/kernel/fs/ext2.c
index b14d726..bc17db6 100644
--- a/src/kernel/fs/ext2/ext2.c
+++ b/src/kernel/fs/ext2.c
@@ -5,7 +5,7 @@
#include <kernel/lib/stdio.h>
#include <kernel/lib/lib.h>
#include <kernel/memory/alloc.h>
-#include <kernel/fs/ext2/ext2.h>
+#include <kernel/fs/ext2.h>
uint32_t ext2_file_size(vfs_node_t *node)
{
@@ -259,7 +259,7 @@ void ext2_create_entry(vfs_node_t *parent, char *entry_name, uint32_t entry_inod
if (curr_dir->name_len == entry_name_len) {
memcpy(check, curr_dir->name, entry_name_len);
if (curr_dir->inode != 0 && !strcmp(entry_name, check)) {
- log("Entry by the same name %s already exist\n", check);
+ log("Entry by the same name %s already exist", check);
return;
}
}
@@ -570,8 +570,7 @@ void set_disk_block_number(ext2_fs_t *ext2fs, inode_t *inode, uint32_t inode_idx
}
b = a - p;
if (b <= 0) {
- alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS]), ext2fs, inode,
- inode_idx, NULL, 0);
+ if(!alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS]), ext2fs, inode, inode_idx, NULL, 0));
read_disk_block(ext2fs, inode->blocks[EXT2_DIRECT_BLOCKS], (void *)tmp);
((unsigned int *)tmp)[a] = disk_block;
write_disk_block(ext2fs, inode->blocks[EXT2_DIRECT_BLOCKS], (void *)tmp);
@@ -582,11 +581,9 @@ void set_disk_block_number(ext2_fs_t *ext2fs, inode_t *inode, uint32_t inode_idx
if (c <= 0) {
c = b / p;
d = b - c * p;
- alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS + 1]), ext2fs, inode,
- inode_idx, NULL, 0);
+ if(!alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS + 1]), ext2fs, inode, inode_idx, NULL, 0));
read_disk_block(ext2fs, inode->blocks[EXT2_DIRECT_BLOCKS + 1], (void *)tmp);
- alloc_inode_metadata_block(&(tmp[c]), ext2fs, inode, inode_idx, (void *)tmp,
- inode->blocks[EXT2_DIRECT_BLOCKS + 1]);
+ if(!alloc_inode_metadata_block(&(tmp[c]), ext2fs, inode, inode_idx, (void*)tmp, inode->blocks[EXT2_DIRECT_BLOCKS + 1]));
unsigned int temp = tmp[c];
read_disk_block(ext2fs, temp, (void *)tmp);
tmp[d] = disk_block;
@@ -598,14 +595,12 @@ void set_disk_block_number(ext2_fs_t *ext2fs, inode_t *inode, uint32_t inode_idx
e = c / (p * p);
f = (c - e * p * p) / p;
g = (c - e * p * p - f * p);
- alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS + 2]), ext2fs, inode,
- inode_idx, NULL, 0);
+ if(!alloc_inode_metadata_block(&(inode->blocks[EXT2_DIRECT_BLOCKS + 2]), ext2fs, inode, inode_idx, NULL, 0));
read_disk_block(ext2fs, inode->blocks[EXT2_DIRECT_BLOCKS + 2], (void *)tmp);
- alloc_inode_metadata_block(&(tmp[e]), ext2fs, inode, inode_idx, (void *)tmp,
- inode->blocks[EXT2_DIRECT_BLOCKS + 2]);
+ if(!alloc_inode_metadata_block(&(tmp[e]), ext2fs, inode, inode_idx, (void*)tmp, inode->blocks[EXT2_DIRECT_BLOCKS + 2]));
unsigned int temp = tmp[e];
read_disk_block(ext2fs, tmp[e], (void *)tmp);
- alloc_inode_metadata_block(&(tmp[f]), ext2fs, inode, inode_idx, (void *)tmp, temp);
+ if(!alloc_inode_metadata_block(&(tmp[f]), ext2fs, inode, inode_idx, (void*)tmp, temp));
temp = tmp[f];
read_disk_block(ext2fs, tmp[f], (void *)tmp);
tmp[g] = disk_block;
@@ -642,7 +637,7 @@ uint32_t ext2_alloc_block(ext2_fs_t *ext2fs)
}
}
}
- panic("We're out of blocks!\n");
+ panic("We're out of blocks!");
return (uint32_t)-1;
}
@@ -707,7 +702,7 @@ uint32_t alloc_inode(ext2_fs_t *ext2fs)
}
}
}
- panic("We're out of inodes!\n");
+ panic("We're out of inodes!");
return (uint32_t)-1;
}
@@ -762,10 +757,12 @@ void ext2_init(char *device_path, char *mountpoint)
{
ext2_fs_t *ext2fs = kcalloc(sizeof(ext2_fs_t), 1);
ext2fs->disk_device = file_open(device_path, 0);
+ log("%s", ext2fs->disk_device->name);
ext2fs->sb = kmalloc(SUPERBLOCK_SIZE);
ext2fs->block_size = 1024;
- read_disk_block(ext2fs, 1, (void *)ext2fs->sb);
+ read_disk_block(ext2fs, 1, (void *)ext2fs->sb); //!
log("%x", ext2fs->sb->ext2_magic);
+ log("%x", ext2fs->sb->total_inodes);
ext2fs->block_size = (1024 << ext2fs->sb->log2block_size);
ext2fs->blocks_per_group = ext2fs->sb->blocks_per_group;
ext2fs->inodes_per_group = ext2fs->sb->inodes_per_group;
diff --git a/src/kernel/fs/ext2/ext2.h b/src/kernel/fs/ext2.h
index 3996ba5..62105c7 100644
--- a/src/kernel/fs/ext2/ext2.h
+++ b/src/kernel/fs/ext2.h
@@ -2,7 +2,7 @@
#define MELVIX_EXT2_H
#include <stdint.h>
-#include <kernel/fs/vfs/vfs.h>
+#include <kernel/fs/vfs.h>
#define EXT2_DIRECT_BLOCKS 12
@@ -208,4 +208,4 @@ vfs_node_t *get_ext2_root(ext2_fs_t *ext2fs, inode_t *inode);
void ext2_init(char *device_path, char *mountpoint);
-#endif \ No newline at end of file
+#endif
diff --git a/src/kernel/fs/vfs/vfs.c b/src/kernel/fs/vfs.c
index 10d3c21..9dc684c 100644
--- a/src/kernel/fs/vfs/vfs.c
+++ b/src/kernel/fs/vfs.c
@@ -1,6 +1,6 @@
#include <kernel/system.h>
-#include <kernel/fs/ext2/ext2.h>
-#include <kernel/fs/vfs/vfs.h>
+#include <kernel/fs/ext2.h>
+#include <kernel/fs/vfs.h>
#include <kernel/lib/data/list.h>
#include <kernel/lib/data/generic_tree.h>
#include <kernel/memory/alloc.h>
@@ -53,7 +53,7 @@ void print_vfstree_recur(gtreenode_t *node, int parent_offset)
} else {
log("%s(empty)", fnode->name);
}
- log("%s\n", tmp);
+ log("%s", tmp);
len = strlen(fnode->name);
kfree(tmp);
foreach(child, node->children)
@@ -259,6 +259,7 @@ vfs_node_t *get_mountpoint_recur(char **path, gtreenode_t *subroot)
}
return get_mountpoint_recur(path, subroot);
}
+
vfs_node_t *get_mountpoint(char **path)
{
if (strlen(*path) > 1 && (*path)[strlen(*path) - 1] == '/')
@@ -324,7 +325,7 @@ void vfs_mount_recur(char *path, gtreenode_t *subroot, vfs_node_t *fs_obj)
if (curr_token == NULL || !strcmp(curr_token, "")) {
struct vfs_entry *ent = (struct vfs_entry *)subroot->value;
if (ent->file) {
- log("The path is already mounted, plz unmount before mounting again\n");
+ warn("The path is already mounted, please unmount before mounting again");
return;
}
if (!strcmp(ent->name, "/"))
@@ -358,7 +359,7 @@ void vfs_mount(char *path, vfs_node_t *fs_obj)
if (path[0] == '/' && strlen(path) == 1) {
struct vfs_entry *ent = (struct vfs_entry *)vfs_tree->root->value;
if (ent->file) {
- log("The path is already mounted, plz unmount before mounting again\n");
+ warn("The path is already mounted, please unmount before mounting again");
return;
}
vfs_root = fs_obj;
diff --git a/src/kernel/fs/vfs/vfs.h b/src/kernel/fs/vfs.h
index b31767e..b31767e 100644
--- a/src/kernel/fs/vfs/vfs.h
+++ b/src/kernel/fs/vfs.h