aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/fs/dev.c110
-rw-r--r--src/kernel/fs/dev.h25
-rw-r--r--src/kernel/fs/ext2.c187
-rw-r--r--src/kernel/fs/ext2.h1
-rw-r--r--src/kernel/fs/fs.c61
-rw-r--r--src/kernel/fs/fs.h11
-rw-r--r--src/kernel/fs/vfs.c204
-rw-r--r--src/kernel/fs/vfs.h71
-rw-r--r--src/kernel/graphics/vesa.c3
-rw-r--r--src/kernel/kernel.c17
-rw-r--r--src/kernel/syscall/actions/sys_read.c21
-rw-r--r--src/kernel/syscall/actions/sys_write.c22
-rw-r--r--src/kernel/syscall/syscall.h4
-rw-r--r--src/userspace/libc/syscall.c4
-rw-r--r--src/userspace/libc/syscall.h4
-rw-r--r--src/userspace/programs/sh.c1
16 files changed, 93 insertions, 653 deletions
diff --git a/src/kernel/fs/dev.c b/src/kernel/fs/dev.c
deleted file mode 100644
index b0e7619..0000000
--- a/src/kernel/fs/dev.c
+++ /dev/null
@@ -1,110 +0,0 @@
-#include <stdint.h>
-#include <stddef.h>
-#include <kernel/system.h>
-#include <kernel/fs/dev.h>
-#include <kernel/fs/vfs.h>
-#include <kernel/fs/ext2.h>
-#include <kernel/memory/alloc.h>
-#include <kernel/lib/stdlib.h>
-#include <kernel/lib/stdio.h>
-
-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");
- fs_open(dev_node);
-
- if (dev_node->inode == 0) {
- warn("Can't make device, no path for /dev");
- return;
- }
-
- fs_close(dev_node);
-
- char *path = (char *)kmalloc(strlen(name) + strlen("/dev/") + 2);
- strcpy(path, "/dev/");
- strcpy(&path[strlen("/dev/")], name);
-
- struct fs_node *node = vfs_touch(fs_root, path);
-
- if (node->inode == 0) {
- warn("Couldn't resolve path");
- return;
- }
-
- node->read = read;
- node->write = write;
-
- node->dev = (struct dev *)kmalloc(sizeof(struct dev));
- node->dev->read = read;
- node->dev->write = write;
- node->dev->block_size = 512;
-}
-
-uint32_t dev_read(struct fs_node *dev, uint32_t offset, uint32_t size, char *buffer)
-{
- if (dev->read == NULL) {
- warn("Can't read from device");
- return (uint32_t)-1;
- }
-
- return dev->read(dev, offset, size, buffer);
-}
-
-uint32_t dev_write(struct fs_node *dev, uint32_t offset, uint32_t size, char *buffer)
-{
- if (dev->write == NULL) {
- warn("Can't write to device");
- return (uint32_t)-1;
- }
-
- return dev->write(dev, offset, size, buffer);
-}
-
-// Standard devices
-
-uint32_t stdin_read(struct fs_node *node, uint32_t offset, uint32_t size, uint8_t *buffer)
-{
- // Do something
- return 0;
-}
-
-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");
- fs_open(node);
- node->dev->block_size = 0;
- node->length = 0xFFFFFFFF;
-}
-
-uint32_t stdout_write(struct fs_node *node, uint32_t offset, uint32_t size, uint8_t *buffer)
-{
- //putch(*buffer);
- return 0;
-}
-
-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");
- fs_open(node);
- node->dev->block_size = 0;
-}
-
-uint32_t stderr_write(struct fs_node *node, uint32_t offset, uint32_t size, uint8_t *buffer)
-{
- //putch(*buffer);
- return 0;
-}
-
-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");
- fs_open(node);
- node->dev->block_size = 0;
-} \ No newline at end of file
diff --git a/src/kernel/fs/dev.h b/src/kernel/fs/dev.h
deleted file mode 100644
index 40263e6..0000000
--- a/src/kernel/fs/dev.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef MELVIX_DEV_H
-#define MELVIX_DEV_H
-
-#include <stdint.h>
-#include <kernel/fs/vfs.h>
-
-struct dev {
- char name[128];
- uint32_t block_size;
- read read;
- write write;
-
- uint8_t bus;
- uint8_t drive;
-};
-
-void dev_make(char *name, read read, write write);
-uint32_t dev_read(struct fs_node *dev, uint32_t offset, uint32_t size, char *buffer);
-uint32_t dev_write(struct fs_node *dev, uint32_t offset, uint32_t size, char *buffer);
-
-void dev_stdout();
-void dev_stdin();
-void dev_stderr();
-
-#endif \ No newline at end of file
diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c
index ceeff6e..b4f81a8 100644
--- a/src/kernel/fs/ext2.c
+++ b/src/kernel/fs/ext2.c
@@ -3,7 +3,6 @@
#include <stdbool.h>
#include <kernel/fs/ata.h>
#include <kernel/fs/ext2.h>
-#include <kernel/fs/vfs.h>
#include <kernel/system.h>
#include <kernel/memory/alloc.h>
#include <kernel/lib/lib.h>
@@ -30,21 +29,13 @@ void ext2_init_fs()
debug("Type & perms: 0x%x", root_inode.mode);
debug("Size: %d", root_inode.size);
- fs_root = (struct fs_node *)kmalloc(sizeof(struct fs_node));
- strcpy(fs_root->name, "root");
- fs_root->type = DIR_NODE;
- ext2_mount(fs_root);
- fs_root = fs_root->node_ptr; // why not? :)
-
- log("Files in /");
- fs_open(fs_root);
- struct dirent *dirent;
- int i = 0;
- while ((dirent = fs_read_dir(fs_root, i)) != NULL) {
- log("%s", dirent->name);
- i++;
- }
- /* fs_close(fs_root); */
+ 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);
}
static void read_block(uint32_t block_num, void *buf)
@@ -236,168 +227,4 @@ uint32_t ext2_look_up_path(char *path)
return 0;
return inode;
-}
-
-struct fs_node *ext2_index(struct fs_node *start)
-{
- log("\n\n");
- fs_open(start);
- struct dirent *dirent;
- int i = 0;
- while ((dirent = fs_read_dir(start, i)) != NULL) {
- i++;
- if (dirent->name[0] == '.')
- continue;
-
- char name[256];
- strcpy(name, start->name);
- strcat(name, "/");
- strcat(name, dirent->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, dirent->name);
- //fs_open(sub);
- log("%d", sub->inode);
-
- if (sub->type == DIR_NODE) {
- debug("Directory %s", name);
- } else if (sub->type == FILE_NODE) {
- debug("File %s", name);
- } else if (sub->type == (enum node_type)NULL) {
- warn("No file type %s", name);
- } else {
- warn("Unsupported file type!");
- }
- }
-
- return start;
-}
-
-// Interface
-
-uint8_t *read_file(char *path)
-{
- ext2_index(fs_root);
- halt_loop();
- uint32_t inode = ext2_look_up_path(path);
- struct ext2_file file;
- ext2_open_inode(inode, &file);
- if (inode != 0) {
- size_t size = file.inode.size;
- debug("Reading %s: %dKiB", path, size >> 10);
- uint8_t *buf = kmalloc(size);
- ext2_read(&file, buf, size);
- kfree(file.buf);
- buf[size - 1] = '\0';
- return buf;
- } else {
- warn("File not found");
- return NULL;
- }
-}
-
-void ext2_vfs_open(struct fs_node *node)
-{
- node->inode = ext2_look_up_path(node->name);
-
- if (node->inode != 0) {
- struct ext2_file *file = kmalloc(sizeof *file);
- ext2_node_init(node);
- ext2_open_inode(node->inode, file);
- node->impl = file;
-
- if (S_ISDIR(file->inode.mode))
- node->type = DIR_NODE;
- else if (S_ISREG(file->inode.mode))
- node->type = FILE_NODE;
- else // TODO: Add missing
- warn("Unsupported filetype!");
- }
-}
-
-void ext2_vfs_close(struct fs_node *node)
-{
- kfree(node->impl);
-}
-
-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");
- return 0;
- }
-
- return (uint32_t)ext2_read(node->impl, (uint8_t *)buf, size);
-}
-
-uint32_t ext2_vfs_write(struct fs_node *node, size_t offset, size_t size, char *buf)
-{
- warn(RED "Writing to Ext2 is currently unsupported" RES);
-
- return 0;
-}
-
-struct dirent *ext2_vfs_read_dir(struct fs_node *node, size_t index)
-{
- struct ext2_dirent ext2_dir;
-
- if (ext2_next_dirent(node->impl, &ext2_dir)) {
- struct dirent *dir = kmalloc(sizeof *dir);
-
- dir->inode = ext2_dir.inode_num;
- strcpy(dir->name, (char *)ext2_dir.name);
-
- return dir;
- } else {
- return NULL;
- }
-}
-
-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(struct fs_node));
- found->inode = inode;
-
- return found;
- }
-}
-
-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);
- assert((mountpoint->type & DIR_NODE) != 0);
-
- struct fs_node *ext2_root = (struct fs_node *)kmalloc(sizeof(struct fs_node));
- strcpy(ext2_root->name, "/.");
- ext2_root->inode = ROOT_INODE;
- ext2_root->type = DIR_NODE;
- ext2_node_init(ext2_root);
-
- mountpoint->type |= MOUNTPOINT_NODE;
- mountpoint->node_ptr = ext2_root;
} \ No newline at end of file
diff --git a/src/kernel/fs/ext2.h b/src/kernel/fs/ext2.h
index 2fd0e83..f63b8b6 100644
--- a/src/kernel/fs/ext2.h
+++ b/src/kernel/fs/ext2.h
@@ -4,7 +4,6 @@
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
-#include <kernel/fs/vfs.h>
#define ROOT_INODE 2
diff --git a/src/kernel/fs/fs.c b/src/kernel/fs/fs.c
new file mode 100644
index 0000000..1553113
--- /dev/null
+++ b/src/kernel/fs/fs.c
@@ -0,0 +1,61 @@
+#include <stdint.h>
+#include <kernel/fs/ext2.h>
+#include <kernel/system.h>
+#include <kernel/memory/alloc.h>
+
+uint32_t get_file_size(char *path)
+{
+ uint32_t inode = ext2_look_up_path(path);
+ struct ext2_file file;
+ ext2_open_inode(inode, &file);
+ if (inode != 0) {
+ return file.inode.size;
+ } else {
+ warn("File not found");
+ return -1;
+ }
+}
+
+// TODO: Implement offset
+uint32_t read(char *path, uint32_t offset, uint32_t count, uint8_t *buf)
+{
+ uint32_t inode = ext2_look_up_path(path);
+ struct ext2_file file;
+ ext2_open_inode(inode, &file);
+ if (inode != 0) {
+ debug("Reading %s: %dKiB", path, count >> 10);
+ ext2_read(&file, buf, count);
+ kfree(file.buf);
+ buf[count - 1] = '\0';
+ return buf;
+ } else {
+ warn("File not found");
+ return -1;
+ }
+}
+
+// TODO: Implement writing
+uint32_t write(char *path, uint32_t offset, uint32_t count, uint8_t *buf)
+{
+ warn("Writing is not supported!");
+ return -1;
+}
+
+uint8_t *read_file(char *path)
+{
+ uint32_t inode = ext2_look_up_path(path);
+ struct ext2_file file;
+ ext2_open_inode(inode, &file);
+ if (inode != 0) {
+ size_t size = file.inode.size;
+ debug("Reading %s: %dKiB", path, size >> 10);
+ uint8_t *buf = kmalloc(size);
+ ext2_read(&file, buf, size);
+ kfree(file.buf);
+ buf[size - 1] = '\0';
+ return buf;
+ } else {
+ warn("File not found");
+ return NULL;
+ }
+} \ No newline at end of file
diff --git a/src/kernel/fs/fs.h b/src/kernel/fs/fs.h
new file mode 100644
index 0000000..88dcd95
--- /dev/null
+++ b/src/kernel/fs/fs.h
@@ -0,0 +1,11 @@
+#ifndef MELVIX_FS_H
+#define MELVIX_FS_H
+
+#include <stdint.h>
+
+uint32_t get_file_size(char *path);
+uint32_t read(char *path, uint32_t offset, uint32_t count, uint8_t *buf);
+uint32_t write(char *path, uint32_t offset, uint32_t count, uint8_t *buf);
+uint8_t *read_file(char *path); // Only for temp kernel reads
+
+#endif \ No newline at end of file
diff --git a/src/kernel/fs/vfs.c b/src/kernel/fs/vfs.c
deleted file mode 100644
index 0098d3b..0000000
--- a/src/kernel/fs/vfs.c
+++ /dev/null
@@ -1,204 +0,0 @@
-#include <stdint.h>
-#include <stddef.h>
-#include <kernel/fs/vfs.h>
-#include <kernel/fs/ext2.h>
-#include <kernel/lib/stdlib.h>
-#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)
-{
- if (node->read != NULL)
- return node->read(node, offset, size, buf);
- else
- return 0;
-}
-
-uint32_t fs_write(struct fs_node *node, uint32_t offset, uint32_t size, char *buf)
-{
- if (node->write != NULL)
- return node->write(node, offset, size, buf);
- else
- return 0;
-}
-
-void fs_open(struct fs_node *node)
-{
- if (node->open != NULL)
- node->open(node);
- else // TODO: Better ext2 default open workaround
- fs_root->open(node);
-}
-
-void fs_close(struct fs_node *node)
-{
- if (node->close != NULL)
- node->close(node);
- else
- fs_root->open(node);
-}
-
-struct dirent *fs_read_dir(struct fs_node *node, uint32_t index)
-{
- if ((node->type & DIR_NODE) != 0 && node->find_dir != NULL)
- return node->read_dir(node, index);
- else
- return (struct dirent *)NULL;
-}
-
-struct fs_node *fs_find_dir(struct fs_node *node, char *name)
-{
- if ((node->type & DIR_NODE) != 0 && node->find_dir != NULL)
- return node->find_dir(node, name);
- else
- return (struct fs_node *)NULL;
-}
-
-// TODO: This should be somewhere else ig
-char *next_str(char *str)
-{
- str = &str[strlen(str)];
-
- int i = 0;
- while (str[i] == 0)
- i++;
-
- return &str[i];
-}
-
-// By far not the fastest algorithm
-struct fs_node *fs_path(struct fs_node *node, char *name)
-{
- if (name[0] == '/')
- return node;
-
- char *cpy = (char *)kmalloc(strlen(name) + 2);
- strcpy(cpy, name);
- cpy[strlen(name) + 1] = 1;
-
- name = cpy;
- char *end = &name[strlen(name)];
-
- int len = strlen(name);
- for (int i = 0; i < len; i++)
- if (name[i] == '/')
- name[i] = 0;
-
- if (strlen(name) == 0)
- name = next_str(name);
-
- do {
- node = node->node_ptr;
-
- while (node != NULL) {
- if (strcmp(node->name, name) == 0)
- break;
-
- node = node->link;
- }
-
- if (node == NULL) {
- kfree(cpy);
- return NULL;
- }
-
- name = next_str(name);
- } while ((uint32_t)name < (uint32_t)end);
-
- kfree(cpy);
- return node;
-}
-
-void vfs_ls(char *path)
-{
- struct fs_node *dir = fs_path(fs_root, path);
- if (dir == NULL) {
- warn("Invalid path");
- return;
- }
-
- struct fs_node *link = dir->node_ptr;
-
- log("Listing for %s", path);
- while (link != NULL) {
- log(link->name);
- link = link->link;
- }
-}
-
-struct fs_node *vfs_get_dir(struct fs_node *node, char *name)
-{
- char *cpy = (char *)kmalloc(strlen(name) + 2);
- char *ref = cpy;
- strcpy(cpy, name);
- cpy[strlen(name) + 1] = 1;
- name = cpy;
-
- for (int i = strlen(name); i >= 0; i--)
- if (name[i] == '/') {
- name[i] = 0;
- break;
- }
-
- struct fs_node *output;
- if (strlen(name) == 0)
- output = fs_root;
- else
- output = fs_path(node, name);
-
- kfree(ref);
- return output;
-}
-
-char *basename(char *name)
-{
- for (int i = strlen(name); i >= 0; i--)
- if (name[i] == '/')
- return &name[i + 1];
-
- return name;
-}
-
-// TODO: Implement file touching in ext2
-struct fs_node *vfs_touch(struct fs_node *node, char *name)
-{
- struct fs_node *dir = vfs_get_dir(node, name);
-
- if (dir == NULL)
- return NULL;
-
- struct fs_node *file = (struct fs_node *)kmalloc(sizeof(struct fs_node));
- ext2_node_init(file);
- file->type = FILE_NODE;
- strcpy(file->name, basename(name));
-
- //ext2_file *entry = ext2_new_file();
- //strcpy(file->name, entry->name);
-
- file->link = dir->node_ptr;
- dir->node_ptr = file;
-
- return file;
-}
-
-struct fs_node *vfs_mkdir(struct fs_node *node, char *name)
-{
- struct fs_node *dir = vfs_get_dir(node, name);
- if (dir == NULL) {
- warn("Invalid path");
- return NULL;
- }
-
- struct fs_node *file = (struct fs_node *)kmalloc(sizeof(struct fs_node));
- ext2_node_init(file);
- file->type = DIR_NODE;
- strcpy(file->name, basename(name));
-
- file->link = dir->node_ptr;
- dir->node_ptr = file;
-
- return file;
-} \ No newline at end of file
diff --git a/src/kernel/fs/vfs.h b/src/kernel/fs/vfs.h
deleted file mode 100644
index 26c34f9..0000000
--- a/src/kernel/fs/vfs.h
+++ /dev/null
@@ -1,71 +0,0 @@
-#ifndef MELVIX_VFS_H
-#define MELVIX_VFS_H
-
-#include <stdint.h>
-
-#define MAX_NAME_LENGTH 128
-
-enum node_type {
- FILE_NODE = 1,
- DIR_NODE,
- CHAR_DEV_NODE,
- BLOCK_DEV_NODE,
- PIPE_NODE,
- SYMLINK_NODE,
- MOUNTPOINT_NODE = 8
-};
-
-struct fs_node;
-struct dirent;
-
-typedef uint32_t (*read)(struct fs_node *, uint32_t, uint32_t, char *);
-typedef uint32_t (*write)(struct fs_node *, uint32_t, uint32_t, char *);
-typedef void (*open)(struct fs_node *);
-typedef void (*close)(struct fs_node *);
-typedef struct dirent *(*read_dir)(struct fs_node *, uint32_t);
-typedef struct fs_node *(*find_dir)(struct fs_node *, char *);
-
-struct fs_node {
- char name[MAX_NAME_LENGTH];
- uint32_t length;
- uint32_t inode;
- uint32_t permissions;
- uint32_t uid;
- uint32_t gid;
- enum node_type type;
-
- struct dev *dev;
- struct fs_node *node_ptr;
- struct fs_node *link;
-
- void *impl;
-
- read read;
- write write;
- open open;
- close close;
- read_dir read_dir;
- find_dir find_dir;
-};
-
-struct dirent {
- char name[MAX_NAME_LENGTH];
- uint32_t inode;
-};
-
-extern struct fs_node *fs_root;
-
-uint32_t fs_read(struct fs_node *node, uint32_t offset, uint32_t size, char *buf);
-uint32_t fs_write(struct fs_node *node, uint32_t offset, uint32_t size, char *buf);
-void fs_open(struct fs_node *node);
-void fs_close(struct fs_node *node);
-struct dirent *fs_read_dir(struct fs_node *node, uint32_t index);
-struct fs_node *fs_find_dir(struct fs_node *node, char *name);
-
-char *basename(char *name);
-void vfs_ls(char *path);
-struct fs_node *vfs_get_dir(struct fs_node *node, char *name);
-struct fs_node *vfs_touch(struct fs_node *node, char *name);
-struct fs_node *vfs_mkdir(struct fs_node *node, char *name);
-
-#endif \ No newline at end of file
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index 1e8c9c1..cf31d76 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -5,7 +5,6 @@
#include <kernel/lib/stdio.h>
#include <kernel/memory/alloc.h>
#include <kernel/memory/paging.h>
-#include <kernel/fs/dev.h>
void vbe_error()
{
@@ -177,7 +176,7 @@ void set_optimal_resolution()
paging_map_user(paging_root_directory, (uint32_t)fb + z, (uint32_t)fb + z);
}
- dev_make("fb", NULL, (write)fb_write);
+ /* dev_make("fb", NULL, (write)fb_write); */
/* struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node)); */
/* strcpy(node->name, "/dev/fb"); */
/* fs_open(node); */
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index 40db307..c940e55 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -17,8 +17,6 @@
#include <kernel/lib/stdio.h>
#include <kernel/fs/ata.h>
#include <kernel/fs/ext2.h>
-#include <kernel/fs/vfs.h>
-#include <kernel/fs/dev.h>
#include <kernel/cmos/rtc.h>
#include <kernel/memory/alloc.h>
@@ -67,20 +65,7 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address, uint32_t esp)
load_binaries();
set_optimal_resolution();
-
- struct fs_node *test = (struct fs_node *)kmalloc(sizeof(struct fs_node));
- strcpy(test->name, "/etc/test");
- fs_open(test);
- uint32_t size = ((struct ext2_file *)test->impl)->inode.size;
- char buf[size];
- fs_read(test, 0, size, buf);
- buf[size - 1] = '\0';
- log("Content of /etc/test: %s", buf);
- fs_close(test);
-
- dev_stdin();
- dev_stdout();
- dev_stderr();
+ log("Content of /etc/test: %s", read_file("/etc/test"));
syscalls_install();
kexec("/bin/init");
diff --git a/src/kernel/syscall/actions/sys_read.c b/src/kernel/syscall/actions/sys_read.c
index 8931ede..492e5fd 100644
--- a/src/kernel/syscall/actions/sys_read.c
+++ b/src/kernel/syscall/actions/sys_read.c
@@ -1,22 +1,7 @@
#include <stdint.h>
-#include <kernel/fs/vfs.h>
-#include <kernel/fs/ext2.h>
-#include <kernel/lib/stdlib.h>
-#include <kernel/memory/alloc.h>
+#include <kernel/fs/fs.h>
-uint32_t sys_read(char *path, uint32_t offset, uint32_t count, char *buf)
+uint32_t sys_read(char *path, uint32_t offset, uint32_t count, uint8_t *buf)
{
- struct fs_node *node = (struct fs_node *)umalloc(sizeof(struct fs_node));
- strcpy(node->name, path);
- fs_open(node);
- if (node->inode != 0) {
- uint32_t size = ((struct ext2_file *)node->impl)->inode.size;
- fs_read(node, 0, size, buf);
- buf[size - 1] = '\0';
- fs_close(node);
- return size;
- } else {
- fs_close(node);
- return -1;
- }
+ return read(path, offset, count, buf);
} \ No newline at end of file
diff --git a/src/kernel/syscall/actions/sys_write.c b/src/kernel/syscall/actions/sys_write.c
index 28a5929..b9b30f3 100644
--- a/src/kernel/syscall/actions/sys_write.c
+++ b/src/kernel/syscall/actions/sys_write.c
@@ -1,23 +1,7 @@
#include <stdint.h>
-#include <kernel/fs/vfs.h>
-#include <kernel/fs/ext2.h>
-#include <kernel/lib/stdlib.h>
-#include <kernel/memory/alloc.h>
-#include <kernel/system.h>
+#include <kernel/fs/fs.h>
-uint32_t sys_write(char *path, uint32_t offset, uint32_t count, char *buf)
+uint32_t sys_write(char *path, uint32_t offset, uint32_t count, uint8_t *buf)
{
- struct fs_node *node = (struct fs_node *)umalloc(sizeof(struct fs_node));
- strcpy(node->name, path);
- fs_open(node);
- if (node->inode != 0) {
- uint32_t size = ((struct ext2_file *)node->impl)->inode.size;
- fs_write(node, 0, size, buf);
- buf[size - 1] = '\0';
- fs_close(node);
- return size;
- } else {
- fs_close(node);
- return -1;
- }
+ return write(path, offset, count, buf);
} \ No newline at end of file
diff --git a/src/kernel/syscall/syscall.h b/src/kernel/syscall/syscall.h
index 322e551..9af18e8 100644
--- a/src/kernel/syscall/syscall.h
+++ b/src/kernel/syscall/syscall.h
@@ -12,9 +12,9 @@ uint32_t sys_exit(uint32_t code);
uint32_t sys_fork(struct regs *r);
-uint32_t sys_read(char *path, uint32_t offset, uint32_t count, char *buf);
+uint32_t sys_read(char *path, uint32_t offset, uint32_t count, uint8_t *buf);
-uint32_t sys_write(char *path, uint32_t offset, uint32_t count, char *buf);
+uint32_t sys_write(char *path, uint32_t offset, uint32_t count, uint8_t *buf);
uint32_t sys_exec(char *path);
diff --git a/src/userspace/libc/syscall.c b/src/userspace/libc/syscall.c
index f6761ac..fc0e09a 100644
--- a/src/userspace/libc/syscall.c
+++ b/src/userspace/libc/syscall.c
@@ -9,9 +9,9 @@ DEFN_SYSCALL1(exit, 1, u32);
DEFN_SYSCALL0(fork, 2);
-DEFN_SYSCALL4(read, 3, char *, u32, u32, char *);
+DEFN_SYSCALL4(read, 3, char *, u32, u32, u8 *);
-DEFN_SYSCALL4(write, 4, char *, u32, u32, char *);
+DEFN_SYSCALL4(write, 4, char *, u32, u32, u8 *);
DEFN_SYSCALL1(exec, 5, char *);
diff --git a/src/userspace/libc/syscall.h b/src/userspace/libc/syscall.h
index 262e05a..038f985 100644
--- a/src/userspace/libc/syscall.h
+++ b/src/userspace/libc/syscall.h
@@ -74,9 +74,9 @@ DECL_SYSCALL1(exit, u32);
DECL_SYSCALL0(fork);
-DECL_SYSCALL4(read, char *, u32, u32, char *);
+DECL_SYSCALL4(read, char *, u32, u32, u8 *);
-DECL_SYSCALL4(write, char *, u32, u32, char *);
+DECL_SYSCALL4(write, char *, u32, u32, u8 *);
DECL_SYSCALL1(exec, char *);
diff --git a/src/userspace/programs/sh.c b/src/userspace/programs/sh.c
index f22a528..bb1c9ea 100644
--- a/src/userspace/programs/sh.c
+++ b/src/userspace/programs/sh.c
@@ -5,7 +5,6 @@
void main()
{
- write("/dev/fb", 0, 5, "hallo");
printf("[~] ");
while (1) {