aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/filesystem/file_descriptor_table.cpp
diff options
context:
space:
mode:
authorLukas Oesch <lukasoesch20@gmail.com>2026-03-20 22:27:26 +0100
committerLukas Oesch <lukasoesch20@gmail.com>2026-03-26 21:17:30 +0100
commitbe44d4b778bb7c3a947af4cae610ecc3b8851672 (patch)
tree2dbee85f2ccc9e9597e1df368312d50504e7c879 /kernel/src/filesystem/file_descriptor_table.cpp
parenta396b71827a24f9d6c8010fd85b9afd9d86b6e2a (diff)
downloadteachos-be44d4b778bb7c3a947af4cae610ecc3b8851672.tar.xz
teachos-be44d4b778bb7c3a947af4cae610ecc3b8851672.zip
use kstd::shared_ptr instead of std::optional for open_file_descriptions
Diffstat (limited to 'kernel/src/filesystem/file_descriptor_table.cpp')
-rw-r--r--kernel/src/filesystem/file_descriptor_table.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/kernel/src/filesystem/file_descriptor_table.cpp b/kernel/src/filesystem/file_descriptor_table.cpp
index 814322e..6eb3845 100644
--- a/kernel/src/filesystem/file_descriptor_table.cpp
+++ b/kernel/src/filesystem/file_descriptor_table.cpp
@@ -4,6 +4,8 @@
#include "kernel/filesystem/open_file_description.hpp"
+#include <kstd/memory>
+
#include <algorithm>
#include <cstddef>
#include <optional>
@@ -35,9 +37,15 @@ namespace filesystem
return *global_file_descriptor_table;
}
- auto file_descriptor_table::add_file(open_file_description & file_description) -> int
+ auto file_descriptor_table::add_file(kstd::shared_ptr<open_file_description> const & file_description) -> int
{
- auto it = std::ranges::find_if(m_open_files, [](auto & open_file) { return !open_file.has_value(); });
+ if (!file_description)
+ {
+ // TODO BA-FS26 panic or errorcode?
+ return -1;
+ }
+
+ auto it = std::ranges::find_if(m_open_files, [](auto const & open_file) { return open_file == nullptr; });
if (it != m_open_files.end())
{
*it = file_description;
@@ -48,20 +56,20 @@ namespace filesystem
return static_cast<int>(m_open_files.size() - 1);
}
- auto file_descriptor_table::get_file(int fd) const -> std::optional<open_file_description>
+ auto file_descriptor_table::get_file(int fd) const -> kstd::shared_ptr<open_file_description>
{
if (fd < 0)
{
- return std::nullopt;
+ return nullptr;
}
auto const index = static_cast<size_t>(fd);
- if (index >= m_open_files.size() || !m_open_files.at(fd).has_value())
+ if (index >= m_open_files.size())
{
- return std::nullopt;
+ return nullptr;
}
- return m_open_files.at(fd);
+ return m_open_files.at(index);
}
auto file_descriptor_table::remove_file(int fd) -> void
@@ -77,6 +85,6 @@ namespace filesystem
return;
}
- m_open_files.at(fd).reset();
+ m_open_files.at(index) = nullptr;
}
} // namespace filesystem \ No newline at end of file