diff options
author | Marvin Borner | 2020-04-24 20:44:36 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-24 20:44:36 +0200 |
commit | 24175ce2a37d6f5d9ba367f942fabce681ee9e4a (patch) | |
tree | 829c4f13f8283298207b86b6a339763a10d3c521 | |
parent | cd1d0115f0b873e155a2435f932f3f2865d72ce9 (diff) |
Removed vfs again...
-rwxr-xr-x | run | 2 | ||||
-rw-r--r-- | src/kernel/fs/ext2.c | 94 | ||||
-rw-r--r-- | src/kernel/fs/ext2.h | 5 | ||||
-rw-r--r-- | src/kernel/fs/vfs.c | 48 | ||||
-rw-r--r-- | src/kernel/fs/vfs.h | 66 | ||||
-rw-r--r-- | src/kernel/kernel.c | 3 |
6 files changed, 3 insertions, 215 deletions
@@ -70,7 +70,7 @@ make_build() { cd .. # Create disk image - mke2fs -b 1024 -N 1024 ./build/disk.img 65536 || exit 1 + mke2fs -b 4096 -N 4096 ./build/disk.img 65536 || exit 1 mkdir ./mnt/ || exit 1 sudo mount ./build/disk.img ./mnt/ || exit 1 sudo mkdir -p ./mnt/abc/def/ diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c index a61b9e6..3ab2f89 100644 --- a/src/kernel/fs/ext2.c +++ b/src/kernel/fs/ext2.c @@ -7,7 +7,6 @@ #include <kernel/memory/alloc.h> #include <kernel/lib/lib.h> #include <kernel/lib/stdlib.h> -#include <kernel/fs/vfs.h> static struct ext2_superblock superblock; static struct bgd *bgdt; @@ -233,96 +232,3 @@ uint32_t ext2_look_up_path(char *path) return inode; } - -// VFS Implementation - -void ext2_vfs_open(struct fs_node *node) -{ - node->inode = ext2_look_up_path(node->name); - - if (node->inode != 0) { - struct ext2_file *file = kmalloc(sizeof *file); - ext2_open_inode(node->inode, file); - - node->impl = file; - - // TODO: More file metadata - } -} - -static void ext2_vfs_close(struct fs_node *node) -{ - kfree(node->impl); -} - -static uint32_t ext2_vfs_read(struct fs_node *node, size_t offset, size_t size, char *buf) -{ - if (offset != ((struct ext2_file *)node->impl)->pos) { - panic("Seeking is currently unsupported for Ext2 files"); - return 0; - } - - return (uint32_t)ext2_read(node->impl, (uint8_t *)buf, size); -} - -static uint32_t ext2_vfs_write(struct fs_node *node, size_t offset, size_t size, char *buf) -{ - panic("Writing to Ext2 is currently unsupported"); - - return 0; -} - -static struct dir_entry *ext2_vfs_read_dir(struct fs_node *node, size_t index) -{ - struct ext2_dirent ext2_dir; - - if (ext2_next_dirent(node->impl, &ext2_dir)) { - struct dir_entry *dir = kmalloc(sizeof *dir); - - dir->inode = ext2_dir.inode_num; - strcpy(dir->name, (char *)ext2_dir.name); - - return dir; - } else { - return NULL; - } -} - -static struct fs_node *ext2_vfs_find_dir(struct fs_node *node, char *name) -{ - uint32_t inode = ext2_find_in_dir(node->inode, name); - if (inode == 0) { - return NULL; - } else { - struct fs_node *found = kmalloc(sizeof *found); - found->inode = inode; - - return found; - } -} - -void ext2_mount(struct fs_node *mountpoint) -{ - assert(mountpoint->node_ptr == NULL && (mountpoint->type & MOUNTPOINT_NODE) == 0); - assert((mountpoint->type & DIR_NODE) != 0); - - struct fs_node *ext2_root = (struct fs_node *)kmalloc(sizeof(struct fs_node)); - ext2_root->name[0] = '\0'; - ext2_root->permissions = 0; - ext2_root->uid = 0; - ext2_root->gid = 0; - ext2_root->inode = ROOT_INODE; - ext2_root->length = 0; - ext2_root->type = DIR_NODE; - ext2_root->read = ext2_vfs_read; - ext2_root->write = ext2_vfs_write; - ext2_root->open = ext2_vfs_open; - ext2_root->close = ext2_vfs_close; - ext2_root->read_dir = ext2_vfs_read_dir; - ext2_root->find_dir = ext2_vfs_find_dir; - ext2_root->node_ptr = NULL; - ext2_root->impl = NULL; - - mountpoint->type |= MOUNTPOINT_NODE; - mountpoint->node_ptr = ext2_root; -}
\ No newline at end of file diff --git a/src/kernel/fs/ext2.h b/src/kernel/fs/ext2.h index 065b04b..f9c977c 100644 --- a/src/kernel/fs/ext2.h +++ b/src/kernel/fs/ext2.h @@ -4,7 +4,6 @@ #include <stdint.h> #include <stddef.h> #include <stdbool.h> -#include <kernel/fs/vfs.h> #define ROOT_INODE 2 @@ -138,6 +137,4 @@ 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); -void ext2_mount(struct fs_node *mountpoint); - -#endif
\ No newline at end of file +#endif diff --git a/src/kernel/fs/vfs.c b/src/kernel/fs/vfs.c deleted file mode 100644 index 6471f1b..0000000 --- a/src/kernel/fs/vfs.c +++ /dev/null @@ -1,48 +0,0 @@ -#include <stddef.h> -#include <kernel/fs/vfs.h> - -struct fs_node *fs_root = NULL; - -uint32_t read_fs_node(struct fs_node *node, size_t offset, size_t size, char *buf) -{ - if (node->read != NULL) - return node->read(node, offset, size, buf); - else - return 0; -} - -uint32_t write_fs_node(struct fs_node *node, size_t offset, size_t size, char *buf) -{ - if (node->write != NULL) - return node->write(node, offset, size, buf); - else - return 0; -} - -void open_fs_node(struct fs_node *node, bool read, bool write) -{ - if (node->open != NULL) - node->open(node); -} - -void close_fs_node(struct fs_node *node) -{ - if (node->close != NULL) - node->close(node); -} - -struct dir_entry *read_dir_node(struct fs_node *node, size_t index) -{ - if ((node->type & DIR_NODE) != 0 && node->read_dir != NULL) - return node->read_dir(node, index); - else - return NULL; -} - -struct fs_node *find_dir_node(struct fs_node *node, char *name) -{ - if ((node->type & DIR_NODE) != 0 && node->find_dir != NULL) - return node->find_dir(node, name); - else - return NULL; -}
\ No newline at end of file diff --git a/src/kernel/fs/vfs.h b/src/kernel/fs/vfs.h deleted file mode 100644 index 3582a11..0000000 --- a/src/kernel/fs/vfs.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef MELVIX_VFS_H -#define MELVIX_VFS_H - -#include <stdbool.h> -#include <stddef.h> -#include <stdint.h> - -#define MAX_NAME_LENGTH 128 - -enum node_type { - FILE_NODE = 1, - DIR_NODE, - CHAR_DEV_NODE, - BLOCK_DEV_NODE, - PIPE_NODE, - SYMLINK_NODE, - MOUNTPOINT_NODE = 8 -}; - -struct fs_node; -struct dir_entry; - -typedef uint32_t (*read)(struct fs_node *, size_t, size_t, char *); -typedef uint32_t (*write)(struct fs_node *, size_t, size_t, char *); -typedef void (*open)(struct fs_node *); -typedef void (*close)(struct fs_node *); - -typedef struct dir_entry *(*read_dir)(struct fs_node *, size_t); -typedef struct fs_node *(*find_dir)(struct fs_node *, char *); - -struct fs_node { - char name[MAX_NAME_LENGTH]; - uint32_t length; - uint32_t inode; - uint32_t permissions; - uint32_t uid; - uint32_t gid; - enum node_type type; - - struct fs_node *node_ptr; - - void *impl; - - read read; - write write; - open open; - close close; - read_dir read_dir; - find_dir find_dir; -}; - -struct dir_entry { - char name[MAX_NAME_LENGTH]; - uint32_t inode; -}; - -struct fs_node *fs_root; - -uint32_t read_fs_node(struct fs_node *node, size_t offset, size_t size, char *buf); -uint32_t write_fs_node(struct fs_node *node, size_t offset, size_t size, char *buf); -void open_fs_node(struct fs_node *node, bool read, bool write); -void close_fs_node(struct fs_node *node); -struct dir_entry *read_dir_node(struct fs_node *node, size_t index); -struct fs_node *find_dir_node(struct fs_node *node, char *name); - -#endif
\ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 3847627..d4c7b93 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -58,7 +58,6 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address) ata_init(); ext2_init_fs(); - ext2_mount(fs_root); load_binaries(); set_optimal_resolution(); @@ -77,4 +76,4 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address) // panic("This should NOT happen!"); // asm ("div %0" :: "r"(0)); // Exception testing x/0 -}
\ No newline at end of file +} |