aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/syscall_handler/filesystem.cpp
diff options
context:
space:
mode:
authorMarcel Braun <marcel.braun@ost.ch>2026-04-12 20:45:23 +0200
committerMarcel Braun <marcel.braun@ost.ch>2026-04-12 20:45:23 +0200
commitbb01b9f2d29524974881e9a88ffb6c229836ddba (patch)
treec8a3eb83ada92c83e73afad5cf763f12243bd642 /kernel/kapi/syscall_handler/filesystem.cpp
parent4d2a1d028f8ba28b655026b93124e71a12562619 (diff)
downloadteachos-bb01b9f2d29524974881e9a88ffb6c229836ddba.tar.xz
teachos-bb01b9f2d29524974881e9a88ffb6c229836ddba.zip
Add fs syscall handler
Diffstat (limited to 'kernel/kapi/syscall_handler/filesystem.cpp')
-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