aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/include/kernel/filesystem/inode.hpp3
-rw-r--r--kernel/src/filesystem/ext2/filesystem.cpp41
2 files changed, 31 insertions, 13 deletions
diff --git a/kernel/include/kernel/filesystem/inode.hpp b/kernel/include/kernel/filesystem/inode.hpp
index d97b5ab..59207df 100644
--- a/kernel/include/kernel/filesystem/inode.hpp
+++ b/kernel/include/kernel/filesystem/inode.hpp
@@ -25,7 +25,8 @@ namespace kernel::filesystem
[[nodiscard]] auto is_regular() const -> bool;
[[nodiscard]] auto is_device() const -> bool;
- private:
+ // TODO BA-FS26 improve inode_kind really needed?
+ public:
inode_kind m_kind{inode_kind::regular};
};
} // namespace kernel::filesystem
diff --git a/kernel/src/filesystem/ext2/filesystem.cpp b/kernel/src/filesystem/ext2/filesystem.cpp
index d650e97..31dc6f2 100644
--- a/kernel/src/filesystem/ext2/filesystem.cpp
+++ b/kernel/src/filesystem/ext2/filesystem.cpp
@@ -26,18 +26,18 @@ namespace kernel::filesystem::ext2
constexpr uint32_t ROOT_INODE_NUMBER = 2;
// Mode bits
- // constexpr uint16_t S_IFMT = 0xF000;
- // constexpr uint16_t S_IFREG = 0x8000;
- // constexpr uint16_t S_IFDIR = 0x4000;
-
- // auto S_ISREG(uint16_t mode) -> bool
- // {
- // return (mode & S_IFMT) == S_IFREG;
- // }
- // auto S_ISDIR(uint16_t mode) -> bool
- // {
- // return (mode & S_IFMT) == S_IFDIR;
- // }
+ constexpr uint16_t S_IFMT = 0xF000;
+ constexpr uint16_t S_IFREG = 0x8000;
+ constexpr uint16_t S_IFDIR = 0x4000;
+
+ auto S_ISREG(uint16_t mode) -> bool
+ {
+ return (mode & S_IFMT) == S_IFREG;
+ }
+ auto S_ISDIR(uint16_t mode) -> bool
+ {
+ return (mode & S_IFMT) == S_IFDIR;
+ }
} // namespace
auto filesystem::mount(kstd::shared_ptr<kapi::devices::device> const & device) -> int
@@ -63,6 +63,7 @@ namespace kernel::filesystem::ext2
num_block_groups * sizeof(block_group_descriptor));
m_root_inode = read_inode(ROOT_INODE_NUMBER);
+ // TODO BA-FS26 check if root inode is valid and is a directory ??
return 0;
}
@@ -98,6 +99,22 @@ namespace kernel::filesystem::ext2
auto new_inode = kstd::make_shared<inode>();
kernel::devices::block_device_utils::read(m_device, &new_inode->m_data, inode_offset, sizeof(inode_data));
+
+ // TODO BA-FS26 improve inode_kind really needed? or just map it to the mode bits?
+ if (S_ISREG(new_inode->m_data.mode))
+ {
+ new_inode->m_kind = inode::inode_kind::regular;
+ }
+ else if (S_ISDIR(new_inode->m_data.mode))
+ {
+ new_inode->m_kind = inode::inode_kind::directory;
+ }
+ else
+ {
+ // TODO BA-FS26 really correct??
+ return nullptr;
+ }
+
return new_inode;
}