Add readdir() test, devfs
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 5bd8f87..a939238 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -39,6 +39,14 @@
vga_write("Setup complete!\n");
vga_set_color(WHITE, BLACK);
+ kprintf("fs_readdir(\"/\")\n");
+
+ struct fs_dirent dirent;
+ for (int i = 0; fs_readdir(&root, i, &dirent); i++)
+ {
+ kprintf("name: %s, inode: %d\n", dirent.name, dirent.inode);
+ }
+
asm volatile("sti");
while (true)
diff --git a/src/kernel/vfs.c b/src/kernel/vfs.c
index 7b4ff0b..aef955b 100644
--- a/src/kernel/vfs.c
+++ b/src/kernel/vfs.c
@@ -36,25 +36,25 @@
node->vtable->close(node);
}
-uint fs_readdir(struct fs_node *node, uint index, struct fs_dirent *out)
+bool fs_readdir(struct fs_node *node, uint index, struct fs_dirent *out)
{
if (!node || !node->vtable || !node->vtable->readdir ||
(node->flags & 7) != FS_DIRECTORY)
- return 1;
+ return false;
return node->vtable->readdir(node, index, out);
}
-uint fs_finddir(struct fs_node *node, char *name, struct fs_node *out)
+struct fs_node *fs_finddir(struct fs_node *node, char *name)
{
if (!node || !node->vtable || !node->vtable->finddir ||
(node->flags & 7) != FS_DIRECTORY)
- return 1;
+ return NULL;
- return node->vtable->finddir(node, name, out);
+ return node->vtable->finddir(node, name);
}
-uint root_readdir(struct fs_node *node, uint index, struct fs_dirent *out)
+bool root_readdir(struct fs_node *node, uint index, struct fs_dirent *out)
{
if (node == &root && index == 0)
{
@@ -62,48 +62,45 @@
memcpy(out->name, "dev", 4);
out->inode = -1;
- return 0;
+ return true;
}
else
- return 1;
+ return false;
}
-uint root_finddir(struct fs_node *node, char *name, struct fs_node *out)
+struct fs_node *root_finddir(struct fs_node *node, char *name)
{
if (!strcmp(name, "dev"))
{
- *out = dev;
- return 0;
+ return &dev;
}
-
- return 1;
+ else return NULL;
}
-uint dev_readdir(struct fs_node *node, uint index, struct fs_dirent *out)
+bool dev_readdir(struct fs_node *node, uint index, struct fs_dirent *out)
{
if (node == &dev && index == 0)
{
// initrd
memcpy(out->name, "dirent", 7);
out->inode = -1;
- return 0;
+ return true;
}
else
- return 1;
+ return false;
}
-uint dev_finddir(struct fs_node *node, char *name, struct fs_node *out)
+struct fs_node *dev_finddir(struct fs_node *node, char *name)
{
if (node != &dev)
- return 1;
+ return NULL;
if (!strcmp(name, "initrd"))
{
- *out = initrd;
- return 0;
+ return &initrd;
}
- return 1;
+ return NULL;
}
void init_vfs()
@@ -121,6 +118,9 @@
root_v.readdir = root_readdir;
root_v.finddir = root_finddir;
+
+ dev_v.readdir = dev_readdir;
+ dev_v.finddir = dev_finddir;
}
uint fs_mount(struct fs_node *target, struct fs_node *source)
diff --git a/src/kernel/vfs.h b/src/kernel/vfs.h
index 1510566..1da0d6e 100644
--- a/src/kernel/vfs.h
+++ b/src/kernel/vfs.h
@@ -31,8 +31,8 @@
typedef void (* fs_open_t)(struct fs_node *node);
typedef void (* fs_close_t)(struct fs_node *node);
-typedef uint (* fs_readdir_t)(struct fs_node *node, uint index, struct fs_dirent *dirent);
-typedef uint (* fs_finddir_t)(struct fs_node *node, char *name, struct fs_node *out);
+typedef bool (* fs_readdir_t)(struct fs_node *node, uint index, struct fs_dirent *dirent);
+typedef struct fs_node *(* fs_finddir_t)(struct fs_node *node, char *name);
struct fs_vtable
{
@@ -67,12 +67,8 @@
void fs_open(struct fs_node *node);
void fs_close(struct fs_node *node);
-/* For all of the functions that return integers;
- * 0 = okay
- * non-zero = error */
-
-uint fs_readdir(struct fs_node *node, uint index, struct fs_dirent *out);
-uint fs_finddir(struct fs_node *node, char *name, struct fs_node *out);
+bool fs_readdir(struct fs_node *node, uint index, struct fs_dirent *out);
+struct fs_node *fs_finddir(struct fs_node *node, char *name);
/* Returns the following error codes:
* 0: success
diff --git a/src/kernel/vfs_initrd.c b/src/kernel/vfs_initrd.c
index 6bbfd3f..0ec48a0 100644
--- a/src/kernel/vfs_initrd.c
+++ b/src/kernel/vfs_initrd.c
@@ -1,4 +1,14 @@
#include <initrd/initrd.h>
#include "kint.h"
#include "vfs.h"
+#include "io.h"
+struct fs_node real_initrd;
+struct fs_node *initrd_content = NULL;
+
+void init_initrd_vfs()
+{
+ memset(&real_initrd, 0, sizeof(real_initrd));
+
+ real_initrd.flags = FS_DIRECTORY;
+}