aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/syscall_handler
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/kapi/syscall_handler')
-rw-r--r--kernel/kapi/syscall_handler/filesystem.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/kernel/kapi/syscall_handler/filesystem.cpp b/kernel/kapi/syscall_handler/filesystem.cpp
new file mode 100644
index 0000000..a6e8027
--- /dev/null
+++ b/kernel/kapi/syscall_handler/filesystem.cpp
@@ -0,0 +1,59 @@
+#include "kapi/syscall_handler/filesystem.hpp"
+
+#include "kernel/filesystem/file_descriptor_table.hpp"
+#include "kernel/filesystem/vfs.hpp"
+
+#include <cstddef>
+#include <sys/types.h>
+
+namespace kapi::syscall_handler::filesystem
+{
+ auto mount(char const * source, char const * target) -> int
+ {
+ // TODO BA-FS26
+ }
+
+ auto umount(char const * target) -> int
+ {
+ if (kernel::filesystem::vfs::get().unmount(target) == kernel::filesystem::vfs::operation_result::success)
+ {
+ return 0;
+ }
+ return -1;
+ }
+
+ auto open(char const * path) -> int
+ {
+ if (auto open_file_description = kernel::filesystem::vfs::get().open(path))
+ {
+ return kernel::filesystem::file_descriptor_table::get().add_file(open_file_description);
+ }
+
+ return -1;
+ }
+
+ auto close(int fd) -> int
+ {
+ return kernel::filesystem::file_descriptor_table::get().remove_file(fd);
+ }
+
+ auto read(int fd, void * buffer, size_t size) -> ssize_t
+ {
+ if (auto open_file_description = kernel::filesystem::file_descriptor_table::get().get_file(fd))
+ {
+ return open_file_description->read(buffer, size);
+ }
+
+ return -1;
+ }
+
+ auto write(int fd, void const * buffer, size_t size) -> ssize_t
+ {
+ if (auto open_file_description = kernel::filesystem::file_descriptor_table::get().get_file(fd))
+ {
+ return open_file_description->write(buffer, size);
+ }
+
+ return -1;
+ }
+} // namespace kapi::syscall_handler::filesystem \ No newline at end of file