aboutsummaryrefslogtreecommitdiff
path: root/src/kernel
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
parent2ac25568839df7af2e271db9efa84bbd6fcb1f88 (diff)
Work on ext2 vfs indexer
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/fs/ext2.c48
-rw-r--r--src/kernel/fs/vfs.c4
-rw-r--r--src/kernel/lib/data.h2
-rw-r--r--src/kernel/lib/data/list.c3
-rw-r--r--src/kernel/lib/data/tree.c2
5 files changed, 22 insertions, 37 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];
diff --git a/src/kernel/lib/data.h b/src/kernel/lib/data.h
index 356b978..d0eaaf5 100644
--- a/src/kernel/lib/data.h
+++ b/src/kernel/lib/data.h
@@ -91,4 +91,4 @@ void tree2array(struct tree *tree, void **array, int *size);
void tree2array_recur(struct tree_node *subroot, void **array, int *size);
-#endif
+#endif \ No newline at end of file
diff --git a/src/kernel/lib/data/list.c b/src/kernel/lib/data/list.c
index 3346e32..788b4ab 100644
--- a/src/kernel/lib/data/list.c
+++ b/src/kernel/lib/data/list.c
@@ -132,7 +132,6 @@ void *list_peek_back(struct list *list)
return list->tail->val;
}
-
int list_contain(struct list *list, void *val)
{
int idx = 0;
@@ -222,4 +221,4 @@ char *list_to_str(struct list *list, const char *delim)
strcat(ret, temp);
}
return ret;
-}
+} \ No newline at end of file
diff --git a/src/kernel/lib/data/tree.c b/src/kernel/lib/data/tree.c
index 53233a4..514e2cd 100644
--- a/src/kernel/lib/data/tree.c
+++ b/src/kernel/lib/data/tree.c
@@ -100,4 +100,4 @@ void tree2array_recur(struct tree_node *subroot, void **array, int *size)
{
tree2array_recur(child->val, array, size);
}
-}
+} \ No newline at end of file