aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/main.cpp
diff options
context:
space:
mode:
authorMarcel Braun <marcel.braun@ost.ch>2026-05-25 14:13:11 +0200
committerMarcel Braun <marcel.braun@ost.ch>2026-05-25 14:13:11 +0200
commit0ab7525951b0116241f393090987bedc07a18c33 (patch)
treefdd1d16c7de4f35dfc6d527cb9caa554e0db2c0c /kernel/src/main.cpp
parent093074d5209f2d0062be79059f5881ee051c07d0 (diff)
parentadb1b5f2d6858097227fa610e86d1152b79d0bfa (diff)
downloadkernel-0ab7525951b0116241f393090987bedc07a18c33.tar.xz
kernel-0ab7525951b0116241f393090987bedc07a18c33.zip
Merge branch 'improve-mount-reference-count' into 'develop-BA-FS26'
Increase reference count of source_mount when one of its files is mounted somewhere See merge request teachos/kernel!42
Diffstat (limited to 'kernel/src/main.cpp')
-rw-r--r--kernel/src/main.cpp54
1 files changed, 40 insertions, 14 deletions
diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp
index 22d2b1e..6985e94 100644
--- a/kernel/src/main.cpp
+++ b/kernel/src/main.cpp
@@ -13,7 +13,6 @@
#include <kapi/system.hpp>
#include <kstd/format>
-#include <kstd/os/error.hpp>
#include <kstd/print>
#include <kstd/units>
#include <kstd/vector>
@@ -26,57 +25,84 @@ using namespace kstd::units_literals;
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)
{
- kstd::os::panic("demo failed");
+ kapi::system::panic("demo failed");
+ }
+ else
+ {
+ kstd::println("--> successfully opened /entrance/tickets.txt with file descriptor {}", fd_1);
}
// 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)};
- kstd::println("Read {} bytes from /entrance/tickets.txt: {}", bytes_read, buffer_as_str);
+ 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)
{
- kstd::println("/entrance/information/info_1.txt is not accessible before mounting, as expected.");
+ kstd::println("--> as expected the file could not be opened before mounting");
}
// 4) mount a new filesystem on top of /entrance
- kapi::filesystem::mount("/dev/ram16", "/entrance");
+ kstd::println("mount /dev/ram16 to /entrance");
+ if (kapi::filesystem::mount("/dev/ram16", "/entrance") == 0)
+ {
+ kstd::println("--> successfully mounted /dev/ram16 to /entrance");
+ }
+ else
+ {
+ kapi::system::panic("demo failed");
+ }
+ kstd::println("");
// 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 != -1)
+ {
+ kstd::println("--> successfully opened /entrance/information/info_1.txt with file descriptor {}", fd_2);
+ }
+ else
{
- kstd::os::panic("demo failed");
+ kapi::system::panic("demo failed");
}
// 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());
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);
+ kstd::println("--> read {} bytes from /entrance/information/info_1.txt: {} ", bytes_read, buffer_as_str);
// 7) open device as file
- auto fd_3 = kapi::filesystem::open("/dev/ram48");
- if (fd_3 == -1)
+ kstd::println("attempting to open /dev/ram32 as a file");
+ auto fd_3 = kapi::filesystem::open("/dev/ram32");
+ if (fd_3 != -1)
+ {
+ kstd::println("--> successfully opened /dev/ram32 as a file with file descriptor {}", fd_3);
+ }
+ else
{
- kstd::os::panic("demo failed");
+ kapi::system::panic("demo failed");
}
// 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());
- kstd::println("Read {} bytes from /dev/ram48: {::#04x}", bytes_read, buffer_3);
+ kstd::println("--> read {} bytes from /dev/ram32: {::#04x} ", bytes_read, buffer_3);
// 9) write to the device file
- kstd::vector<std::byte> write_buffer{std::byte{0xAA}, std::byte{0xAA}};
+ 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());
- kstd::println("Written {} bytes to /dev/ram48: {::#04x}", bytes_written, write_buffer);
+ 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
}