aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-22 12:23:56 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-22 12:26:00 +0200
commit984d20ec8cb734cb47fb1ff5d34861eaf9f4aa32 (patch)
treedba1a8546397ef25bbdf9755cd944091b8137d33
parent994539e1cd983d9aa512dad7be84adb8d364bd64 (diff)
downloadkernel-984d20ec8cb734cb47fb1ff5d34861eaf9f4aa32.tar.xz
kernel-984d20ec8cb734cb47fb1ff5d34861eaf9f4aa32.zip
kapi/fs: add file status and type types.
-rw-r--r--kapi/kapi/filesystem.hpp2
-rw-r--r--kapi/kapi/filesystem/file_status.hpp26
-rw-r--r--kapi/kapi/filesystem/file_type.hpp46
3 files changed, 74 insertions, 0 deletions
diff --git a/kapi/kapi/filesystem.hpp b/kapi/kapi/filesystem.hpp
index b64d251d..2b5dc827 100644
--- a/kapi/kapi/filesystem.hpp
+++ b/kapi/kapi/filesystem.hpp
@@ -2,6 +2,8 @@
#define TEACHOS_KAPI_FILESYSTEM_HPP
#include <kapi/filesystem/device_number.hpp> // IWYU pragma: export
+#include <kapi/filesystem/file_status.hpp> // IWYU pragma: export
+#include <kapi/filesystem/file_type.hpp> // IWYU pragma: export
#include <kstd/result.hpp>
#include <kstd/system_error.hpp>
diff --git a/kapi/kapi/filesystem/file_status.hpp b/kapi/kapi/filesystem/file_status.hpp
new file mode 100644
index 00000000..df48f9db
--- /dev/null
+++ b/kapi/kapi/filesystem/file_status.hpp
@@ -0,0 +1,26 @@
+#ifndef TEACH_KAPI_FILESYSTEM_FILE_STATUS_HPP
+#define TEACH_KAPI_FILESYSTEM_FILE_STATUS_HPP
+
+// IWYU pragma: private, include <kapi/filesystem.hpp>
+
+#include <kapi/filesystem/device_number.hpp>
+
+#include <kstd/units.hpp>
+
+#include <cstdint>
+
+namespace kapi::filesystem
+{
+
+ struct file_status
+ {
+ std::uint32_t mode{};
+ kstd::units::bytes size{};
+ device_number raw_device{};
+ std::uint64_t inode_number{};
+ std::uint32_t link_count{};
+ };
+
+} // namespace kapi::filesystem
+
+#endif
diff --git a/kapi/kapi/filesystem/file_type.hpp b/kapi/kapi/filesystem/file_type.hpp
new file mode 100644
index 00000000..cb346b71
--- /dev/null
+++ b/kapi/kapi/filesystem/file_type.hpp
@@ -0,0 +1,46 @@
+#ifndef TEACH_KAPI_FILESYSTEM_FILE_TYPE_HPP
+#define TEACH_KAPI_FILESYSTEM_FILE_TYPE_HPP
+
+// IWYU pragma: private, include <kapi/filesystem.hpp>
+
+#include <cstdint>
+
+namespace kapi::filesystem
+{
+
+ enum struct file_type : std::uint32_t
+ {
+ fifo = 0x1000,
+ character_device = 0x2000,
+ directory = 0x4000,
+ block_device = 0x6000,
+ regular = 0x8000,
+ symbolic_link = 0xa000,
+ socket = 0xc000,
+ };
+
+ constexpr auto inline file_type_mask = std::uint32_t{0xf000};
+
+ [[nodiscard]] constexpr auto inline is_block_device(std::uint32_t mode) noexcept -> bool
+ {
+ return static_cast<file_type>(mode & file_type_mask) == file_type::block_device;
+ }
+
+ [[nodiscard]] constexpr auto inline is_character_device(std::uint32_t mode) noexcept -> bool
+ {
+ return static_cast<file_type>(mode & file_type_mask) == file_type::character_device;
+ }
+
+ [[nodiscard]] constexpr auto inline is_directory(std::uint32_t mode) noexcept -> bool
+ {
+ return static_cast<file_type>(mode & file_type_mask) == file_type::directory;
+ }
+
+ [[nodiscard]] constexpr auto inline is_regular(std::uint32_t mode) noexcept -> bool
+ {
+ return static_cast<file_type>(mode & file_type_mask) == file_type::regular;
+ }
+
+} // namespace kapi::filesystem
+
+#endif