aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/syscall_handler/filesystem.cpp
blob: a6e802778f9e9e111919557495150bd5e281b085 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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