aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi
diff options
context:
space:
mode:
authorManuel Bott <manuel.bott@ost.ch>2026-11-12 12:41:56 +0100
committerManuel Bott <manuel.bott@ost.ch>2026-11-12 12:41:56 +0100
commitb343039cfd1227a1493aef1e773ce07204763d07 (patch)
treedeaebf06e5d1b13577e4ebd1c9d79bb6ea8c672e /kernel/kapi
parentacddd90e000a69470b6aafb1e74acb2caca4af58 (diff)
parentf3df6fe2537b31bb9b86d13bf02f9d01e903a524 (diff)
downloadkernel-b343039cfd1227a1493aef1e773ce07204763d07.tar.xz
kernel-b343039cfd1227a1493aef1e773ce07204763d07.zip
Merge branch 'feature/writeFiles' into 'fa26/develop'
kernel/filesystems: implement fat32 write files See merge request teachos/kernel!73
Diffstat (limited to 'kernel/kapi')
-rw-r--r--kernel/kapi/filesystem.tests.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/kernel/kapi/filesystem.tests.cpp b/kernel/kapi/filesystem.tests.cpp
index f46c6bb8..f71eead0 100644
--- a/kernel/kapi/filesystem.tests.cpp
+++ b/kernel/kapi/filesystem.tests.cpp
@@ -12,6 +12,7 @@
#include <cstddef>
#include <filesystem>
#include <ranges>
+#include <span>
#include <string>
#include <string_view>
#include <utility>
@@ -414,14 +415,21 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_vfs_fixture, "Kapi files
REQUIRE(kapi::filesystem::read_directory(*directory, buffer) == 0);
}
- THEN("writing to a file fails because the filesystem is read only")
+ THEN("a file can be overwritten and extended through its file descriptor")
{
auto const fd = kapi::filesystem::open("/information/hello.txt");
REQUIRE(fd);
- auto const buffer = std::vector<std::byte>{std::byte{'X'}};
- REQUIRE(kapi::filesystem::write(*fd, buffer).error() == kstd::errc::read_only_file_system);
+ auto const text = std::string_view{"Hello Peter! Goodbye"};
+ REQUIRE(kapi::filesystem::seek(*fd, 6_B_off, kapi::filesystem::seek_origin::beginning) == 6_B);
+ REQUIRE(kapi::filesystem::write(*fd, std::as_bytes(std::span{text}.subspan(6))) == 14_B);
REQUIRE(kapi::filesystem::close(*fd));
+
+ auto const reopened = kapi::filesystem::open("/information/hello.txt");
+ REQUIRE(reopened);
+ REQUIRE(read_text(*reopened, 7) == text);
+ REQUIRE(kapi::filesystem::close(*reopened));
+ REQUIRE(kapi::filesystem::status("/information/hello.txt")->size == 20_B);
}
THEN("opening a missing file fails")