aboutsummaryrefslogtreecommitdiff
path: root/kernel/features
diff options
context:
space:
mode:
authorMarvin Borner2021-04-30 15:03:27 +0200
committerMarvin Borner2021-04-30 15:03:27 +0200
commit350748137b62e2aa15c62c53ebf4d30816e441f4 (patch)
treea4c1b1c443c1f0de4bd74336a9ceed9376ce694a /kernel/features
parent3a3d50d7eb0f4fdbb9beaf16bacfa98689cc448c (diff)
Added MBR driver and better disk creation
Diffstat (limited to 'kernel/features')
-rw-r--r--kernel/features/fs.c70
-rw-r--r--kernel/features/proc.c2
2 files changed, 41 insertions, 31 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index 6cb10c8..fdd5154 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -7,6 +7,7 @@
#include <errno.h>
#include <fs.h>
#include <ide.h>
+#include <mbr.h>
#include <mem.h>
#include <mm.h>
#include <print.h>
@@ -94,33 +95,6 @@ struct vfs_dev *vfs_find_dev(const char *path)
return m && m->dev ? m->dev : NULL;
}
-/*static const char *vfs_resolve_type(enum vfs_type type)
-{
- switch (type) {
- case VFS_DEVFS:
- return "devfs";
- case VFS_TMPFS:
- return "tmpfs";
- case VFS_PROCFS:
- return "procfs";
- case VFS_EXT2:
- return "ext2";
- default:
- return "unknown";
- }
-}
-
-static void vfs_list_mounts()
-{
- struct node *iterator = mount_points->head;
- while (iterator) {
- struct mount_info *m = iterator->data;
- printf("%s on %s type %s\n", m->dev->name, m->path,
- vfs_resolve_type(m->dev->vfs->type));
- iterator = iterator->next;
- }
-}*/
-
res vfs_mount(struct vfs_dev *dev, const char *path)
{
if (!memory_readable(path))
@@ -223,6 +197,14 @@ res vfs_stat(const char *path, struct stat *buf)
return m->dev->vfs->stat(path, buf, m->dev);
}
+CLEAR void vfs_load(struct vfs_dev *dev)
+{
+ if (!mbr_load(dev)) {
+ assert(ext2_load(dev));
+ // TODO: Add GPT support
+ }
+}
+
CLEAR void vfs_install(void)
{
mount_points = list_new();
@@ -458,7 +440,7 @@ static struct ext2_inode *ext2_find_inode_by_path(const char *path, struct ext2_
return ext2_get_inode(inode, in_buf, dev);
}
-res ext2_read(const char *path, void *buf, u32 offset, u32 count, struct vfs_dev *dev)
+static res ext2_read(const char *path, void *buf, u32 offset, u32 count, struct vfs_dev *dev)
{
struct ext2_inode in = { 0 };
if (ext2_find_inode_by_path(path, &in, dev) == &in) {
@@ -467,7 +449,7 @@ res ext2_read(const char *path, void *buf, u32 offset, u32 count, struct vfs_dev
return -ENOENT;
}
-res ext2_stat(const char *path, struct stat *buf, struct vfs_dev *dev)
+static res ext2_stat(const char *path, struct stat *buf, struct vfs_dev *dev)
{
struct ext2_inode in = { 0 };
if (ext2_find_inode_by_path(path, &in, dev) != &in)
@@ -484,7 +466,7 @@ res ext2_stat(const char *path, struct stat *buf, struct vfs_dev *dev)
return EOK;
}
-res ext2_perm(const char *path, enum vfs_perm perm, struct vfs_dev *dev)
+static res ext2_perm(const char *path, enum vfs_perm perm, struct vfs_dev *dev)
{
struct ext2_inode in = { 0 };
if (ext2_find_inode_by_path(path, &in, dev) != &in)
@@ -501,3 +483,31 @@ res ext2_perm(const char *path, enum vfs_perm perm, struct vfs_dev *dev)
return -EINVAL;
}
}
+
+CLEAR u8 ext2_load(struct vfs_dev *dev)
+{
+ struct ext2_superblock *sb = ext2_buffer_read(EXT2_SUPER, dev);
+ if (sb->magic != EXT2_MAGIC) {
+ free(sb);
+ return 0;
+ }
+
+ struct vfs *vfs = zalloc(sizeof(*vfs));
+ vfs->type = VFS_EXT2;
+ vfs->read = ext2_read;
+ vfs->stat = ext2_stat;
+ vfs->perm = ext2_perm;
+ dev->vfs = vfs;
+
+ // Verify that '/' is unmounted
+ struct mount_info *m = vfs_find_mount_info("/");
+ if (m && m->dev)
+ panic("Found multiple ext2 disks!\n");
+
+ // TODO: Mount other ext2 disks somewhere else
+ printf("Mounting disk %s to '/'\n", dev->name);
+ vfs_mount(dev, "/");
+
+ free(sb);
+ return 1;
+}
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index ffa711b..36ee6b9 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -332,7 +332,7 @@ NORETURN void proc_init(void)
vfs->perm = procfs_perm;
vfs->data = NULL;
struct vfs_dev *dev = zalloc(sizeof(*dev));
- dev->name = "proc";
+ strlcpy(dev->name, "proc", sizeof(dev->name));
dev->type = DEV_CHAR;
dev->vfs = vfs;
vfs_add_dev(dev);