diff options
Diffstat (limited to 'kernel/include')
| -rw-r--r-- | kernel/include/kernel/filesystem/file_descriptor_table.hpp | 64 | ||||
| -rw-r--r-- | kernel/include/kernel/filesystem/open_file_descriptor.hpp (renamed from kernel/include/kernel/filesystem/open_file_description.hpp) | 24 | ||||
| -rw-r--r-- | kernel/include/kernel/filesystem/open_file_table.hpp | 63 | ||||
| -rw-r--r-- | kernel/include/kernel/filesystem/vfs.hpp | 1 | ||||
| -rw-r--r-- | kernel/include/kernel/test_support/filesystem/file_descriptor_table.hpp | 10 | ||||
| -rw-r--r-- | kernel/include/kernel/test_support/filesystem/open_file_table.hpp | 10 |
6 files changed, 85 insertions, 87 deletions
diff --git a/kernel/include/kernel/filesystem/file_descriptor_table.hpp b/kernel/include/kernel/filesystem/file_descriptor_table.hpp deleted file mode 100644 index 293dc36..0000000 --- a/kernel/include/kernel/filesystem/file_descriptor_table.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef TEACH_OS_KERNEL_FILESYSTEM_FILE_DESCRIPTOR_TABLE_HPP -#define TEACH_OS_KERNEL_FILESYSTEM_FILE_DESCRIPTOR_TABLE_HPP - -#include <kernel/filesystem/open_file_description.hpp> - -#include <kstd/memory> -#include <kstd/vector> - -namespace kernel::filesystem -{ - /** - @brief A table for managing file descriptors in the filesystem. This class provides methods for adding, retrieving, - and removing open file descriptions. - */ - struct file_descriptor_table - { - /** - @brief Initialize the global file descriptor table. This method creates the singleton instance of the file - descriptor table. - @warning Panics if called more than once. - */ - auto static init() -> void; - - /** - @brief Get the global file descriptor table instance. - @return A reference to the global file descriptor table. - @warning Panics if the file descriptor table has not been initialized. - */ - auto static get() -> file_descriptor_table &; - - /** - @brief Destructor for the file descriptor table. - */ - ~file_descriptor_table() = default; - - /** - @brief Add a file to the descriptor table. - @param f The file description to add. - @return The file descriptor index assigned to the file, or -1 on failure. - */ - auto add_file(kstd::shared_ptr<open_file_description> const & f) -> int; - - /** - @brief Get a file from the descriptor table. - @param fd The file descriptor index to retrieve. - @return A pointer to the requested file description, or a null pointer if not found. - */ - [[nodiscard]] auto get_file(int fd) const -> kstd::shared_ptr<open_file_description>; - - /** - @brief Remove a file from the descriptor table. - @param fd The file descriptor index to remove. - @return 0 on success, or -1 on failure. - */ - auto remove_file(int fd) -> int; - - private: - file_descriptor_table() = default; - - kstd::vector<kstd::shared_ptr<open_file_description>> m_open_files{}; - }; -} // namespace kernel::filesystem - -#endif
\ No newline at end of file diff --git a/kernel/include/kernel/filesystem/open_file_description.hpp b/kernel/include/kernel/filesystem/open_file_descriptor.hpp index fad41e4..036dcf0 100644 --- a/kernel/include/kernel/filesystem/open_file_description.hpp +++ b/kernel/include/kernel/filesystem/open_file_descriptor.hpp @@ -1,5 +1,5 @@ -#ifndef TEACH_OS_KERNEL_FILESYSTEM_OPEN_FILE_DESCRIPTION_HPP -#define TEACH_OS_KERNEL_FILESYSTEM_OPEN_FILE_DESCRIPTION_HPP +#ifndef TEACH_OS_KERNEL_FILESYSTEM_OPEN_FILE_DESCRIPTOR_HPP +#define TEACH_OS_KERNEL_FILESYSTEM_OPEN_FILE_DESCRIPTOR_HPP #include <kernel/filesystem/inode.hpp> @@ -10,24 +10,24 @@ namespace kernel::filesystem { /** - @brief Represents an open file description in the filesystem. This class encapsulates the state of an open file, + @brief Represents an open file descriptor in the filesystem. This class encapsulates the state of an open file, including a reference to the associated inode and the current file offset. */ - struct open_file_description + struct open_file_descriptor { /** - @brief Constructs an open file description for the given @p inode. - @param inode The inode to associate with the open file description. + @brief Constructs an open file descriptor for the given @p inode. + @param inode The inode to associate with the open file descriptor. */ - explicit open_file_description(kstd::shared_ptr<inode> const & inode); + explicit open_file_descriptor(kstd::shared_ptr<inode> const & inode); /** - @brief Destructor for the open file description. + @brief Destructor for the open file descriptor. */ - ~open_file_description() = default; + ~open_file_descriptor() = default; /** - @brief Reads data from the open file description into a @p buffer, starting at the current file offset and for a + @brief Reads data from the open file descriptor into a @p buffer, starting at the current file offset and for a given @p size. The file offset is advanced by the number of bytes read. @param buffer The buffer to read data into. @@ -37,7 +37,7 @@ namespace kernel::filesystem auto read(void * buffer, size_t size) -> size_t; /** - @brief Writes data to the open file description from a @p buffer, starting at the current file offset and for a + @brief Writes data to the open file descriptor from a @p buffer, starting at the current file offset and for a given @p size. The file offset is advanced by the number of bytes written. @param buffer The buffer to write data from. @@ -47,7 +47,7 @@ namespace kernel::filesystem auto write(void const * buffer, size_t size) -> size_t; /** - @brief Returns the current file offset for this open file description. + @brief Returns the current file offset for this open file descriptor. @return The current file offset in bytes. */ [[nodiscard]] auto offset() const -> size_t; diff --git a/kernel/include/kernel/filesystem/open_file_table.hpp b/kernel/include/kernel/filesystem/open_file_table.hpp new file mode 100644 index 0000000..2f9a421 --- /dev/null +++ b/kernel/include/kernel/filesystem/open_file_table.hpp @@ -0,0 +1,63 @@ +#ifndef TEACH_OS_KERNEL_FILESYSTEM_OPEN_FILE_TABLE_HPP +#define TEACH_OS_KERNEL_FILESYSTEM_OPEN_FILE_TABLE_HPP + +#include <kernel/filesystem/open_file_descriptor.hpp> + +#include <kstd/memory> +#include <kstd/vector> + +namespace kernel::filesystem +{ + /** + @brief A table for managing file descriptors in the filesystem. This class provides methods for adding, retrieving, + and removing open file descriptors. + */ + struct open_file_table + { + /** + @brief Initialize the global open file table. This method creates the singleton instance of the open file table. + @warning Panics if called more than once. + */ + auto static init() -> void; + + /** + @brief Get the global open file table instance. + @return A reference to the global open file table. + @warning Panics if the open file table has not been initialized. + */ + auto static get() -> open_file_table &; + + /** + @brief Destructor for the open file table. + */ + ~open_file_table() = default; + + /** + @brief Add a file to the open file table. + @param f The file descriptor to add. + @return The file descriptor index assigned to the file, or -1 on failure. + */ + auto add_file(kstd::shared_ptr<open_file_descriptor> const & f) -> int; + + /** + @brief Get a file from the open file table. + @param fd The file descriptor index to retrieve. + @return A pointer to the requested file descriptor, or a null pointer if not found. + */ + [[nodiscard]] auto get_file(int fd) const -> kstd::shared_ptr<open_file_descriptor>; + + /** + @brief Remove a file from the open file table. + @param fd The file descriptor index to remove. + @return 0 on success, or -1 on failure. + */ + auto remove_file(int fd) -> int; + + private: + open_file_table() = default; + + kstd::vector<kstd::shared_ptr<open_file_descriptor>> m_open_files{}; + }; +} // namespace kernel::filesystem + +#endif
\ No newline at end of file diff --git a/kernel/include/kernel/filesystem/vfs.hpp b/kernel/include/kernel/filesystem/vfs.hpp index 5b5c868..881f458 100644 --- a/kernel/include/kernel/filesystem/vfs.hpp +++ b/kernel/include/kernel/filesystem/vfs.hpp @@ -4,7 +4,6 @@ #include <kernel/filesystem/dentry.hpp> #include <kernel/filesystem/filesystem.hpp> #include <kernel/filesystem/mount_table.hpp> -#include <kernel/filesystem/open_file_description.hpp> #include <kstd/memory> diff --git a/kernel/include/kernel/test_support/filesystem/file_descriptor_table.hpp b/kernel/include/kernel/test_support/filesystem/file_descriptor_table.hpp deleted file mode 100644 index bbc0f4a..0000000 --- a/kernel/include/kernel/test_support/filesystem/file_descriptor_table.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef TEACHOS_KERNEL_TEST_SUPPORT_FILESYSTEM_FILE_DESCRIPTOR_TABLE_HPP -#define TEACHOS_KERNEL_TEST_SUPPORT_FILESYSTEM_FILE_DESCRIPTOR_TABLE_HPP - -namespace kernel::tests::filesystem::file_descriptor_table -{ - //! Deinitialize the file descriptor table singleton. - auto deinit() -> void; -} // namespace kernel::tests::filesystem::file_descriptor_table - -#endif
\ No newline at end of file diff --git a/kernel/include/kernel/test_support/filesystem/open_file_table.hpp b/kernel/include/kernel/test_support/filesystem/open_file_table.hpp new file mode 100644 index 0000000..46b0334 --- /dev/null +++ b/kernel/include/kernel/test_support/filesystem/open_file_table.hpp @@ -0,0 +1,10 @@ +#ifndef TEACHOS_KERNEL_TEST_SUPPORT_FILESYSTEM_OPEN_FILE_TABLE_HPP +#define TEACHOS_KERNEL_TEST_SUPPORT_FILESYSTEM_OPEN_FILE_TABLE_HPP + +namespace kernel::tests::filesystem::open_file_table +{ + //! Deinitialize the open file table singleton. + auto deinit() -> void; +} // namespace kernel::tests::filesystem::open_file_table + +#endif
\ No newline at end of file |
