diff options
Diffstat (limited to 'kernel/kernel/main.cpp')
| -rw-r--r-- | kernel/kernel/main.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/kernel/kernel/main.cpp b/kernel/kernel/main.cpp index 8dc13490..8dce5143 100644 --- a/kernel/kernel/main.cpp +++ b/kernel/kernel/main.cpp @@ -13,10 +13,11 @@ #include <kapi/memory.hpp> #include <kapi/system.hpp> -#include <kstd/format> -#include <kstd/print> -#include <kstd/units> -#include <kstd/vector> +#include <kstd/format.hpp> +#include <kstd/print.hpp> +#include <kstd/system_error.hpp> +#include <kstd/units.hpp> +#include <kstd/vector.hpp> #include <cstddef> #include <string_view> @@ -28,33 +29,33 @@ auto run_demo() -> void // 1) open a file kstd::println("attempting to open /entrance/tickets.txt"); auto fd_1 = kapi::filesystem::open("/entrance/tickets.txt"); - if (fd_1 == -1) + if (!fd_1) { kapi::system::panic("demo failed"); } else { - kstd::println("--> successfully opened /entrance/tickets.txt with file descriptor {}", fd_1); + kstd::println("--> successfully opened /entrance/tickets.txt with file descriptor {}", fd_1.value()); } // 2) read from the file kstd::vector<std::byte> buffer_1{10}; - auto bytes_read = kapi::filesystem::read(fd_1, buffer_1.data(), buffer_1.size()); - auto buffer_as_str = std::string_view{reinterpret_cast<char *>(buffer_1.data()), static_cast<size_t>(bytes_read)}; + auto bytes_read = *kapi::filesystem::read(fd_1.value(), buffer_1.data(), buffer_1.size()); + auto buffer_as_str = std::string_view{reinterpret_cast<char *>(buffer_1.data()), bytes_read}; kstd::println("--> read {} bytes from /entrance/tickets.txt: {}", bytes_read, buffer_as_str); kstd::println(""); // 3) show that /entrance/information/info_1.txt is not accessible before mounting kstd::println("attempting to open /entrance/information/info_1.txt before mounting"); auto fd_before_mount = kapi::filesystem::open("/entrance/information/info_1.txt"); - if (fd_before_mount == -1) + if (!fd_before_mount && fd_before_mount.error() == kstd::errc::no_such_file_or_directory) { kstd::println("--> as expected the file could not be opened before mounting"); } // 4) mount a new filesystem on top of /entrance kstd::println("mount /dev/ram16 to /entrance"); - if (kapi::filesystem::mount("/dev/ram16", "/entrance") == 0) + if (kapi::filesystem::mount("/dev/ram16", "/entrance")) { kstd::println("--> successfully mounted /dev/ram16 to /entrance"); } @@ -67,9 +68,9 @@ auto run_demo() -> void // 5) open a file from the new filesystem kstd::println("attempting to open /entrance/information/info_1.txt"); auto fd_2 = kapi::filesystem::open("/entrance/information/info_1.txt"); - if (fd_2 != -1) + if (fd_2) { - kstd::println("--> successfully opened /entrance/information/info_1.txt with file descriptor {}", fd_2); + kstd::println("--> successfully opened /entrance/information/info_1.txt with file descriptor {}", fd_2.value()); } else { @@ -78,16 +79,16 @@ auto run_demo() -> void // 6) read from the new file kstd::vector<std::byte> buffer_2{10}; - bytes_read = kapi::filesystem::read(fd_2, buffer_2.data(), buffer_2.size()); + bytes_read = *kapi::filesystem::read(fd_2.value(), buffer_2.data(), buffer_2.size()); buffer_as_str = std::string_view{reinterpret_cast<char *>(buffer_2.data()), static_cast<size_t>(bytes_read)}; kstd::println("--> read {} bytes from /entrance/information/info_1.txt: {} ", bytes_read, buffer_as_str); // 7) open device as file kstd::println("attempting to open /dev/ram32 as a file"); auto fd_3 = kapi::filesystem::open("/dev/ram32"); - if (fd_3 != -1) + if (fd_3) { - kstd::println("--> successfully opened /dev/ram32 as a file with file descriptor {}", fd_3); + kstd::println("--> successfully opened /dev/ram32 as a file with file descriptor {}", fd_3.value()); } else { @@ -96,13 +97,13 @@ auto run_demo() -> void // 8) read from the device file kstd::vector<std::byte> buffer_3{2}; - bytes_read = kapi::filesystem::read(fd_3, buffer_3.data(), buffer_3.size()); + bytes_read = *kapi::filesystem::read(fd_3.value(), buffer_3.data(), buffer_3.size()); kstd::println("--> read {} bytes from /dev/ram32: {::#04x} ", bytes_read, buffer_3); // 9) write to the device file auto const default_buffer_value = std::byte{0xAA}; kstd::vector<std::byte> write_buffer{default_buffer_value, default_buffer_value}; - auto bytes_written = kapi::filesystem::write(fd_3, write_buffer.data(), write_buffer.size()); + auto bytes_written = *kapi::filesystem::write(fd_3.value(), write_buffer.data(), write_buffer.size()); kstd::println("--> written {} bytes to /dev/ram32: {::#04x}", bytes_written, write_buffer); // 10) do memory dump to show that the write to the device file had an effect @@ -146,7 +147,7 @@ auto main() -> int kstd::println("[OS] Virtual filesystem initialized."); // TODO BA-FS26 remove demo code? - // run_demo(); + run_demo(); kapi::system::panic("Returning from kernel main!"); } |
