diff options
author | Marvin Borner | 2020-12-11 20:22:15 +0100 |
---|---|---|
committer | Marvin Borner | 2020-12-11 20:22:15 +0100 |
commit | d4c618d81316614942a8248f34e18d105ea31201 (patch) | |
tree | ad606d663c4e4a4c70a44525c6b2c609c4e4aa68 /kernel/features | |
parent | e15742fac894e2d5be3d0d44411a5cd24f794e18 (diff) |
Some FS stuff
Diffstat (limited to 'kernel/features')
-rw-r--r-- | kernel/features/fs.c | 107 |
1 files changed, 72 insertions, 35 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c index 00aa152..63a1f70 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -6,9 +6,81 @@ #include <ide.h> #include <mem.h> #include <print.h> +#include <random.h> #include <str.h> /** + * 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(); +} + +/** + * Device + */ + +static struct list *devices = NULL; + +void device_add(struct device *dev) +{ + dev->id = rand(); + list_add(devices, dev); +} + +struct device *device_get(u32 id) +{ + struct node *iterator = devices->head; + while (iterator) { + if (((struct device *)iterator->data)->id == id) + return iterator->data; + iterator = iterator->next; + } + return NULL; +} + +void device_install() +{ + devices = list_new(); + + struct vfs *vfs = malloc(sizeof(*vfs)); + vfs->name = strdup("devfs"); + struct device *dev = malloc(sizeof(*dev)); + dev->name = "dev"; + dev->vfs = vfs; + device_add(dev); + vfs_mount(dev, "/dev/"); +} + +/** * EXT2 */ @@ -183,38 +255,3 @@ 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(); -} |