aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/fs
diff options
context:
space:
mode:
authorMarvin Borner2020-05-04 21:52:22 +0200
committerMarvin Borner2020-05-04 21:52:22 +0200
commit2832a529b7f16799db801823fee0ebfd2aa77168 (patch)
tree66c9917682ee774a01a82ae1e32c285c6a49dc50 /src/kernel/fs
parent2ac25568839df7af2e271db9efa84bbd6fcb1f88 (diff)
Work on ext2 vfs indexer
Diffstat (limited to 'src/kernel/fs')
-rw-r--r--src/kernel/fs/ext2.c48
-rw-r--r--src/kernel/fs/vfs.c4
2 files changed, 19 insertions, 33 deletions
diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c
index 77010bb..ceeff6e 100644
--- a/src/kernel/fs/ext2.c
+++ b/src/kernel/fs/ext2.c
@@ -238,18 +238,10 @@ uint32_t ext2_look_up_path(char *path)
return inode;
}
-struct fs_node *ext2_index(char *dir)
+struct fs_node *ext2_index(struct fs_node *start)
{
log("\n\n");
- struct fs_node *start = (struct fs_node *)kmalloc(sizeof(struct fs_node));
- ext2_node_init(start);
- strcpy(start->name, dir);
- start->inode = ext2_look_up_path(dir);
- start->type = DIR_NODE;
fs_open(start);
- log("%d", start->inode);
- struct fs_node *parent = start;
-
struct dirent *dirent;
int i = 0;
while ((dirent = fs_read_dir(start, i)) != NULL) {
@@ -257,46 +249,39 @@ struct fs_node *ext2_index(char *dir)
if (dirent->name[0] == '.')
continue;
- char *name = dir;
+ char name[256];
+ strcpy(name, start->name);
strcat(name, "/");
strcat(name, dirent->name);
- log(name);
+ log("%s", start->name);
+ log("%s", dirent->name);
+ log("%s", name);
struct fs_node *sub = fs_find_dir(start, dirent->name);
ext2_node_init(sub);
- strcpy(sub->name, name);
- fs_open(sub);
+ strcpy(sub->name, dirent->name);
+ //fs_open(sub);
+ log("%d", sub->inode);
if (sub->type == DIR_NODE) {
- sub = ext2_index(name);
+ debug("Directory %s", name);
} else if (sub->type == FILE_NODE) {
- sub = (struct fs_node *)kmalloc(sizeof(struct fs_node));
- ext2_node_init(sub);
- strcpy(sub->name, name);
- sub->inode = ext2_look_up_path(name);
+ debug("File %s", name);
} else if (sub->type == (enum node_type)NULL) {
- warn("No node type!");
- } else {
- warn("Unsupported node type!");
- }
-
- if (parent->node_ptr == NULL) {
- parent->node_ptr = sub;
- start = sub;
+ warn("No file type %s", name);
} else {
- start->link = sub;
- start = sub;
+ warn("Unsupported file type!");
}
}
- return parent;
+ return start;
}
// Interface
uint8_t *read_file(char *path)
{
- ext2_index("/.");
+ ext2_index(fs_root);
halt_loop();
uint32_t inode = ext2_look_up_path(path);
struct ext2_file file;
@@ -376,9 +361,10 @@ 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) {
+ warn("Couldn't find file");
return NULL;
} else {
- struct fs_node *found = kmalloc(sizeof *found);
+ struct fs_node *found = kmalloc(sizeof(struct fs_node));
found->inode = inode;
return found;
diff --git a/src/kernel/fs/vfs.c b/src/kernel/fs/vfs.c
index 6d29eed..0098d3b 100644
--- a/src/kernel/fs/vfs.c
+++ b/src/kernel/fs/vfs.c
@@ -6,6 +6,7 @@
#include <kernel/memory/alloc.h>
#include <kernel/system.h>
+struct tree *fs_tree;
struct fs_node *fs_root = NULL;
uint32_t fs_read(struct fs_node *node, uint32_t offset, uint32_t size, char *buf)
@@ -154,8 +155,7 @@ struct fs_node *vfs_get_dir(struct fs_node *node, char *name)
char *basename(char *name)
{
- int i;
- for (i = strlen(name); i >= 0; i--)
+ for (int i = strlen(name); i >= 0; i--)
if (name[i] == '/')
return &name[i + 1];