aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/filesystem/ext2/filesystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/filesystem/ext2/filesystem.cpp')
-rw-r--r--kernel/src/filesystem/ext2/filesystem.cpp38
1 files changed, 12 insertions, 26 deletions
diff --git a/kernel/src/filesystem/ext2/filesystem.cpp b/kernel/src/filesystem/ext2/filesystem.cpp
index 6d5960e..0ad5c97 100644
--- a/kernel/src/filesystem/ext2/filesystem.cpp
+++ b/kernel/src/filesystem/ext2/filesystem.cpp
@@ -21,29 +21,14 @@ namespace kernel::filesystem::ext2
{
namespace
{
- constexpr size_t SUPERBLOCK_OFFSET = 1024;
- constexpr uint16_t MAGIC_NUMBER = 0xEF53;
-
- constexpr uint32_t ROOT_INODE_NUMBER = 2;
-
- constexpr size_t DIRECT_BLOCK_COUNT = 12;
- constexpr size_t SINGLY_INDIRECT_BLOCK_INDEX = DIRECT_BLOCK_COUNT;
- constexpr size_t DOUBLY_INDIRECT_BLOCK_INDEX = SINGLY_INDIRECT_BLOCK_INDEX + 1;
- constexpr size_t TRIPLY_INDIRECT_BLOCK_INDEX = DOUBLY_INDIRECT_BLOCK_INDEX + 1;
-
- // 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;
+ return (mode & constants::mode_mask) == constants::mode_regular;
}
auto S_ISDIR(uint16_t mode) -> bool
{
- return (mode & S_IFMT) == S_IFDIR;
+ return (mode & constants::mode_mask) == constants::mode_directory;
}
} // namespace
@@ -51,9 +36,10 @@ namespace kernel::filesystem::ext2
{
kernel::filesystem::filesystem::mount(device);
- kernel::devices::block_device_utils::read(m_device, &m_superblock, SUPERBLOCK_OFFSET, sizeof(m_superblock));
+ kernel::devices::block_device_utils::read(m_device, &m_superblock, constants::superblock_offset,
+ sizeof(m_superblock));
- if (m_superblock.magic != MAGIC_NUMBER)
+ if (m_superblock.magic != constants::magic_number)
{
return operation_result::invalid_magic_number;
}
@@ -69,7 +55,7 @@ namespace kernel::filesystem::ext2
block_group_descriptor_table_offset,
num_block_groups * sizeof(block_group_descriptor));
- m_root_inode = read_inode(ROOT_INODE_NUMBER);
+ m_root_inode = read_inode(constants::root_inode_number);
if (!m_root_inode || !m_root_inode->is_directory())
{
@@ -161,11 +147,11 @@ namespace kernel::filesystem::ext2
auto filesystem::map_inode_block_index_to_global_block_number(uint32_t inode_block_index, inode_data data) -> uint32_t
{
- if (inode_block_index < DIRECT_BLOCK_COUNT)
+ if (inode_block_index < constants::direct_block_count)
{
return data.block.at(inode_block_index);
}
- inode_block_index -= DIRECT_BLOCK_COUNT;
+ inode_block_index -= constants::direct_block_count;
auto const block_size = get_block_size();
auto const numbers_per_block = block_size / sizeof(uint32_t);
@@ -176,14 +162,14 @@ namespace kernel::filesystem::ext2
if (inode_block_index < block_numbers_per_singly_indirect_block)
{
- auto const singly_indirect_block_number = data.block.at(SINGLY_INDIRECT_BLOCK_INDEX);
+ auto const singly_indirect_block_number = data.block.at(constants::singly_indirect_block_index);
return read_block_number_at_index(singly_indirect_block_number, inode_block_index);
}
inode_block_index -= block_numbers_per_singly_indirect_block;
if (inode_block_index < block_numbers_per_doubly_indirect_block)
{
- auto const doubly_indirect_block_number = data.block.at(DOUBLY_INDIRECT_BLOCK_INDEX);
+ auto const doubly_indirect_block_number = data.block.at(constants::doubly_indirect_block_index);
auto const singly_indirect_block_index_in_doubly_indirect_block =
inode_block_index / block_numbers_per_singly_indirect_block;
auto const singly_indirect_block_number = read_block_number_at_index(
@@ -196,7 +182,7 @@ namespace kernel::filesystem::ext2
if (inode_block_index < block_numbers_per_triply_indirect_block)
{
- auto const triply_indirect_block_number = data.block.at(TRIPLY_INDIRECT_BLOCK_INDEX);
+ auto const triply_indirect_block_number = data.block.at(constants::triply_indirect_block_index);
auto const doubly_indirect_block_index_in_triply_indirect_block =
inode_block_index / block_numbers_per_doubly_indirect_block;
auto const doubly_indirect_block_number = read_block_number_at_index(
@@ -230,7 +216,7 @@ namespace kernel::filesystem::ext2
auto filesystem::get_block_size() -> size_t
{
- return 1024U << m_superblock.log_block_size;
+ return constants::base_block_size << m_superblock.log_block_size;
}
auto filesystem::get_inode_size() -> size_t