aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2020-12-10 22:41:08 +0100
committerMarvin Borner2020-12-10 22:41:08 +0100
commite15742fac894e2d5be3d0d44411a5cd24f794e18 (patch)
treebbd5ca4ec43274f658d1c97feb4fca31b2aeeb75 /kernel
parent8587e297ab7aa5b43a913f0e20cfe5edee18f075 (diff)
Started VFS
I have plans to remove the whole event system and make everything a file - just like Unix does. It's way easier that way actually.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/features/fs.c40
-rw-r--r--kernel/inc/fs.h30
2 files changed, 68 insertions, 2 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index 480f199..00aa152 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -1,5 +1,4 @@
// MIT License, Copyright (c) 2020 Marvin Borner
-// EXT2 based filesystem
#include <assert.h>
#include <def.h>
@@ -9,6 +8,10 @@
#include <print.h>
#include <str.h>
+/**
+ * EXT2
+ */
+
void *buffer_read(u32 block)
{
return ide_read(malloc(BLOCK_SIZE), block);
@@ -180,3 +183,38 @@ u32 file_stat(char *path)
return in->size;
}
+
+/**
+ * VFS
+ */
+
+static struct list *mount_points = NULL;
+
+struct device *vfs_mounted(const char *path)
+{
+ struct node *iterator = mount_points->head;
+ while (iterator) {
+ if (!strcmp(iterator->data, path))
+ return iterator->data;
+ iterator = iterator->next;
+ }
+ return NULL;
+}
+
+u32 vfs_mount(struct device *dev, const char *path)
+{
+ if (!dev || !dev->id || vfs_mounted(path))
+ return 0;
+
+ struct mount_info *m = malloc(sizeof(*m));
+ m->path = strdup(path);
+ m->dev = dev;
+ list_add(mount_points, m);
+
+ return 1;
+}
+
+void vfs_install()
+{
+ mount_points = list_new();
+}
diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h
index 156bb8c..7336a72 100644
--- a/kernel/inc/fs.h
+++ b/kernel/inc/fs.h
@@ -1,11 +1,14 @@
// MIT License, Copyright (c) 2020 Marvin Borner
-// EXT2 based filesystem
#ifndef FS_H
#define FS_H
#include <def.h>
+/**
+ * EXT2
+ */
+
#define EXT2_BOOT 0
#define EXT2_SUPER 1
#define EXT2_ROOT 2
@@ -96,4 +99,29 @@ struct file {
void *file_read(char *path);
u32 file_stat(char *path);
+/**
+ * VFS
+ */
+
+struct device {
+ u32 id;
+ const char *name;
+ int type; // TODO: Block, char device
+ struct vfs *vfs;
+ u8 (*read)(u8 *buf, u32 offset, u32 count, struct device *dev);
+ u8 (*write)(u8 *buf, u32 offset, u32 count, struct device *dev);
+};
+
+struct vfs {
+ const char *name;
+ u8 (*probe)(struct device *);
+ u8 (*read)(char *, char *, struct device *, void *);
+ u8 (*mount)(struct device *, void *);
+};
+
+struct mount_info {
+ const char *path;
+ struct device *dev;
+};
+
#endif