diff options
Diffstat (limited to 'kernel/filesystem/src')
| -rw-r--r-- | kernel/filesystem/src/file_descriptor_table.cpp | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/kernel/filesystem/src/file_descriptor_table.cpp b/kernel/filesystem/src/file_descriptor_table.cpp index 645da9f..286678c 100644 --- a/kernel/filesystem/src/file_descriptor_table.cpp +++ b/kernel/filesystem/src/file_descriptor_table.cpp @@ -37,29 +37,27 @@ namespace filesystem auto file_descriptor_table::add_file(open_file_description & f) -> int { - auto it = std::ranges::find(m_open_files, nullptr); + auto it = std::ranges::find_if(m_open_files, [](auto & open_file) { return !open_file.has_value(); }); if (it != m_open_files.end()) { - *it = &f; + *it = f; return static_cast<int>(it - m_open_files.begin()); } return -1; } - auto file_descriptor_table::get_file(int fd) -> open_file_description & + auto file_descriptor_table::get_file(int fd) -> std::optional<open_file_description> { - // TODO BA-FS26 do not panic, its an user error if (fd < 0) { - kapi::system::panic("[FILESYSTEM] get_file called with negative descriptor."); + return std::nullopt; } - // TODO BA-FS26 do not panic, its an user error auto const index = static_cast<size_t>(fd); - if (index >= m_open_files.size() || m_open_files[index] == nullptr) + if (index >= m_open_files.size() || !m_open_files[index].has_value()) { - kapi::system::panic("[FILESYSTEM] get_file called with invalid descriptor."); + return std::nullopt; } return *m_open_files[index]; @@ -67,21 +65,17 @@ namespace filesystem auto file_descriptor_table::remove_file(int fd) -> void { - // TODO BA-FS26 do not panic, its an user error if (fd < 0) { - kapi::system::panic("[FILESYSTEM] remove_file called with negative descriptor."); + return; } - // TODO BA-FS26 do not panic, its an user error auto const index = static_cast<size_t>(fd); if (index >= m_open_files.size()) { - kapi::system::panic("[FILESYSTEM] remove_file called with out-of-range descriptor."); + return; } - // TODO BA-FS26 - // delete m_open_files[index]; - m_open_files[index] = nullptr; + m_open_files[index].reset(); } } // namespace filesystem
\ No newline at end of file |
