From 1e24d2b3cd4315fff4177c593bcfeef5b354f612 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 29 Aug 2026 10:32:29 +0200 Subject: chore: apply stylistic cleanups --- arch/x86_64/arch/cpu/task_state_segment.hpp | 30 ++++---- arch/x86_64/kapi/devices.cpp | 3 +- kapi/kapi/capabilities/facet_id.hpp | 2 +- kapi/kapi/devices/bus.hpp | 2 +- kapi/kapi/devices/device_registry.hpp | 2 +- kapi/kapi/filesystem.hpp | 8 +- kapi/kapi/filesystem/block_special_file.hpp | 2 +- kapi/kapi/memory/frame.hpp | 2 +- kapi/kapi/memory/page.hpp | 2 +- kapi/kapi/system.hpp | 2 +- kernel/kapi/devices/bus.cpp | 2 +- kernel/kapi/devices/device_registry.cpp | 2 +- kernel/kapi/filesystem.cpp | 8 +- kernel/kapi/filesystem.tests.cpp | 3 +- kernel/kernel/devices/block_device_utils.cpp | 4 +- kernel/kernel/devices/block_device_utils.hpp | 2 +- kernel/kernel/devices/block_device_utils.tests.cpp | 10 +-- .../filesystems/ext2/block_group_descriptor.hpp | 16 ++-- kernel/kernel/filesystems/ext2/filesystem.cpp | 65 ++++++++-------- kernel/kernel/filesystems/ext2/filesystem.hpp | 49 ++++++------ .../kernel/filesystems/ext2/filesystem.tests.cpp | 26 +++---- kernel/kernel/filesystems/ext2/inode.cpp | 8 +- kernel/kernel/filesystems/ext2/inode.hpp | 44 +++++------ kernel/kernel/filesystems/ext2/inode.tests.cpp | 33 ++++---- .../filesystems/ext2/linked_directory_entry.hpp | 8 +- kernel/kernel/filesystems/ext2/superblock.hpp | 90 +++++++++++----------- kernel/kernel/main.cpp | 2 +- .../kernel/test_support/devices/block_device.cpp | 5 +- .../kernel/test_support/devices/block_device.hpp | 6 +- kernel/kernel/test_support/filesystems/ext2.cpp | 6 +- kernel/kernel/test_support/filesystems/ext2.hpp | 2 +- .../vfs/storage_boot_module_fixture.cpp | 2 +- kernel/kernel/vfs/constants.hpp | 6 +- kernel/kernel/vfs/dentry.cpp | 6 +- kernel/kernel/vfs/dentry.hpp | 4 +- kernel/kernel/vfs/device_inode.tests.cpp | 2 +- kernel/kernel/vfs/mount.cpp | 2 +- kernel/kernel/vfs/mount.hpp | 4 +- kernel/kernel/vfs/open_file_table.cpp | 4 +- kernel/kernel/vfs/open_file_table.hpp | 4 +- libs/kstd/kstd/allocator.hpp | 2 +- .../kstd/bits/format/formatter/string_view.hpp | 2 +- libs/kstd/kstd/bits/format/string.hpp | 2 +- libs/kstd/kstd/bits/shared_ptr.hpp | 6 +- libs/multiboot2/multiboot2/information.hpp | 4 +- 45 files changed, 252 insertions(+), 244 deletions(-) diff --git a/arch/x86_64/arch/cpu/task_state_segment.hpp b/arch/x86_64/arch/cpu/task_state_segment.hpp index 57729dd6..373fb8af 100644 --- a/arch/x86_64/arch/cpu/task_state_segment.hpp +++ b/arch/x86_64/arch/cpu/task_state_segment.hpp @@ -8,21 +8,21 @@ namespace arch::cpu struct [[gnu::packed]] task_state_segment { - uint32_t : 32; - uint64_t rsp0 = {}; - uint64_t rsp1 = {}; - uint64_t rsp2 = {}; - uint64_t : 64; - uint64_t ist1 = {}; - uint64_t ist2 = {}; - uint64_t ist3 = {}; - uint64_t ist4 = {}; - uint64_t ist5 = {}; - uint64_t ist6 = {}; - uint64_t ist7 = {}; - uint64_t : 64; - uint16_t : 16; - uint16_t io_map_base_address = {}; + std::uint32_t : 32; + std::uint64_t rsp0 = {}; + std::uint64_t rsp1 = {}; + std::uint64_t rsp2 = {}; + std::uint64_t : 64; + std::uint64_t ist1 = {}; + std::uint64_t ist2 = {}; + std::uint64_t ist3 = {}; + std::uint64_t ist4 = {}; + std::uint64_t ist5 = {}; + std::uint64_t ist6 = {}; + std::uint64_t ist7 = {}; + std::uint64_t : 64; + std::uint16_t : 16; + std::uint16_t io_map_base_address = {}; }; } // namespace arch::cpu diff --git a/arch/x86_64/kapi/devices.cpp b/arch/x86_64/kapi/devices.cpp index 888b6e20..1e2fedd6 100644 --- a/arch/x86_64/kapi/devices.cpp +++ b/arch/x86_64/kapi/devices.cpp @@ -11,6 +11,7 @@ #include #include +#include namespace kapi::devices { @@ -39,7 +40,7 @@ namespace kapi::devices { auto instance = driver->make_instance(); kstd::println("[x86_64:DRV] registering driver '{}' ({})", instance->name(), driver->name()); - kapi::devices::driver_registry::get().add(driver->make_instance()); + kapi::devices::driver_registry::get().add(std::move(instance)); } } diff --git a/kapi/kapi/capabilities/facet_id.hpp b/kapi/kapi/capabilities/facet_id.hpp index 820814be..bb6de9c1 100644 --- a/kapi/kapi/capabilities/facet_id.hpp +++ b/kapi/kapi/capabilities/facet_id.hpp @@ -22,7 +22,7 @@ namespace kapi::capabilities {} //! Get the name of this facet. - [[nodiscard]] constexpr auto name() const noexcept -> std::string_view const & + [[nodiscard]] constexpr auto name() const noexcept -> std::string_view { return m_name; } diff --git a/kapi/kapi/devices/bus.hpp b/kapi/kapi/devices/bus.hpp index 3a0ba6a6..365d5c6c 100644 --- a/kapi/kapi/devices/bus.hpp +++ b/kapi/kapi/devices/bus.hpp @@ -44,7 +44,7 @@ namespace kapi::devices //! Whenever a device is attached to a bus, the bus takes sole ownership of the device. //! //! @param child The child device to attach. - auto add_child(kstd::shared_ptr child) -> void; + auto add_child(kstd::shared_ptr const & child) -> void; //! Detach a child device from this bus and tear it down. //! diff --git a/kapi/kapi/devices/device_registry.hpp b/kapi/kapi/devices/device_registry.hpp index 816ad984..346b9a10 100644 --- a/kapi/kapi/devices/device_registry.hpp +++ b/kapi/kapi/devices/device_registry.hpp @@ -55,7 +55,7 @@ namespace kapi::devices //! //! @param device The device to register. //! @return true if the device was registered successfully, false otherwise. - auto add(kstd::shared_ptr device) -> bool; + auto add(kstd::shared_ptr const & device) -> bool; //! Remove a device from the kernel's device registry. //! diff --git a/kapi/kapi/filesystem.hpp b/kapi/kapi/filesystem.hpp index cd687c45..99466dfd 100644 --- a/kapi/kapi/filesystem.hpp +++ b/kapi/kapi/filesystem.hpp @@ -54,21 +54,21 @@ namespace kapi::filesystem //! //! @param file_descriptor The file descriptor to close. //! @return Nothing on success, an error code otherwise . - auto close(size_t file_descriptor) -> kstd::result; + auto close(std::size_t file_descriptor) -> kstd::result; //! Read bytes from a file into a given buffer. //! //! @param file_descriptor The file descriptor to read from. //! @param buffer The buffer to store the read data. //! @return The number of bytes read on success, an error code otherwise. - auto read(size_t file_descriptor, std::span buffer) -> kstd::result; + auto read(std::size_t file_descriptor, std::span buffer) -> kstd::result; //! Write bytes from a given buffer to a file descriptor. //! //! @param file_descriptor The file descriptor to write to. //! @param buffer The buffer containing the data to write. //! @return The number of bytes written on success, an error code otherwise. - auto write(size_t file_descriptor, std::span buffer) -> kstd::result; + auto write(std::size_t file_descriptor, std::span buffer) -> kstd::result; //! Adjust the current position in the file. //! @@ -76,7 +76,7 @@ namespace kapi::filesystem //! @param offset The offset to seek to, relative to the origin. //! @param origin The origing to seek relatively to. //! @return The new position in the file on success, an error code otherwise. - auto seek(size_t file_descriptor, kstd::offset offset, seek_origin origin) -> kstd::result; + auto seek(std::size_t file_descriptor, kstd::offset offset, seek_origin origin) -> kstd::result; //! Create a new directory at the specified path. //! diff --git a/kapi/kapi/filesystem/block_special_file.hpp b/kapi/kapi/filesystem/block_special_file.hpp index daf4a97b..79a52817 100644 --- a/kapi/kapi/filesystem/block_special_file.hpp +++ b/kapi/kapi/filesystem/block_special_file.hpp @@ -33,7 +33,7 @@ namespace kapi::filesystem //! @param block_index The number of the block to read from. //! @param buffer The buffer to read into. //! @return The number of bytes read on success, an error otherwise. - [[nodiscard]] auto virtual read_block(size_t block_index, std::span buffer) + [[nodiscard]] auto virtual read_block(std::size_t block_index, std::span buffer) -> kstd::result = 0; //! Write data from a buffer into a block. diff --git a/kapi/kapi/memory/frame.hpp b/kapi/kapi/memory/frame.hpp index aafca5c7..bfb0d91a 100644 --- a/kapi/kapi/memory/frame.hpp +++ b/kapi/kapi/memory/frame.hpp @@ -21,7 +21,7 @@ namespace kapi::memory { frame() = default; - frame(std::size_t number) + explicit frame(std::size_t number) : chunk{number} {} diff --git a/kapi/kapi/memory/page.hpp b/kapi/kapi/memory/page.hpp index 2a609833..e1c7d528 100644 --- a/kapi/kapi/memory/page.hpp +++ b/kapi/kapi/memory/page.hpp @@ -22,7 +22,7 @@ namespace kapi::memory { page() = default; - page(std::size_t number) + explicit page(std::size_t number) : chunk{number} {} diff --git a/kapi/kapi/system.hpp b/kapi/kapi/system.hpp index f7dd4d7c..80233507 100644 --- a/kapi/kapi/system.hpp +++ b/kapi/kapi/system.hpp @@ -30,7 +30,7 @@ namespace kapi::system , location{location} {} - consteval panic_format_string(std::string_view const & format, + consteval panic_format_string(std::string_view format, std::source_location location = std::source_location::current()) : format{format} , location{location} diff --git a/kernel/kapi/devices/bus.cpp b/kernel/kapi/devices/bus.cpp index e4b5a2c5..300151d5 100644 --- a/kernel/kapi/devices/bus.cpp +++ b/kernel/kapi/devices/bus.cpp @@ -34,7 +34,7 @@ namespace kapi::devices } } - auto bus::add_child(kstd::shared_ptr child) -> void + auto bus::add_child(kstd::shared_ptr const & child) -> void { { auto guard = kstd::lock_guard{m_lock}; diff --git a/kernel/kapi/devices/device_registry.cpp b/kernel/kapi/devices/device_registry.cpp index 080ae39b..09da35ae 100644 --- a/kernel/kapi/devices/device_registry.cpp +++ b/kernel/kapi/devices/device_registry.cpp @@ -42,7 +42,7 @@ namespace kapi::devices return *instance; } - auto device_registry::add(kstd::shared_ptr device) -> bool + auto device_registry::add(kstd::shared_ptr const & device) -> bool { if (!device) { diff --git a/kernel/kapi/filesystem.cpp b/kernel/kapi/filesystem.cpp index 2f3c524e..8ebda7cc 100644 --- a/kernel/kapi/filesystem.cpp +++ b/kernel/kapi/filesystem.cpp @@ -38,7 +38,7 @@ namespace kapi::filesystem .and_then([](auto file_descriptor) { return kernel::vfs::open_file_table::get().add_file(file_descriptor); }); } - auto close(size_t file_descriptor) -> kstd::result + auto close(std::size_t file_descriptor) -> kstd::result { return kernel::vfs::open_file_table::get() .file(file_descriptor) @@ -47,21 +47,21 @@ namespace kapi::filesystem .and_then([=]() { return kernel::vfs::open_file_table::get().remove_file(file_descriptor); }); } - auto read(size_t file_descriptor, std::span buffer) -> kstd::result + auto read(std::size_t file_descriptor, std::span buffer) -> kstd::result { return kernel::vfs::open_file_table::get().file(file_descriptor).and_then([=](auto descriptor) { return descriptor->read(buffer); }); } - auto write(size_t file_descriptor, std::span buffer) -> kstd::result + auto write(std::size_t file_descriptor, std::span buffer) -> kstd::result { return kernel::vfs::open_file_table::get().file(file_descriptor).and_then([=](auto descriptor) { return descriptor->write(buffer); }); } - auto seek(size_t file_descriptor, kstd::offset offset, seek_origin origin) -> kstd::result + auto seek(std::size_t file_descriptor, kstd::offset offset, seek_origin origin) -> kstd::result { return kernel::vfs::open_file_table::get().file(file_descriptor).and_then([=](auto file) { return file->seek(offset, origin); diff --git a/kernel/kapi/filesystem.tests.cpp b/kernel/kapi/filesystem.tests.cpp index 6fa2de3d..efcb4fd3 100644 --- a/kernel/kapi/filesystem.tests.cpp +++ b/kernel/kapi/filesystem.tests.cpp @@ -258,7 +258,8 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_vfs_fixture, "Kapi files auto read_buffer = std::vector(4); auto bytes_read = kapi::filesystem::read(*fd, read_buffer); - std::string_view buffer_as_str{reinterpret_cast(read_buffer.data()), static_cast(*bytes_read)}; + std::string_view buffer_as_str{reinterpret_cast(read_buffer.data()), + static_cast(*bytes_read)}; REQUIRE(buffer_as_str == "Test"); REQUIRE(kapi::filesystem::close(*fd)); diff --git a/kernel/kernel/devices/block_device_utils.cpp b/kernel/kernel/devices/block_device_utils.cpp index 398e5e2a..473df371 100644 --- a/kernel/kernel/devices/block_device_utils.cpp +++ b/kernel/kernel/devices/block_device_utils.cpp @@ -18,7 +18,7 @@ namespace kernel::devices::block_device_utils namespace { - using block_op = kstd::result (*)(size_t idx, kstd::bytes off, kstd::bytes len, kstd::bytes done, + using block_op = kstd::result (*)(std::size_t idx, kstd::bytes off, kstd::bytes len, kstd::bytes done, kapi::filesystem::block_special_file & device, std::span scratch, std::span buffer); @@ -64,7 +64,7 @@ namespace kernel::devices::block_device_utils } } // namespace - auto calculate_transfer(kapi::filesystem::block_special_file const & device, size_t block_index) -> transfer_info + auto calculate_transfer(kapi::filesystem::block_special_file const & device, std::size_t block_index) -> transfer_info { auto const offset = block_index * device.block_size(); auto const limit = device.capacity(); diff --git a/kernel/kernel/devices/block_device_utils.hpp b/kernel/kernel/devices/block_device_utils.hpp index b9c8c416..1fb7cd9d 100644 --- a/kernel/kernel/devices/block_device_utils.hpp +++ b/kernel/kernel/devices/block_device_utils.hpp @@ -21,7 +21,7 @@ namespace kernel::devices::block_device_utils kstd::bytes remainder; }; - [[nodiscard]] auto calculate_transfer(kapi::filesystem::block_special_file const & device, size_t block_index) + [[nodiscard]] auto calculate_transfer(kapi::filesystem::block_special_file const & device, std::size_t block_index) -> transfer_info; //! Read data from a block device into a given buffer. diff --git a/kernel/kernel/devices/block_device_utils.tests.cpp b/kernel/kernel/devices/block_device_utils.tests.cpp index 576c9284..9d90259b 100644 --- a/kernel/kernel/devices/block_device_utils.tests.cpp +++ b/kernel/kernel/devices/block_device_utils.tests.cpp @@ -23,7 +23,7 @@ SCENARIO("reading from a block device with block_device_utils", "[devices][block auto const block_size = 512_B; auto device = kstd::make_shared("test_block_device", block_size); kstd::vector block_data(block_size.value); - for (size_t i = 0; i < block_data.size(); ++i) + for (std::size_t i = 0; i < block_data.size(); ++i) { block_data[i] = static_cast(i % 256); } @@ -58,7 +58,7 @@ SCENARIO("reading from a block device with block_device_utils", "[devices][block THEN("the data read matches the expected data across block boundaries") { - for (size_t i = 0; i < bytes_read.value().value; ++i) + for (std::size_t i = 0; i < bytes_read.value().value; ++i) { auto expected_value = static_cast((256 + i) % 256); REQUIRE(read_buffer[i] == expected_value); @@ -101,7 +101,7 @@ SCENARIO("writing to a block device using block_device_utils", "[devices][block_ WHEN("writing to the block device using block_device_utils") { kstd::vector write_buffer(block_size.value); - for (size_t i = 0; i < write_buffer.size(); ++i) + for (std::size_t i = 0; i < write_buffer.size(); ++i) { write_buffer[i] = static_cast(i % 256); } @@ -124,7 +124,7 @@ SCENARIO("writing to a block device using block_device_utils", "[devices][block_ WHEN("writing over block boundaries") { kstd::vector write_buffer(2 * block_size.value); - for (size_t i = 0; i < write_buffer.size(); ++i) + for (std::size_t i = 0; i < write_buffer.size(); ++i) { write_buffer[i] = static_cast(i % 256); } @@ -141,7 +141,7 @@ SCENARIO("writing to a block device using block_device_utils", "[devices][block_ kstd::vector read_buffer(2 * block_size.value); auto bytes_read = kernel::devices::block_device_utils::read(*device, read_buffer, 256_B); - for (size_t i = 0; i < bytes_read.value().value; ++i) + for (std::size_t i = 0; i < bytes_read.value().value; ++i) { REQUIRE(read_buffer[i] == write_buffer[i]); } diff --git a/kernel/kernel/filesystems/ext2/block_group_descriptor.hpp b/kernel/kernel/filesystems/ext2/block_group_descriptor.hpp index dd9c3317..d447c855 100644 --- a/kernel/kernel/filesystems/ext2/block_group_descriptor.hpp +++ b/kernel/kernel/filesystems/ext2/block_group_descriptor.hpp @@ -9,14 +9,14 @@ namespace kernel::filesystems::ext2 //! A block group descriptor in the ext2 filesystem. struct [[gnu::packed]] block_group_descriptor { - uint32_t block_bitmap; - uint32_t inode_bitmap; - uint32_t inode_table; - uint16_t free_blocks_count; - uint16_t free_inodes_count; - uint16_t used_dirs_count; - std::array padding; - std::array reserved; // NOLINT(readability-magic-numbers) + std::uint32_t block_bitmap; + std::uint32_t inode_bitmap; + std::uint32_t inode_table; + std::uint16_t free_blocks_count; + std::uint16_t free_inodes_count; + std::uint16_t used_dirs_count; + std::array padding; + std::array reserved; // NOLINT(readability-magic-numbers) }; } // namespace kernel::filesystems::ext2 #endif \ No newline at end of file diff --git a/kernel/kernel/filesystems/ext2/filesystem.cpp b/kernel/kernel/filesystems/ext2/filesystem.cpp index 7eaeeba2..1785c0d7 100644 --- a/kernel/kernel/filesystems/ext2/filesystem.cpp +++ b/kernel/kernel/filesystems/ext2/filesystem.cpp @@ -47,8 +47,8 @@ namespace kernel::filesystems::ext2 { struct indirect_level { - uint32_t slot_index; - size_t capacity; + std::uint32_t slot_index; + std::size_t capacity; }; //! Check if the given bit has the bit at the given index set. @@ -57,7 +57,7 @@ namespace kernel::filesystems::ext2 //! //! @param bitmap The bitmap to check. //! @param index The index of the bit to check. - [[nodiscard]] constexpr auto bitmap_is_set(kstd::vector const & bitmap, size_t index) -> bool + [[nodiscard]] constexpr auto bitmap_is_set(kstd::vector const & bitmap, std::size_t index) -> bool { auto const byte_index = index / 8; auto const bit_index = index % 8; @@ -70,7 +70,7 @@ namespace kernel::filesystems::ext2 //! //! @param bitmap The bitmap to manipulate. //! @param index The index of the bit to set. - constexpr auto bitmap_set(kstd::vector & bitmap, size_t index) -> void + constexpr auto bitmap_set(kstd::vector & bitmap, std::size_t index) -> void { auto const byte_index = index / 8; auto const bit_index = index % 8; @@ -114,7 +114,7 @@ namespace kernel::filesystems::ext2 //! //! @param mode The mode to extract the type from. //! @return The file type encoded in the mode. - constexpr auto to_filetype(uint16_t mode) -> kapi::filesystem::file_type + constexpr auto to_filetype(std::uint16_t mode) -> kapi::filesystem::file_type { switch (mode & constants::mode_mask) { @@ -141,7 +141,7 @@ namespace kernel::filesystems::ext2 //! //! @param type The type to encode. //! @param mode The original ext2 file mode. - constexpr auto combine(kapi::filesystem::file_type type, uint16_t mode) -> uint16_t + constexpr auto combine(kapi::filesystem::file_type type, std::uint16_t mode) -> std::uint16_t { if (mode & constants::mode_mask) { @@ -210,7 +210,7 @@ namespace kernel::filesystems::ext2 std::string_view name, kapi::filesystem::file_type type) -> kstd::result { - auto const name_length = static_cast(name.size()); + auto const name_length = static_cast(name.size()); auto const record_size = (sizeof(linked_directory_entry) - 1 + name_length + 3u) & ~3u; if (buffer.size() - offset.value < record_size) { @@ -231,7 +231,7 @@ namespace kernel::filesystems::ext2 //! //! @param state The driver state to operate on. //! @return The revision level. - [[nodiscard]] constexpr auto revision_level(driver_state const & state) -> uint32_t + [[nodiscard]] constexpr auto revision_level(driver_state const & state) -> std::uint32_t { return state.superblock.rev_level; } @@ -251,7 +251,7 @@ namespace kernel::filesystems::ext2 //! @param buffer The buffer to read the block data into. //! @param state The state to operate on. //! @return The number of bytes read. - [[nodiscard]] auto read_block(uint32_t block_number, std::span buffer, driver_state const & state) + [[nodiscard]] auto read_block(std::uint32_t block_number, std::span buffer, driver_state const & state) -> kstd::result { if (buffer.size() < block_size(state).value) @@ -259,7 +259,7 @@ namespace kernel::filesystems::ext2 return kstd::failure(vfs::errc::invalid_argument); } - auto const block_offset = static_cast(block_number) * block_size(state); + auto const block_offset = static_cast(block_number) * block_size(state); return state.backing_inode->read(buffer, block_offset); } @@ -269,7 +269,7 @@ namespace kernel::filesystems::ext2 //! @param buffer The buffer containing the data to write. //! @param state The state to operate on. //! @return The number of bytes written. - [[nodiscard]] auto write_block(uint32_t block_number, std::span buffer, driver_state & state) + [[nodiscard]] auto write_block(std::uint32_t block_number, std::span buffer, driver_state & state) -> kstd::result { if (buffer.size() < block_size(state).value) @@ -277,7 +277,7 @@ namespace kernel::filesystems::ext2 return kstd::failure(vfs::errc::invalid_argument); } - auto const block_offset = static_cast(block_number) * block_size(state); + auto const block_offset = static_cast(block_number) * block_size(state); return state.backing_inode->write(buffer, block_offset); } @@ -286,7 +286,7 @@ namespace kernel::filesystems::ext2 //! @param state The driver state to operate on. //! @param batch The active write batch. //! @return An inode number on success, an error otherwise. - auto allocate_inode(driver_state & state, write_batch & batch) -> kstd::result + auto allocate_inode(driver_state & state, write_batch & batch) -> kstd::result { auto & superblock = state.superblock; auto & block_group_descriptors = state.block_group_descriptors; @@ -311,7 +311,7 @@ namespace kernel::filesystems::ext2 return kstd::failure(read_result.error()); } - for (auto i = 0uz; i < static_cast(superblock.inodes_per_group); ++i) + for (auto i = 0uz; i < static_cast(superblock.inodes_per_group); ++i) { if (!bitmap_is_set(inode_bitmap, i)) { @@ -375,7 +375,7 @@ namespace kernel::filesystems::ext2 } auto const file_type = to_filetype(mode); - auto const name_len = static_cast(name.size()); + auto const name_len = static_cast(name.size()); auto const needed_rec_len = static_cast((8u + name_len + 3u) & ~3u); auto * last_entry = reinterpret_cast(buffer.data() + offset); @@ -546,12 +546,12 @@ namespace kernel::filesystems::ext2 //! @param state The driver state to operate on. //! @return The block number at the given index in the given indirect block on success, an error otherwise. [[nodiscard]] auto read_block_number_at_index(std::uint32_t block, std::size_t index, driver_state const & state) - -> kstd::result + -> kstd::result { - uint32_t block_number_buffer = 0; + std::uint32_t block_number_buffer = 0; auto const block_offset = block * block_size(state); - auto const number_offset = block_offset + index * kstd::size_of(); + auto const number_offset = block_offset + index * kstd::size_of(); if (auto read_result = state.backing_inode->read(kstd::raw_bytes(block_number_buffer), number_offset); !read_result) @@ -778,7 +778,7 @@ namespace kernel::filesystems::ext2 return kstd::bytes{constants::base_block_size.value << state.superblock.log_block_size}; } - auto block_count(inode const & inode, driver_state const & state) -> uint32_t + auto block_count(inode const & inode, driver_state const & state) -> std::uint32_t { return inode.data().blocks / (2 << state.superblock.log_block_size); } @@ -799,9 +799,9 @@ namespace kernel::filesystems::ext2 { if (revision_level(state) > constants::good_old_revision && inode.is_regular()) { - inode.data().dir_acl = static_cast(new_size.value >> 32); + inode.data().dir_acl = static_cast(new_size.value >> 32); } - inode.data().size = static_cast(new_size.value); + inode.data().size = static_cast(new_size.value); } auto do_read(inode const & inode, std::span buffer, kstd::bytes offset, driver_state const & state) @@ -852,7 +852,8 @@ namespace kernel::filesystems::ext2 return bytes_read; } - auto allocate_blocks(size_t count, driver_state & state, write_batch & batch) -> kstd::result> + auto allocate_blocks(std::size_t count, driver_state & state, write_batch & batch) + -> kstd::result> { auto & superblock = state.superblock; auto & block_group_descriptors = state.block_group_descriptors; @@ -870,7 +871,7 @@ namespace kernel::filesystems::ext2 }; auto pending = kstd::vector{}; - auto allocated_blocks = kstd::vector{}; + auto allocated_blocks = kstd::vector{}; for (auto group_index = 0uz; group_index < block_group_descriptors.size() && allocated_blocks.size() < count; ++group_index) @@ -888,7 +889,8 @@ namespace kernel::filesystems::ext2 } auto claimed = 0uz; - for (auto i = 0uz; i < static_cast(superblock.blocks_per_group) && allocated_blocks.size() < count; ++i) + for (auto i = 0uz; i < static_cast(superblock.blocks_per_group) && allocated_blocks.size() < count; + ++i) { if (!bitmap_is_set(block_bitmap, i)) { @@ -925,12 +927,12 @@ namespace kernel::filesystems::ext2 return allocated_blocks; } - auto update_inode_block_count(inode_data & data, uint32_t delta, driver_state & state) -> void + auto update_inode_block_count(inode_data & data, std::uint32_t delta, driver_state & state) -> void { data.blocks += delta * (2 << state.superblock.log_block_size); } - auto write_inode(uint32_t inode_number, inode_data const & data, driver_state & state) -> kstd::result + auto write_inode(std::uint32_t inode_number, inode_data const & data, driver_state & state) -> kstd::result { if (auto inode_offset = calculate_inode_offset(inode_number, state)) { @@ -942,7 +944,8 @@ namespace kernel::filesystems::ext2 } } - auto inode_block_number(size_t index, inode const & inode, driver_state const & state) -> kstd::result + auto inode_block_number(std::size_t index, inode const & inode, driver_state const & state) + -> kstd::result { auto const & block_array = inode.data().block; @@ -1000,8 +1003,8 @@ namespace kernel::filesystems::ext2 return kstd::failure(errc::invalid_block_index); } - auto write_global_block_number_to_inode_block_index(size_t inode_block_index, inode_data & data, - uint32_t global_block_number, driver_state & state, + auto write_global_block_number_to_inode_block_index(std::size_t inode_block_index, inode_data & data, + std::uint32_t global_block_number, driver_state & state, write_batch & batch) -> kstd::result { if (inode_block_index < constants::direct_block_count) @@ -1055,7 +1058,7 @@ namespace kernel::filesystems::ext2 } } - auto const byte_offset = block_number * block_size + idx * kstd::size_of(); + auto const byte_offset = block_number * block_size + idx * kstd::size_of(); if (stride == 1) { @@ -1084,7 +1087,7 @@ namespace kernel::filesystems::ext2 } auto write_block_group_descriptor(block_group_descriptor const & block_group_descriptor, - size_t block_group_descriptor_index, driver_state const & state) + std::size_t block_group_descriptor_index, driver_state const & state) -> kstd::result { // TODO update all block group descriptors diff --git a/kernel/kernel/filesystems/ext2/filesystem.hpp b/kernel/kernel/filesystems/ext2/filesystem.hpp index 7ea7b43a..15328d94 100644 --- a/kernel/kernel/filesystems/ext2/filesystem.hpp +++ b/kernel/kernel/filesystems/ext2/filesystem.hpp @@ -32,26 +32,26 @@ namespace kernel::filesystems::ext2 { constexpr kstd::bytes inline base_block_size = kstd::bytes{1024}; constexpr kstd::bytes inline superblock_offset = base_block_size; - constexpr uint16_t inline magic_number = 0xEF53; + constexpr std::uint16_t inline magic_number = 0xEF53; - constexpr uint32_t inline good_old_revision = 0; - constexpr uint32_t inline dynamic_revision = 1; + constexpr std::uint32_t inline good_old_revision = 0; + constexpr std::uint32_t inline dynamic_revision = 1; - constexpr uint32_t inline root_inode_number = 2; + constexpr std::uint32_t inline root_inode_number = 2; - constexpr size_t inline direct_block_count = 12; - constexpr size_t inline singly_indirect_block_index = direct_block_count; - constexpr size_t inline doubly_indirect_block_index = singly_indirect_block_index + 1; - constexpr size_t inline triply_indirect_block_index = doubly_indirect_block_index + 1; + constexpr std::size_t inline direct_block_count = 12; + constexpr std::size_t inline singly_indirect_block_index = direct_block_count; + constexpr std::size_t inline doubly_indirect_block_index = singly_indirect_block_index + 1; + constexpr std::size_t inline triply_indirect_block_index = doubly_indirect_block_index + 1; - constexpr uint16_t inline mode_mask = 0xF000; - constexpr uint16_t inline mode_regular = 0x8000; - constexpr uint16_t inline mode_directory = 0x4000; - constexpr uint16_t inline mode_symbolic_link = 0xA000; - constexpr uint16_t inline mode_block_device = 0x6000; - constexpr uint16_t inline mode_character_device = 0x2000; - constexpr uint16_t inline mode_fifo = 0x1000; - constexpr uint16_t inline mode_socket = 0xC000; + constexpr std::uint16_t inline mode_mask = 0xF000; + constexpr std::uint16_t inline mode_regular = 0x8000; + constexpr std::uint16_t inline mode_directory = 0x4000; + constexpr std::uint16_t inline mode_symbolic_link = 0xA000; + constexpr std::uint16_t inline mode_block_device = 0x6000; + constexpr std::uint16_t inline mode_character_device = 0x2000; + constexpr std::uint16_t inline mode_fifo = 0x1000; + constexpr std::uint16_t inline mode_socket = 0xC000; } // namespace constants @@ -87,7 +87,7 @@ namespace kernel::filesystems::ext2 //! @param inode The inode whose block count to query. //! @param state The driver state to operate on. //! @return The number of blocks allocated to the inode. - [[nodiscard]] auto block_count(inode const & inode, driver_state const & state) -> uint32_t; + [[nodiscard]] auto block_count(inode const & inode, driver_state const & state) -> std::uint32_t; //! Determine the size of an inode's data on disk. //! @@ -119,21 +119,22 @@ namespace kernel::filesystems::ext2 //! @param state The state to operate on. //! @param batch The active write batch. //! @return A vector of the allocated block numbers. - auto allocate_blocks(size_t count, driver_state & state, write_batch & batch) -> kstd::result>; + auto allocate_blocks(std::size_t count, driver_state & state, write_batch & batch) + -> kstd::result>; //! Update the number of blocks allocated to an inode. //! //! @param data The inode data. //! @param state The state to operate on. //! @param delta The change in the number of blocks. - auto update_inode_block_count(inode_data & data, uint32_t delta, driver_state & state) -> void; + auto update_inode_block_count(inode_data & data, std::uint32_t delta, driver_state & state) -> void; //! Write an inode to the backing inode. //! //! @param inode_number The number of the inode to write. //! @param state The state to operate on. //! @param data The inode data to write. - auto write_inode(uint32_t inode_number, inode_data const & data, driver_state & state) -> kstd::result; + auto write_inode(std::uint32_t inode_number, inode_data const & data, driver_state & state) -> kstd::result; //! Get the block number associated with the nth block of an inode. //! @@ -141,7 +142,7 @@ namespace kernel::filesystems::ext2 //! @param inode The inode. //! @param state The state to operate on. //! @return The global block number on success, an error otherwise. - [[nodiscard]] auto inode_block_number(size_t index, inode const & inode, driver_state const & state) + [[nodiscard]] auto inode_block_number(std::size_t index, inode const & inode, driver_state const & state) -> kstd::result; //! Write a global block number to an inode block index. @@ -151,12 +152,12 @@ namespace kernel::filesystems::ext2 //! @param global_block_number The global block number to write. //! @param state The state to operate on. //! @param batch The active write batch. - auto write_global_block_number_to_inode_block_index(size_t block_index, inode_data & data, - uint32_t global_block_number, driver_state & state, + auto write_global_block_number_to_inode_block_index(std::size_t block_index, inode_data & data, + std::uint32_t global_block_number, driver_state & state, write_batch & batch) -> kstd::result; [[nodiscard]] auto write_block_group_descriptor(block_group_descriptor const & block_group_descriptor, - size_t block_group_descriptor_index, driver_state const & state) + std::size_t block_group_descriptor_index, driver_state const & state) -> kstd::result; [[nodiscard]] auto write_superblock(driver_state & state) -> kstd::result; } // namespace kernel::filesystems::ext2 diff --git a/kernel/kernel/filesystems/ext2/filesystem.tests.cpp b/kernel/kernel/filesystems/ext2/filesystem.tests.cpp index 7477a51b..01dc3ad5 100644 --- a/kernel/kernel/filesystems/ext2/filesystem.tests.cpp +++ b/kernel/kernel/filesystems/ext2/filesystem.tests.cpp @@ -173,7 +173,7 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_fixture, "Ext2 filesyste auto bytes_read = new_inode.value()->read(read_buffer, 0_B); REQUIRE(bytes_read == kstd::bytes{read_buffer.size()}); - std::string_view result{reinterpret_cast(read_buffer.data()), static_cast(*bytes_read)}; + std::string_view result{reinterpret_cast(read_buffer.data()), static_cast(*bytes_read)}; REQUIRE(result == "Hello"); } } @@ -232,8 +232,8 @@ SCENARIO("Ext2 block mapping includes direct and all indirect levels", "[filesys kernel::tests::filesystems::ext2::write_u32(*device, 51 * block_size, 52); kernel::tests::filesystems::ext2::write_u32(*device, 52 * block_size, 53); - auto const numbers_per_block = static_cast(block_size / kstd::size_of()); - auto const singly_start = static_cast(kernel::filesystems::ext2::constants::direct_block_count); + auto const numbers_per_block = static_cast(block_size / kstd::size_of()); + auto const singly_start = static_cast(kernel::filesystems::ext2::constants::direct_block_count); auto const doubly_start = singly_start + numbers_per_block; auto const triply_start = doubly_start + numbers_per_block * numbers_per_block; @@ -295,16 +295,16 @@ SCENARIO("Ext2 block writing includes direct and all indirect levels", "[filesys auto driver_state = static_pointer_cast(mount->second); REQUIRE(driver_state); - auto read_u32 = [&](kstd::bytes offset) -> uint32_t { - auto value = uint32_t{0}; + auto read_u32 = [&](kstd::bytes offset) -> std::uint32_t { + auto value = std::uint32_t{0}; std::memcpy(&value, device->data.data() + offset, sizeof(value)); return value; }; auto inode_data = kernel::filesystems::ext2::inode_data{}; - auto const numbers_per_block = static_cast(block_size / kstd::size_of()); - auto const singly_start = static_cast(kernel::filesystems::ext2::constants::direct_block_count); + auto const numbers_per_block = static_cast(block_size / kstd::size_of()); + auto const singly_start = static_cast(kernel::filesystems::ext2::constants::direct_block_count); auto const doubly_start = singly_start + numbers_per_block; auto const triply_start = doubly_start + numbers_per_block * numbers_per_block; @@ -330,23 +330,23 @@ SCENARIO("Ext2 block writing includes direct and all indirect levels", "[filesys REQUIRE(write_global_block_number_to_inode_block_index(singly_start + 1, inode_data, singly_global_block_number + 1, *driver_state, batch)); REQUIRE(read_u32(static_cast(inode_data.block[12]) * block_size.value + - 1 * kstd::size_of()) == singly_global_block_number + 1); + 1 * kstd::size_of()) == singly_global_block_number + 1); REQUIRE(write_global_block_number_to_inode_block_index(doubly_start, inode_data, doubly_global_block_number, *driver_state, batch)); REQUIRE(inode_data.block[13] == 18); - auto const doubly_leaf_table = read_u32(static_cast(inode_data.block[13]) * block_size); + auto const doubly_leaf_table = read_u32(static_cast(inode_data.block[13]) * block_size); REQUIRE(doubly_leaf_table == 19); - REQUIRE(read_u32(static_cast(doubly_leaf_table) * block_size) == doubly_global_block_number); + REQUIRE(read_u32(static_cast(doubly_leaf_table) * block_size) == doubly_global_block_number); REQUIRE(write_global_block_number_to_inode_block_index(triply_start, inode_data, triply_global_block_number, *driver_state, batch)); REQUIRE(inode_data.block[14] == 20); - auto const triply_middle_table = read_u32(static_cast(inode_data.block[14]) * block_size); + auto const triply_middle_table = read_u32(static_cast(inode_data.block[14]) * block_size); REQUIRE(triply_middle_table == 21); - auto const triply_leaf_table = read_u32(static_cast(triply_middle_table) * block_size); + auto const triply_leaf_table = read_u32(static_cast(triply_middle_table) * block_size); REQUIRE(triply_leaf_table == 22); - REQUIRE(read_u32(static_cast(triply_leaf_table) * block_size) == triply_global_block_number); + REQUIRE(read_u32(static_cast(triply_leaf_table) * block_size) == triply_global_block_number); auto inode = kernel::filesystems::ext2::inode{42, inode_data}; diff --git a/kernel/kernel/filesystems/ext2/inode.cpp b/kernel/kernel/filesystems/ext2/inode.cpp index 22e95ee7..4abf8599 100644 --- a/kernel/kernel/filesystems/ext2/inode.cpp +++ b/kernel/kernel/filesystems/ext2/inode.cpp @@ -57,7 +57,7 @@ namespace kernel::filesystems::ext2 } } // namespace - inode::inode(uint32_t inode_number, inode_data const & data) + inode::inode(std::uint32_t inode_number, inode_data const & data) : m_inode_number(inode_number) , m_data(data) {} @@ -68,7 +68,7 @@ namespace kernel::filesystems::ext2 { auto const max_readable = this->size() - offset; auto const requested_size = std::min(kstd::bytes{buffer.size()}, max_readable); - auto inline_target = reinterpret_cast(m_data.block.data()); + auto inline_target = reinterpret_cast(m_data.block.data()); kstd::libc::memcpy(buffer.data(), inline_target + offset, requested_size.value); return requested_size; } @@ -266,7 +266,7 @@ namespace kernel::filesystems::ext2 return std::pair{count, kapi::filesystem::directory_cursor{it.offset().value}}; } - auto inode::append_blocks(size_t count, write_batch & batch) -> bool + auto inode::append_blocks(std::size_t count, write_batch & batch) -> bool { auto state = static_pointer_cast(driver_state().lock()); if (!state) @@ -331,7 +331,7 @@ namespace kernel::filesystems::ext2 return ext2::data_size(*this, *state); } - [[nodiscard]] auto inode::number() const -> uint32_t + [[nodiscard]] auto inode::number() const -> std::uint32_t { return m_inode_number; } diff --git a/kernel/kernel/filesystems/ext2/inode.hpp b/kernel/kernel/filesystems/ext2/inode.hpp index cffbf679..9a3561f7 100644 --- a/kernel/kernel/filesystems/ext2/inode.hpp +++ b/kernel/kernel/filesystems/ext2/inode.hpp @@ -25,24 +25,24 @@ namespace kernel::filesystems::ext2 //! The data for a single ext2 inode. struct [[gnu::packed]] inode_data { - uint16_t mode; - uint16_t uid; - uint32_t size; - uint32_t atime; - uint32_t ctime; - uint32_t mtime; - uint32_t dtime; - uint16_t gid; - uint16_t links_count; - uint32_t blocks; - uint32_t flags; - uint32_t osd1; - std::array block; // NOLINT(readability-magic-numbers) - uint32_t generation; - uint32_t file_acl; - uint32_t dir_acl; - uint32_t faddr; - std::array osd2; // NOLINT(readability-magic-numbers) + std::uint16_t mode; + std::uint16_t uid; + std::uint32_t size; + std::uint32_t atime; + std::uint32_t ctime; + std::uint32_t mtime; + std::uint32_t dtime; + std::uint16_t gid; + std::uint16_t links_count; + std::uint32_t blocks; + std::uint32_t flags; + std::uint32_t osd1; + std::array block; // NOLINT(readability-magic-numbers) + std::uint32_t generation; + std::uint32_t file_acl; + std::uint32_t dir_acl; + std::uint32_t faddr; + std::array osd2; // NOLINT(readability-magic-numbers) }; struct inode : kernel::vfs::inode @@ -54,7 +54,7 @@ namespace kernel::filesystems::ext2 //! //! @param inode_number The inode number on disk. //! @param data The data associated with this inode, read from the disk. - explicit inode(uint32_t inode_number, inode_data const & data); + explicit inode(std::uint32_t inode_number, inode_data const & data); //! @} @@ -104,7 +104,7 @@ namespace kernel::filesystems::ext2 //! @param count The number of blocks to append. //! @param batch The active write batch. //! @return true if the blocks were successfully appended, false otherwise. - auto append_blocks(size_t count, write_batch & batch) -> bool; + auto append_blocks(std::size_t count, write_batch & batch) -> bool; //! Set the size of the file represented by this inode. //! @@ -134,13 +134,13 @@ namespace kernel::filesystems::ext2 //! @brief Get the inode number of this inode. //! //! @return The inode number. - [[nodiscard]] auto number() const -> uint32_t; + [[nodiscard]] auto number() const -> std::uint32_t; //! @} private: //! The inode number on disk. - uint32_t m_inode_number{}; + std::uint32_t m_inode_number{}; //! The inode data. inode_data m_data{}; }; diff --git a/kernel/kernel/filesystems/ext2/inode.tests.cpp b/kernel/kernel/filesystems/ext2/inode.tests.cpp index bdfb661d..277f4401 100644 --- a/kernel/kernel/filesystems/ext2/inode.tests.cpp +++ b/kernel/kernel/filesystems/ext2/inode.tests.cpp @@ -39,8 +39,9 @@ using namespace kstd::units_literals; namespace { - auto write_entry(std::vector & block, std::size_t offset, uint32_t inode_number, std::string_view name, - uint8_t file_type, kstd::bytes block_size, bool extend_to_block_end) -> std::size_t + auto write_entry(std::vector & block, std::size_t offset, std::uint32_t inode_number, + std::string_view name, std::uint8_t file_type, kstd::bytes block_size, bool extend_to_block_end) + -> std::size_t { auto const header_and_name = 8uz + name.size(); auto const rounded = (header_and_name + 3uz) & ~3uz; @@ -48,8 +49,8 @@ namespace auto * entry = reinterpret_cast(block.data() + offset); entry->inode = inode_number; - entry->rec_len = static_cast(rec_len); - entry->name_len = static_cast(name.size()); + entry->rec_len = static_cast(rec_len); + entry->name_len = static_cast(name.size()); entry->file_type = file_type; std::copy(name.begin(), name.end(), &entry->name_start); @@ -454,7 +455,7 @@ SCENARIO("Ext2 inode write across block boundaries", "[filesystem][ext2][inode]" inode_data.block[1] = 21; inode_data.mode = kernel::filesystems::ext2::constants::mode_regular; - uint32_t inode_number = 3; + std::uint32_t inode_number = 3; auto const inode_data_offset = block_group_descriptor.inode_table * block_size + kstd::bytes{(inode_number - 1) * driver_state->superblock.inode_size}; @@ -592,8 +593,8 @@ SCENARIO("Ext2 inode get_size() and set_size() handles size correctly depending data.size = 256; data.dir_acl = 32; - auto const verify_size_and_set_size = [&](uint16_t mode, kstd::bytes expected_initial_size, - uint32_t expected_dir_acl_after_set_size) { + auto const verify_size_and_set_size = [&](std::uint16_t mode, kstd::bytes expected_initial_size, + std::uint32_t expected_dir_acl_after_set_size) { data.mode = mode; auto inode = kernel::filesystems::ext2::inode{42, data}; @@ -639,8 +640,8 @@ SCENARIO("Ext2 inode get_size() and set_size() handles size correctly depending data.size = 256; data.dir_acl = 32; - auto const verify_size_and_set_size = [&](uint16_t mode, kstd::bytes expected_initial_size, - uint32_t expected_dir_acl_after_set_size) { + auto const verify_size_and_set_size = [&](std::uint16_t mode, kstd::bytes expected_initial_size, + std::uint32_t expected_dir_acl_after_set_size) { data.mode = mode; auto inode = kernel::filesystems::ext2::inode{42, data}; @@ -806,15 +807,15 @@ SCENARIO("Ext2 inode read_directory skips deleted entries and paginates correctl auto block = std::vector(block_size.value, std::byte{0}); auto offset = 0uz; - offset += - write_entry(block, offset, 10, "alpha", - static_cast(kernel::filesystems::ext2::constants::mode_regular >> 8), block_size, false); + offset += write_entry(block, offset, 10, "alpha", + static_cast(kernel::filesystems::ext2::constants::mode_regular >> 8), + block_size, false); offset += write_entry(block, offset, 0, "deleted", 0, block_size, false); - offset += - write_entry(block, offset, 11, "beta", - static_cast(kernel::filesystems::ext2::constants::mode_regular >> 8), block_size, false); + offset += write_entry(block, offset, 11, "beta", + static_cast(kernel::filesystems::ext2::constants::mode_regular >> 8), + block_size, false); write_entry(block, offset, 12, "gamma", - static_cast(kernel::filesystems::ext2::constants::mode_regular >> 8), block_size, true); + static_cast(kernel::filesystems::ext2::constants::mode_regular >> 8), block_size, true); kernel::tests::filesystems::ext2::write_bytes(*device, 30 * block_size, block.data(), block_size); diff --git a/kernel/kernel/filesystems/ext2/linked_directory_entry.hpp b/kernel/kernel/filesystems/ext2/linked_directory_entry.hpp index 9530a586..98db586f 100644 --- a/kernel/kernel/filesystems/ext2/linked_directory_entry.hpp +++ b/kernel/kernel/filesystems/ext2/linked_directory_entry.hpp @@ -14,10 +14,10 @@ namespace kernel::filesystems::ext2 return std::string_view{&name_start, name_len}; } - uint32_t inode; - uint16_t rec_len; - uint8_t name_len; - uint8_t file_type; + std::uint32_t inode; + std::uint16_t rec_len; + std::uint8_t name_len; + std::uint8_t file_type; char name_start; // NOLINT(readability-magic-numbers) }; } // namespace kernel::filesystems::ext2 diff --git a/kernel/kernel/filesystems/ext2/superblock.hpp b/kernel/kernel/filesystems/ext2/superblock.hpp index 92c73513..40474e70 100644 --- a/kernel/kernel/filesystems/ext2/superblock.hpp +++ b/kernel/kernel/filesystems/ext2/superblock.hpp @@ -48,64 +48,64 @@ namespace kernel::filesystems::ext2 //! The superblock in the ext2 filesystem. struct [[gnu::packed]] superblock { - uint32_t inodes_count; - uint32_t blocks_count; - uint32_t reserved_blocks_count; - uint32_t free_blocks_count; - uint32_t free_inodes_count; - uint32_t first_data_block; - uint32_t log_block_size; - uint32_t log_frag_size; - uint32_t blocks_per_group; - uint32_t frags_per_group; - uint32_t inodes_per_group; - uint32_t mtime; - uint32_t wtime; - uint16_t mnt_count; - uint16_t max_mnt_count; - uint16_t magic; - uint16_t state; - uint16_t errors; - uint16_t minor_rev_level; - uint32_t lastcheck; - uint32_t checkinterval; - uint32_t creator_os; - uint32_t rev_level; - uint16_t def_resuid; - uint16_t def_resgid; + std::uint32_t inodes_count; + std::uint32_t blocks_count; + std::uint32_t reserved_blocks_count; + std::uint32_t free_blocks_count; + std::uint32_t free_inodes_count; + std::uint32_t first_data_block; + std::uint32_t log_block_size; + std::uint32_t log_frag_size; + std::uint32_t blocks_per_group; + std::uint32_t frags_per_group; + std::uint32_t inodes_per_group; + std::uint32_t mtime; + std::uint32_t wtime; + std::uint16_t mnt_count; + std::uint16_t max_mnt_count; + std::uint16_t magic; + std::uint16_t state; + std::uint16_t errors; + std::uint16_t minor_rev_level; + std::uint32_t lastcheck; + std::uint32_t checkinterval; + std::uint32_t creator_os; + std::uint32_t rev_level; + std::uint16_t def_resuid; + std::uint16_t def_resgid; // EXT2_DYNAMIC_REV superblock only - uint32_t first_ino; - uint16_t inode_size; - uint16_t block_group_nr; + std::uint32_t first_ino; + std::uint16_t inode_size; + std::uint16_t block_group_nr; compatible_features feature_compat; incompatible_features feature_incompat; read_only_compatible_features feature_ro_compat; - std::array uuid; - std::array volume_name; - std::array last_mounted; - uint32_t algorithm_usage_bitmap; + std::array uuid; + std::array volume_name; + std::array last_mounted; + std::uint32_t algorithm_usage_bitmap; // Performance Hints - uint8_t prealloc_blocks; - uint8_t prealloc_dir_blocks; - uint16_t padding1; + std::uint8_t prealloc_blocks; + std::uint8_t prealloc_dir_blocks; + std::uint16_t padding1; // Journaling Support - std::array journal_uuid; - uint32_t journal_inum; - uint32_t journal_dev; - uint32_t last_orphan; + std::array journal_uuid; + std::uint32_t journal_inum; + std::uint32_t journal_dev; + std::uint32_t last_orphan; // Directory Indexing Support - std::array hash_seed; - uint8_t def_hash_version; - std::array padding2; + std::array hash_seed; + std::uint8_t def_hash_version; + std::array padding2; // Other options - uint32_t default_mount_options; - uint32_t first_meta_bg; - std::array unused; // NOLINT(readability-magic-numbers) + std::uint32_t default_mount_options; + std::uint32_t first_meta_bg; + std::array unused; // NOLINT(readability-magic-numbers) }; } // namespace kernel::filesystems::ext2 diff --git a/kernel/kernel/main.cpp b/kernel/kernel/main.cpp index 7083d517..f59b4ad7 100644 --- a/kernel/kernel/main.cpp +++ b/kernel/kernel/main.cpp @@ -81,7 +81,7 @@ auto run_demo() -> void // 6) read from the new file kstd::vector buffer_2{10}; bytes_read = *kapi::filesystem::read(fd_2.value(), buffer_2); - buffer_as_str = std::string_view{reinterpret_cast(buffer_2.data()), static_cast(bytes_read)}; + buffer_as_str = std::string_view{reinterpret_cast(buffer_2.data()), static_cast(bytes_read)}; kstd::println("--> read {} from /entrance/information/info_1.txt: {}", bytes_read, buffer_as_str); // 7) open device as file diff --git a/kernel/kernel/test_support/devices/block_device.cpp b/kernel/kernel/test_support/devices/block_device.cpp index c9ab4a5e..462dc79d 100644 --- a/kernel/kernel/test_support/devices/block_device.cpp +++ b/kernel/kernel/test_support/devices/block_device.cpp @@ -25,7 +25,7 @@ namespace kernel::tests::devices data.resize(initial_size.value, 0); } - auto block_device::read_block(size_t block_index, std::span buffer) -> kstd::result + auto block_device::read_block(std::size_t block_index, std::span buffer) -> kstd::result { auto const offset = block_index * block_size(); if (offset.value >= data.size()) @@ -44,7 +44,8 @@ namespace kernel::tests::devices return bytes_to_read; } - auto block_device::write_block(size_t block_index, std::span buffer) -> kstd::result + auto block_device::write_block(std::size_t block_index, std::span buffer) + -> kstd::result { auto const offset = block_index * block_size(); auto const write_end = offset + block_size(); diff --git a/kernel/kernel/test_support/devices/block_device.hpp b/kernel/kernel/test_support/devices/block_device.hpp index 5f00f27e..9e64ed18 100644 --- a/kernel/kernel/test_support/devices/block_device.hpp +++ b/kernel/kernel/test_support/devices/block_device.hpp @@ -20,13 +20,13 @@ namespace kernel::tests::devices { block_device(kstd::string const & name, kstd::bytes block_size, kstd::bytes initial_size = {}); - auto read_block(size_t block_index, std::span buffer) -> kstd::result override; - auto write_block(size_t block_index, std::span buffer) -> kstd::result override; + auto read_block(std::size_t block_index, std::span buffer) -> kstd::result override; + auto write_block(std::size_t block_index, std::span buffer) -> kstd::result override; [[nodiscard]] auto block_size() const -> kstd::bytes override; [[nodiscard]] auto capacity() const -> kstd::bytes override; - kstd::vector data{}; + kstd::vector data{}; private: [[nodiscard]] auto query_facet(kapi::capabilities::facet_id facet) -> void * override; diff --git a/kernel/kernel/test_support/filesystems/ext2.cpp b/kernel/kernel/test_support/filesystems/ext2.cpp index 92f56aef..df224f63 100644 --- a/kernel/kernel/test_support/filesystems/ext2.cpp +++ b/kernel/kernel/test_support/filesystems/ext2.cpp @@ -17,7 +17,7 @@ namespace kernel::tests::filesystems::ext2 { namespace { - constexpr uint32_t root_directory_data_block = 20; + constexpr std::uint32_t root_directory_data_block = 20; } // namespace auto write_bytes(kernel::tests::devices::block_device & device, kstd::bytes offset, void const * source, @@ -32,7 +32,7 @@ namespace kernel::tests::filesystems::ext2 std::memcpy(device.data.data() + offset, source, size.value); } - auto write_u32(kernel::tests::devices::block_device & device, kstd::bytes offset, uint32_t value) -> void + auto write_u32(kernel::tests::devices::block_device & device, kstd::bytes offset, std::uint32_t value) -> void { write_bytes(device, offset, &value, kstd::size_of(value)); } @@ -74,7 +74,7 @@ namespace kernel::tests::filesystems::ext2 root_inode_data.block[0] = root_directory_data_block; auto const root_inode_offset = - static_cast(group_descriptor.inode_table) * kernel::filesystems::ext2::constants::base_block_size + + static_cast(group_descriptor.inode_table) * kernel::filesystems::ext2::constants::base_block_size + (kernel::filesystems::ext2::constants::root_inode_number - 1) * kstd::bytes{superblock.inode_size}; write_bytes(device, root_inode_offset, &root_inode_data, kstd::size_of(root_inode_data)); } diff --git a/kernel/kernel/test_support/filesystems/ext2.hpp b/kernel/kernel/test_support/filesystems/ext2.hpp index 7509f1e1..043071dc 100644 --- a/kernel/kernel/test_support/filesystems/ext2.hpp +++ b/kernel/kernel/test_support/filesystems/ext2.hpp @@ -13,7 +13,7 @@ namespace kernel::tests::filesystems::ext2 { auto write_bytes(kernel::tests::devices::block_device & device, kstd::bytes offset, void const * source, kstd::bytes size) -> void; - auto write_u32(kernel::tests::devices::block_device & device, kstd::bytes offset, uint32_t value) -> void; + auto write_u32(kernel::tests::devices::block_device & device, kstd::bytes offset, std::uint32_t value) -> void; auto setup_mock_ext2_layout(kernel::tests::devices::block_device & device) -> void; auto setup_mock_ext2_layout(kernel::tests::devices::block_device & device, kernel::filesystems::ext2::superblock const & superblock) -> void; diff --git a/kernel/kernel/test_support/vfs/storage_boot_module_fixture.cpp b/kernel/kernel/test_support/vfs/storage_boot_module_fixture.cpp index 69dec962..8fa48257 100644 --- a/kernel/kernel/test_support/vfs/storage_boot_module_fixture.cpp +++ b/kernel/kernel/test_support/vfs/storage_boot_module_fixture.cpp @@ -122,7 +122,7 @@ namespace kernel::tests::vfs throw std::invalid_argument{"Module names and image paths vectors must have the same size."}; } - for (size_t i = 0; i < module_names.size(); ++i) + for (std::size_t i = 0; i < module_names.size(); ++i) { setup_module_from_img(i, module_names[i], img_paths[i]); } diff --git a/kernel/kernel/vfs/constants.hpp b/kernel/kernel/vfs/constants.hpp index b5759d32..a30bb8e7 100644 --- a/kernel/kernel/vfs/constants.hpp +++ b/kernel/kernel/vfs/constants.hpp @@ -6,13 +6,13 @@ namespace kernel::vfs::constants { //! The maximum allowed length for any path in the system. - constexpr size_t inline max_path_length = 4096; + constexpr std::size_t inline max_path_length = 4096; //! The maximum allowed path length for the target of a symlink. - constexpr size_t inline symlink_max_path_length = 4096; + constexpr std::size_t inline symlink_max_path_length = 4096; //! The maximum number of loops allowed in a path, via symlinks. - constexpr size_t inline symloop_max = 40; + constexpr std::size_t inline symloop_max = 40; } // namespace kernel::vfs::constants #endif \ No newline at end of file diff --git a/kernel/kernel/vfs/dentry.cpp b/kernel/kernel/vfs/dentry.cpp index c22dc0e2..d9cb835a 100644 --- a/kernel/kernel/vfs/dentry.cpp +++ b/kernel/kernel/vfs/dentry.cpp @@ -81,17 +81,17 @@ namespace kernel::vfs auto dentry::set_flag(dentry_flags flag) -> void { - m_flags |= static_cast(flag); + m_flags |= static_cast(flag); } auto dentry::unset_flag(dentry_flags flag) -> void { - m_flags &= ~static_cast(flag); + m_flags &= ~static_cast(flag); } auto dentry::has_flag(dentry_flags flag) const -> bool { - return (m_flags & static_cast(flag)) != 0; + return (m_flags & static_cast(flag)) != 0; } auto dentry::set_parent(dentry_ptr const & parent) -> void diff --git a/kernel/kernel/vfs/dentry.hpp b/kernel/kernel/vfs/dentry.hpp index 13dea2a3..0c669854 100644 --- a/kernel/kernel/vfs/dentry.hpp +++ b/kernel/kernel/vfs/dentry.hpp @@ -19,7 +19,7 @@ namespace kernel::vfs using inode_ptr = kstd::shared_ptr; //! Flags for the dentry. - enum class dentry_flags : uint32_t + enum class dentry_flags : std::uint32_t { is_mount_point = 1 << 0 }; @@ -95,7 +95,7 @@ namespace kernel::vfs kstd::weak_ptr m_parent; kstd::vector m_children; inode_ptr m_inode; - uint32_t m_flags; + std::uint32_t m_flags; }; } // namespace kernel::vfs diff --git a/kernel/kernel/vfs/device_inode.tests.cpp b/kernel/kernel/vfs/device_inode.tests.cpp index 0f9b5881..44346426 100644 --- a/kernel/kernel/vfs/device_inode.tests.cpp +++ b/kernel/kernel/vfs/device_inode.tests.cpp @@ -106,7 +106,7 @@ SCENARIO("Device inode read/write", "[filesystem][device_inode]") WHEN("writing to the device inode") { kstd::vector write_buffer(1024); - for (size_t i = 0; i < write_buffer.size(); ++i) + for (std::size_t i = 0; i < write_buffer.size(); ++i) { write_buffer[i] = static_cast(i % 256); } diff --git a/kernel/kernel/vfs/mount.cpp b/kernel/kernel/vfs/mount.cpp index 76f72e22..3f99f733 100644 --- a/kernel/kernel/vfs/mount.cpp +++ b/kernel/kernel/vfs/mount.cpp @@ -134,7 +134,7 @@ namespace kernel::vfs return m_ref_count == 0; } - auto mount::ref_count() const -> size_t + auto mount::ref_count() const -> std::size_t { return m_ref_count; } diff --git a/kernel/kernel/vfs/mount.hpp b/kernel/kernel/vfs/mount.hpp index b0993dd3..dc49212c 100644 --- a/kernel/kernel/vfs/mount.hpp +++ b/kernel/kernel/vfs/mount.hpp @@ -83,7 +83,7 @@ namespace kernel::vfs //! Get the current reference count for this mount. //! //! @return The current reference count. - [[nodiscard]] auto ref_count() const -> size_t; + [[nodiscard]] auto ref_count() const -> std::size_t; private: friend struct mount_table; @@ -112,7 +112,7 @@ namespace kernel::vfs mount_ptr m_parent_mount{}; kstd::weak_ptr m_source_mount{}; kstd::shared_ptr m_driver_state{}; - std::atomic_size_t m_ref_count{0}; + std::atomic m_ref_count{0}; }; } // namespace kernel::vfs diff --git a/kernel/kernel/vfs/open_file_table.cpp b/kernel/kernel/vfs/open_file_table.cpp index 286fa57b..108f4e11 100644 --- a/kernel/kernel/vfs/open_file_table.cpp +++ b/kernel/kernel/vfs/open_file_table.cpp @@ -59,7 +59,7 @@ namespace kernel::vfs return m_open_files.size() - 1; } - auto open_file_table::file(size_t fd) const -> kstd::result> + auto open_file_table::file(std::size_t fd) const -> kstd::result> { if (fd >= m_open_files.size() || m_open_files.at(fd) == nullptr) { @@ -69,7 +69,7 @@ namespace kernel::vfs return kstd::success(m_open_files.at(fd)); } - auto open_file_table::remove_file(size_t fd) -> kstd::result + auto open_file_table::remove_file(std::size_t fd) -> kstd::result { if (fd >= m_open_files.size() || m_open_files.at(fd) == nullptr) { diff --git a/kernel/kernel/vfs/open_file_table.hpp b/kernel/kernel/vfs/open_file_table.hpp index 10674ba7..8d6a2341 100644 --- a/kernel/kernel/vfs/open_file_table.hpp +++ b/kernel/kernel/vfs/open_file_table.hpp @@ -39,13 +39,13 @@ namespace kernel::vfs //! //! @param fd The file descriptor index to retrieve. //! @return The requested file descriptor on success, an error otherwise. - [[nodiscard]] auto file(size_t fd) const -> kstd::result>; + [[nodiscard]] auto file(std::size_t fd) const -> kstd::result>; //! Remove a file from the open file table. //! //! @param fd The file descriptor index to remove. //! @return Nothin on success, an error otherwise. - auto remove_file(size_t fd) -> kstd::result; + auto remove_file(std::size_t fd) -> kstd::result; private: open_file_table() = default; diff --git a/libs/kstd/kstd/allocator.hpp b/libs/kstd/kstd/allocator.hpp index 0de0e10d..c54a8973 100644 --- a/libs/kstd/kstd/allocator.hpp +++ b/libs/kstd/kstd/allocator.hpp @@ -40,7 +40,7 @@ namespace kstd return static_cast(KSTD_OPERATOR_NEW(n * sizeof(T))); } - constexpr void deallocate(T * p, std::size_t n) noexcept + constexpr auto deallocate(T * p, std::size_t n) noexcept -> void { if (alignof(T) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { diff --git a/libs/kstd/kstd/bits/format/formatter/string_view.hpp b/libs/kstd/kstd/bits/format/formatter/string_view.hpp index 7d745798..417ec81c 100644 --- a/libs/kstd/kstd/bits/format/formatter/string_view.hpp +++ b/libs/kstd/kstd/bits/format/formatter/string_view.hpp @@ -30,7 +30,7 @@ namespace kstd return it; } - auto format(std::string_view const & string, format_context & context) const -> void + auto format(std::string_view string, format_context & context) const -> void { context.push(string); } diff --git a/libs/kstd/kstd/bits/format/string.hpp b/libs/kstd/kstd/bits/format/string.hpp index ab034e7c..98ec6926 100644 --- a/libs/kstd/kstd/bits/format/string.hpp +++ b/libs/kstd/kstd/bits/format/string.hpp @@ -72,7 +72,7 @@ namespace kstd template struct format_string { - consteval format_string(std::string_view const & str) noexcept(false) + consteval format_string(std::string_view str) noexcept(false) : str_view{str} { using namespace bits::format; diff --git a/libs/kstd/kstd/bits/shared_ptr.hpp b/libs/kstd/kstd/bits/shared_ptr.hpp index c3367967..1c1ae08c 100644 --- a/libs/kstd/kstd/bits/shared_ptr.hpp +++ b/libs/kstd/kstd/bits/shared_ptr.hpp @@ -417,7 +417,7 @@ namespace kstd ~enable_shared_from_this() = default; - void internal_assign_ptr(shared_ptr const & ptr) const + auto internal_assign_ptr(shared_ptr const & ptr) const -> void { m_weak_this = ptr; } @@ -672,7 +672,7 @@ namespace kstd //! Replace the managed object. //! //! @param ptr Pointer to a new object to manage. - void reset(T * ptr = nullptr) + auto reset(T * ptr = nullptr) -> void { shared_ptr(ptr).swap(*this); } @@ -680,7 +680,7 @@ namespace kstd //! Exchange ownership of the object manages by this shared pointer and another one. //! //! @param other The shared pointer to swap ownership with. - void swap(shared_ptr & other) noexcept + auto swap(shared_ptr & other) noexcept -> void { std::ranges::swap(m_pointer, other.m_pointer); std::ranges::swap(m_control_block, other.m_control_block); diff --git a/libs/multiboot2/multiboot2/information.hpp b/libs/multiboot2/multiboot2/information.hpp index 2611063b..98fa0d7c 100644 --- a/libs/multiboot2/multiboot2/information.hpp +++ b/libs/multiboot2/multiboot2/information.hpp @@ -289,8 +289,8 @@ namespace multiboot2 return std::nullopt; } - uint32_t m_size{}; - uint32_t : 32; + std::uint32_t m_size{}; + std::uint32_t : 32; tag_header m_tags{}; }; -- cgit v1.2.3