aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/fs')
-rw-r--r--src/kernel/fs/dev.c12
-rw-r--r--src/kernel/fs/ext2.c37
-rw-r--r--src/kernel/fs/ext2.h1
-rw-r--r--src/kernel/fs/vfs.c5
4 files changed, 32 insertions, 23 deletions
diff --git a/src/kernel/fs/dev.c b/src/kernel/fs/dev.c
index 968dcfe..52d8e01 100644
--- a/src/kernel/fs/dev.c
+++ b/src/kernel/fs/dev.c
@@ -12,14 +12,14 @@ void dev_make(char *name, read read, write write)
{
struct fs_node *dev_node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(dev_node->name, "/dev");
- ext2_root->open(dev_node);
+ fs_open(dev_node);
if (dev_node->inode == 0) {
warn("Can't make device, no path for /dev");
return;
}
- ext2_root->close(dev_node);
+ fs_close(dev_node);
char *path = (char *)kmalloc(strlen(name) + strlen("/dev/") + 2);
strcpy(path, "/dev/");
@@ -28,7 +28,7 @@ void dev_make(char *name, read read, write write)
// TODO: Touch dev files in the vfs instead of opening it via ext2
struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(node->name, path);
- ext2_root->open(node);
+ fs_open(node);
kfree(path);
if (node->inode == 0) {
@@ -78,7 +78,7 @@ void dev_stdin()
dev_make("stdout", (read)stdin_read, NULL);
struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(node->name, "/dev/stdin");
- ext2_root->open(node);
+ fs_open(node);
node->dev->block_size = 0;
node->length = 0xFFFFFFFF;
}
@@ -94,7 +94,7 @@ void dev_stdout()
dev_make("stdout", NULL, (write)stdout_write);
struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(node->name, "/dev/stdout");
- ext2_root->open(node);
+ fs_open(node);
node->dev->block_size = 0;
}
@@ -109,6 +109,6 @@ void dev_stderr()
dev_make("stderr", NULL, (write)stderr_write);
struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(node->name, "/dev/stderr");
- ext2_root->open(node);
+ fs_open(node);
node->dev->block_size = 0;
} \ No newline at end of file
diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c
index 91e90fb..3956fd4 100644
--- a/src/kernel/fs/ext2.c
+++ b/src/kernel/fs/ext2.c
@@ -265,11 +265,9 @@ void ext2_vfs_open(struct fs_node *node)
if (node->inode != 0) {
struct ext2_file *file = kmalloc(sizeof *file);
+ ext2_node_init(node);
ext2_open_inode(node->inode, file);
-
node->impl = file;
-
- // TODO: More file metadata
}
}
@@ -281,7 +279,7 @@ void ext2_vfs_close(struct fs_node *node)
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\n");
+ panic("Seeking is currently unsupported for Ext2 files");
return 0;
}
@@ -290,7 +288,7 @@ uint32_t ext2_vfs_read(struct fs_node *node, size_t offset, size_t size, char *b
uint32_t ext2_vfs_write(struct fs_node *node, size_t offset, size_t size, char *buf)
{
- panic("Writing to Ext2 is currently unsupported\n");
+ warn(RED "Writing to Ext2 is currently unsupported" RES);
return 0;
}
@@ -324,6 +322,22 @@ struct fs_node *ext2_vfs_find_dir(struct fs_node *node, char *name)
}
}
+void ext2_node_init(struct fs_node *node)
+{
+ node->permissions = 0;
+ node->uid = 0;
+ node->gid = 0;
+ node->length = 0;
+ node->read = ext2_vfs_read;
+ node->write = ext2_vfs_write;
+ node->open = ext2_vfs_open;
+ node->close = ext2_vfs_close;
+ node->read_dir = ext2_vfs_read_dir;
+ node->find_dir = ext2_vfs_find_dir;
+ node->node_ptr = NULL;
+ node->impl = NULL;
+}
+
void ext2_mount(struct fs_node *mountpoint)
{
assert(mountpoint->node_ptr == NULL && (mountpoint->type & MOUNTPOINT_NODE) == 0);
@@ -331,20 +345,9 @@ void ext2_mount(struct fs_node *mountpoint)
struct fs_node *ext2_root = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(ext2_root->name, "/.");
- 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;
+ ext2_node_init(ext2_root);
mountpoint->type |= MOUNTPOINT_NODE;
mountpoint->node_ptr = ext2_root;
diff --git a/src/kernel/fs/ext2.h b/src/kernel/fs/ext2.h
index 1e89c27..f98531e 100644
--- a/src/kernel/fs/ext2.h
+++ b/src/kernel/fs/ext2.h
@@ -141,6 +141,7 @@ uint32_t ext2_find_in_dir(uint32_t dir_inode, const char *name);
uint32_t ext2_look_up_path(char *path);
uint8_t *read_file(char *path);
+void ext2_node_init(struct fs_node *node);
void ext2_mount(struct fs_node *mountpoint);
#endif \ No newline at end of file
diff --git a/src/kernel/fs/vfs.c b/src/kernel/fs/vfs.c
index fd44f30..2b4cda4 100644
--- a/src/kernel/fs/vfs.c
+++ b/src/kernel/fs/vfs.c
@@ -1,6 +1,7 @@
#include <stdint.h>
#include <stddef.h>
#include <kernel/fs/vfs.h>
+#include <kernel/fs/ext2.h>
#include <kernel/lib/stdlib.h>
struct fs_node *fs_root = NULL;
@@ -25,12 +26,16 @@ void fs_open(struct fs_node *node)
{
if (node->open != NULL)
node->open(node);
+ else // TODO: Better ext2 default open workaround
+ ext2_root->open(node);
}
void fs_close(struct fs_node *node)
{
if (node->close != NULL)
node->close(node);
+ else
+ ext2_root->open(node);
}
struct dirent *fs_read_dir(struct fs_node *node, uint32_t index)