aboutsummaryrefslogtreecommitdiff
path: root/kernel/filesystem/src/file_descriptor_table.cpp
diff options
context:
space:
mode:
authorLukas Oesch <lukas.oesch@ost.ch>2026-03-17 19:48:59 +0100
committerLukas Oesch <lukas.oesch@ost.ch>2026-03-17 19:48:59 +0100
commite4291ea7c01cad04a02ca3f577dba9ccbadad110 (patch)
tree4af08f01820bf13fba8dda7646d036bcbdd3df53 /kernel/filesystem/src/file_descriptor_table.cpp
parent59504cfd677dd3e9d9ddb0deea4df7614efedb84 (diff)
parentfde097681f96e2c6f23ecd71a5c0037acb3ac79e (diff)
downloadteachos-e4291ea7c01cad04a02ca3f577dba9ccbadad110.tar.xz
teachos-e4291ea7c01cad04a02ca3f577dba9ccbadad110.zip
Merge branch 'tidy-up-folder-structure' into 'develop-BA-FS26'
rename files to snake_case (temp_device part1 -> renamed to device later, due... See merge request teachos/kernel!12
Diffstat (limited to 'kernel/filesystem/src/file_descriptor_table.cpp')
-rw-r--r--kernel/filesystem/src/file_descriptor_table.cpp82
1 files changed, 0 insertions, 82 deletions
diff --git a/kernel/filesystem/src/file_descriptor_table.cpp b/kernel/filesystem/src/file_descriptor_table.cpp
deleted file mode 100644
index 64fad0c..0000000
--- a/kernel/filesystem/src/file_descriptor_table.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-#include "filesystem/file_descriptor_table.hpp"
-
-#include "kapi/system.hpp"
-
-#include "filesystem/open_file_description.hpp"
-
-#include <algorithm>
-#include <cstddef>
-#include <optional>
-
-namespace filesystem
-{
- namespace
- {
- constinit auto static global_file_descriptor_table = std::optional<file_descriptor_table>{};
- } // namespace
-
- auto file_descriptor_table::init() -> void
- {
- if (global_file_descriptor_table)
- {
- kapi::system::panic("[FILESYSTEM] File descriptor table has already been initialized.");
- }
-
- global_file_descriptor_table.emplace(file_descriptor_table{});
- }
-
- auto file_descriptor_table::get() -> file_descriptor_table &
- {
- if (!global_file_descriptor_table)
- {
- kapi::system::panic("[FILESYSTEM] File descriptor table has not been initialized.");
- }
-
- return *global_file_descriptor_table;
- }
-
- auto file_descriptor_table::add_file(open_file_description & file_description) -> int
- {
- auto it = std::ranges::find_if(m_open_files, [](auto & open_file) { return !open_file.has_value(); });
- if (it != m_open_files.end())
- {
- *it = file_description;
- return static_cast<int>(it - m_open_files.begin());
- }
-
- m_open_files.push_back(file_description);
- return static_cast<int>(m_open_files.size() - 1);
- }
-
- auto file_descriptor_table::get_file(int fd) const -> std::optional<open_file_description>
- {
- if (fd < 0)
- {
- return std::nullopt;
- }
-
- auto const index = static_cast<size_t>(fd);
- if (index >= m_open_files.size() || !m_open_files.at(fd).has_value())
- {
- return std::nullopt;
- }
-
- return m_open_files.at(fd);
- }
-
- auto file_descriptor_table::remove_file(int fd) -> void
- {
- if (fd < 0)
- {
- return;
- }
-
- auto const index = static_cast<size_t>(fd);
- if (index >= m_open_files.size())
- {
- return;
- }
-
- m_open_files.at(fd).reset();
- }
-} // namespace filesystem \ No newline at end of file