diff options
author | Marvin Borner | 2020-05-01 14:10:57 +0200 |
---|---|---|
committer | Marvin Borner | 2020-05-01 14:10:57 +0200 |
commit | f0439a5dbfe2cfed3d629027d4b54b5f77f4e6de (patch) | |
tree | 6f5897314c3fe545e0fbe98dab85d24d245e2ccd /src | |
parent | 6b48e277cd249d0b5f7b5c7032457bb60dda46d6 (diff) |
Working vfs mount and read
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/fs/ext2.c | 31 | ||||
-rw-r--r-- | src/kernel/fs/ext2.h | 2 | ||||
-rw-r--r-- | src/kernel/kernel.c | 11 |
3 files changed, 19 insertions, 25 deletions
diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c index dcac20d..91e90fb 100644 --- a/src/kernel/fs/ext2.c +++ b/src/kernel/fs/ext2.c @@ -30,38 +30,21 @@ void ext2_init_fs() debug("Type & perms: 0x%x", root_inode.type_and_permissions); debug("Size: %d", root_inode.size); - /* debug("Files:"); */ - - /* struct ext2_file file; */ - /* ext2_open_inode(ROOT_INODE, &file); */ - /* struct ext2_dirent dirent; */ - - /* while (ext2_next_dirent(&file, &dirent)) */ - /* debug("Inode %d, name '%s'", dirent.inode_num, dirent.name); */ - - /* kfree(file.buf); */ - fs_root = (struct fs_node *)kmalloc(sizeof(struct fs_node)); - strcpy(fs_root->name, "/"); + strcpy(fs_root->name, "root"); fs_root->type = DIR_NODE; ext2_mount(fs_root); - // TODO: Fix file tree - struct fs_node *root = fs_root->node_ptr; - root->open(root); + log("Files in /"); + ext2_root = fs_root->node_ptr; + fs_open(ext2_root); struct dirent *dirent; int i = 0; - int count = 0; - while ((dirent = fs_read_dir(root, i)) != NULL) { - struct fs_node *node = fs_find_dir(root, dirent->name); + while ((dirent = fs_read_dir(ext2_root, i)) != NULL) { log("%s", dirent->name); - - if (node->type == FILE_NODE) - count++; - i++; } - log("%d", count); + /* fs_close(ext2_root); */ } static void read_block(uint32_t block_num, void *buf) @@ -347,7 +330,7 @@ void ext2_mount(struct fs_node *mountpoint) assert((mountpoint->type & DIR_NODE) != 0); struct fs_node *ext2_root = (struct fs_node *)kmalloc(sizeof(struct fs_node)); - ext2_root->name[0] = '\0'; + strcpy(ext2_root->name, "/."); ext2_root->permissions = 0; ext2_root->uid = 0; ext2_root->gid = 0; diff --git a/src/kernel/fs/ext2.h b/src/kernel/fs/ext2.h index 8747c19..1e89c27 100644 --- a/src/kernel/fs/ext2.h +++ b/src/kernel/fs/ext2.h @@ -115,6 +115,8 @@ struct ext2_inode { #define DUMP_IGNORE 0x00040 #define NO_UPDATE_ACCESS 0x00080 +struct fs_node *ext2_root; + struct ext2_dirent { uint32_t inode_num; uint16_t total_len; diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index fb1a37e..08018c2 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -66,7 +66,16 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address, uint32_t esp) load_binaries(); set_optimal_resolution(); - log("Content of /etc/test: %s", read_file("/etc/test")); + + struct fs_node *test = (struct fs_node *)kmalloc(sizeof(struct fs_node)); + strcpy(test->name, "/etc/test"); + ext2_root->open(test); + uint32_t size = ((struct ext2_file *)test->impl)->inode.size; + char buf[size]; + ext2_root->read(test, 0, size, buf); + buf[size - 1] = '\0'; + log("Content of /etc/test: %s", buf); + ext2_root->close(test); syscalls_install(); kexec("/bin/init"); |