aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-08-18 13:51:55 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-08-18 13:51:55 +0200
commitcd665ec172dadd049e7c1830b070f15b58fb9011 (patch)
tree42c2eb8ecb984d179263f68cab1c6c2667e8dd2c
parent5754a8591252da5d5eeb4281064f0b82bfdc03a8 (diff)
downloadkernel-cd665ec172dadd049e7c1830b070f15b58fb9011.tar.xz
kernel-cd665ec172dadd049e7c1830b070f15b58fb9011.zip
kstd: flatten units namespace
-rw-r--r--arch/x86_64/arch/bus/cpu.cpp2
-rw-r--r--arch/x86_64/arch/drivers/cpu/lapic.hpp2
-rw-r--r--arch/x86_64/arch/memory/kernel_mapper.cpp3
-rw-r--r--arch/x86_64/arch/memory/page_table.hpp2
-rw-r--r--arch/x86_64/kapi/memory.cpp4
-rw-r--r--kapi/kapi/devices/resource.hpp2
-rw-r--r--kapi/kapi/filesystem.hpp8
-rw-r--r--kapi/kapi/filesystem/block_special_file.hpp8
-rw-r--r--kapi/kapi/filesystem/character_special_file.hpp4
-rw-r--r--kapi/kapi/filesystem/file_status.hpp2
-rw-r--r--kapi/kapi/memory/address.hpp4
-rw-r--r--kapi/kapi/memory/chunk.hpp2
-rw-r--r--kapi/kapi/memory/layout.hpp4
-rw-r--r--kernel/kapi/devices/device.tests.cpp4
-rw-r--r--kernel/kapi/filesystem.cpp8
-rw-r--r--kernel/kapi/memory.cpp2
-rw-r--r--kernel/kernel/devices/block_device_utils.cpp21
-rw-r--r--kernel/kernel/devices/block_device_utils.hpp14
-rw-r--r--kernel/kernel/devices/block_device_utils.tests.cpp8
-rw-r--r--kernel/kernel/drivers/pseudo/null.cpp6
-rw-r--r--kernel/kernel/drivers/pseudo/zero.cpp8
-rw-r--r--kernel/kernel/drivers/storage/ram_disk.cpp15
-rw-r--r--kernel/kernel/filesystem/devfs/inode.cpp4
-rw-r--r--kernel/kernel/filesystem/devfs/inode.hpp7
-rw-r--r--kernel/kernel/filesystem/device_inode.cpp6
-rw-r--r--kernel/kernel/filesystem/device_inode.hpp7
-rw-r--r--kernel/kernel/filesystem/device_inode.tests.cpp4
-rw-r--r--kernel/kernel/filesystem/device_number_registry.tests.cpp2
-rw-r--r--kernel/kernel/filesystem/ext2/filesystem.cpp32
-rw-r--r--kernel/kernel/filesystem/ext2/filesystem.hpp18
-rw-r--r--kernel/kernel/filesystem/ext2/filesystem.tests.cpp10
-rw-r--r--kernel/kernel/filesystem/ext2/inode.cpp20
-rw-r--r--kernel/kernel/filesystem/ext2/inode.hpp11
-rw-r--r--kernel/kernel/filesystem/ext2/inode.tests.cpp24
-rw-r--r--kernel/kernel/filesystem/inode.hpp7
-rw-r--r--kernel/kernel/filesystem/open_file_descriptor.cpp10
-rw-r--r--kernel/kernel/filesystem/open_file_descriptor.hpp12
-rw-r--r--kernel/kernel/filesystem/open_file_descriptor.tests.cpp16
-rw-r--r--kernel/kernel/filesystem/rootfs/inode.cpp8
-rw-r--r--kernel/kernel/filesystem/rootfs/inode.hpp7
-rw-r--r--kernel/kernel/filesystem/vfs.tests.cpp4
-rw-r--r--kernel/kernel/memory.cpp2
-rw-r--r--kernel/kernel/memory/block_list_allocator.cpp15
-rw-r--r--kernel/kernel/memory/block_list_allocator.hpp12
-rw-r--r--kernel/kernel/memory/heap_allocator.hpp2
-rw-r--r--kernel/kernel/memory/operators.cpp4
-rw-r--r--kernel/kernel/test_support/devices/block_device.cpp15
-rw-r--r--kernel/kernel/test_support/devices/block_device.hpp13
-rw-r--r--kernel/kernel/test_support/filesystem/ext2.cpp10
-rw-r--r--kernel/kernel/test_support/filesystem/ext2.hpp6
-rw-r--r--kernel/kernel/test_support/filesystem/inode.cpp8
-rw-r--r--kernel/kernel/test_support/filesystem/inode.hpp6
-rw-r--r--kernel/kernel/test_support/kapi/memory.cpp4
-rw-r--r--kernel/kernel/test_support/page_mapper.cpp2
-rw-r--r--kernel/kernel/test_support/page_mapper.hpp2
-rw-r--r--kernel/kernel/test_support/simulated_memory.cpp8
-rw-r--r--kernel/kernel/test_support/simulated_memory.hpp12
-rw-r--r--libs/acpi/acpi/common/table_header.cpp4
-rw-r--r--libs/acpi/acpi/common/table_header.hpp2
-rw-r--r--libs/acpi/acpi/pointers.cpp4
-rw-r--r--libs/acpi/acpi/pointers.hpp2
-rw-r--r--libs/kstd/kstd/units.hpp113
-rw-r--r--libs/multiboot2/multiboot2/information.hpp8
-rw-r--r--libs/multiboot2/multiboot2/information/data.hpp20
64 files changed, 303 insertions, 313 deletions
diff --git a/arch/x86_64/arch/bus/cpu.cpp b/arch/x86_64/arch/bus/cpu.cpp
index 0a0e94ec..4b9edffc 100644
--- a/arch/x86_64/arch/bus/cpu.cpp
+++ b/arch/x86_64/arch/bus/cpu.cpp
@@ -27,7 +27,7 @@ namespace arch::bus
constexpr auto candidate_flags = ::acpi::processor_local_apic_entry::flags::processor_enabled //
| ::acpi::processor_local_apic_entry::flags::online_capable;
- constexpr auto lapic_mmio_range_size = kstd::units::bytes{0x400};
+ constexpr auto lapic_mmio_range_size = kstd::bytes{0x400};
struct protocol final : kapi::devices::bus_protocol
{
diff --git a/arch/x86_64/arch/drivers/cpu/lapic.hpp b/arch/x86_64/arch/drivers/cpu/lapic.hpp
index f2a8a4e9..678d364a 100644
--- a/arch/x86_64/arch/drivers/cpu/lapic.hpp
+++ b/arch/x86_64/arch/drivers/cpu/lapic.hpp
@@ -40,6 +40,6 @@ namespace arch::drivers::cpu
bool m_is_mapped{};
};
-} // namespace arch::drivers
+} // namespace arch::drivers::cpu
#endif
diff --git a/arch/x86_64/arch/memory/kernel_mapper.cpp b/arch/x86_64/arch/memory/kernel_mapper.cpp
index 0ddf08dd..a15a1d9e 100644
--- a/arch/x86_64/arch/memory/kernel_mapper.cpp
+++ b/arch/x86_64/arch/memory/kernel_mapper.cpp
@@ -74,8 +74,7 @@ namespace arch::memory
auto kernel_mapper::map_section(section_header_type const & section, std::string_view name,
kapi::memory::page_mapper & mapper) -> void
{
- auto number_of_pages =
- (kstd::units::bytes{section.size} + (kapi::memory::page::size - 1_B)) / kapi::memory::page::size;
+ auto number_of_pages = (kstd::bytes{section.size} + (kapi::memory::page::size - 1_B)) / kapi::memory::page::size;
auto linear_start_address = kapi::memory::linear_address{section.virtual_load_address};
auto physical_start_address = kapi::memory::physical_address{section.virtual_load_address & ~m_kernel_load_base};
diff --git a/arch/x86_64/arch/memory/page_table.hpp b/arch/x86_64/arch/memory/page_table.hpp
index 5bb4e1aa..12abacb5 100644
--- a/arch/x86_64/arch/memory/page_table.hpp
+++ b/arch/x86_64/arch/memory/page_table.hpp
@@ -117,7 +117,7 @@ namespace arch::memory
};
//! The maximum number of entries in this table.
- constexpr auto static entry_count{kapi::memory::page::size / kstd::units::bytes{sizeof(entry)}};
+ constexpr auto static entry_count{kapi::memory::page::size / kstd::bytes{sizeof(entry)}};
//! Get the entry at the given index.
//!
diff --git a/arch/x86_64/kapi/memory.cpp b/arch/x86_64/kapi/memory.cpp
index a6f84f07..37b4c7f3 100644
--- a/arch/x86_64/kapi/memory.cpp
+++ b/arch/x86_64/kapi/memory.cpp
@@ -129,7 +129,7 @@ namespace kapi::memory
auto module_physical_start = physical_address{module.start_address};
auto module_virtual_start =
linear_address{module.start_address + std::bit_cast<std::uintptr_t>(&arch::boot::TEACHOS_VMA)};
- auto module_size = static_cast<kstd::units::bytes>(module.end_address - module.start_address);
+ auto module_size = static_cast<kstd::bytes>(module.end_address - module.start_address);
auto module_block_count = (module_size + frame::size - 1_B) / frame::size;
for (auto i = 0uz; i < module_block_count; ++i)
@@ -150,7 +150,7 @@ namespace kapi::memory
}))
{
auto start = frame::containing(physical_address{region.base});
- auto count = kstd::units::bytes{region.size_in_B} / page::size;
+ auto count = kstd::bytes{region.size_in_B} / page::size;
new_allocator.release_many({start, count});
}
diff --git a/kapi/kapi/devices/resource.hpp b/kapi/kapi/devices/resource.hpp
index bcad5dd5..1284ce10 100644
--- a/kapi/kapi/devices/resource.hpp
+++ b/kapi/kapi/devices/resource.hpp
@@ -78,7 +78,7 @@ namespace kapi::devices
//! The physical start address of this range.
kapi::memory::physical_address start;
//! The size of this range.
- kstd::units::bytes size;
+ kstd::bytes size;
};
//! A range of I/O ports.
diff --git a/kapi/kapi/filesystem.hpp b/kapi/kapi/filesystem.hpp
index be754748..78845a00 100644
--- a/kapi/kapi/filesystem.hpp
+++ b/kapi/kapi/filesystem.hpp
@@ -58,14 +58,14 @@ namespace kapi::filesystem
//! @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<std::byte> buffer) -> kstd::result<kstd::units::bytes>;
+ auto read(size_t file_descriptor, std::span<std::byte> buffer) -> kstd::result<kstd::bytes>;
//! 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<std::byte const> buffer) -> kstd::result<kstd::units::bytes>;
+ auto write(size_t file_descriptor, std::span<std::byte const> buffer) -> kstd::result<kstd::bytes>;
//! Adjust the current position in the file.
//!
@@ -74,8 +74,8 @@ namespace kapi::filesystem
//! @param direction The direction to seek towards, 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::units::bytes offset, seek_direction direction, seek_origin origin)
- -> kstd::result<kstd::units::bytes>;
+ auto seek(size_t file_descriptor, kstd::bytes offset, seek_direction direction, seek_origin origin)
+ -> kstd::result<kstd::bytes>;
//! 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 7b06f058..6060c5ea 100644
--- a/kapi/kapi/filesystem/block_special_file.hpp
+++ b/kapi/kapi/filesystem/block_special_file.hpp
@@ -31,7 +31,7 @@ namespace kapi::filesystem
//! @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<std::byte> buffer)
- -> kstd::result<kstd::units::bytes> = 0;
+ -> kstd::result<kstd::bytes> = 0;
//! Write data from a buffer into a block.
//!
@@ -44,13 +44,13 @@ namespace kapi::filesystem
//! @param buffer The buffer to write from.
//! @return The number of bytes written on success, an error otherwise.
auto virtual write_block(std::size_t block_index, std::span<std::byte const> buffer)
- -> kstd::result<kstd::units::bytes> = 0;
+ -> kstd::result<kstd::bytes> = 0;
//! Get the block size in bytes.
- [[nodiscard]] auto virtual block_size() const -> kstd::units::bytes = 0;
+ [[nodiscard]] auto virtual block_size() const -> kstd::bytes = 0;
//! Get the capacity of the associated device.
- [[nodiscard]] auto virtual capacity() const -> kstd::units::bytes = 0;
+ [[nodiscard]] auto virtual capacity() const -> kstd::bytes = 0;
};
} // namespace kapi::filesystem
diff --git a/kapi/kapi/filesystem/character_special_file.hpp b/kapi/kapi/filesystem/character_special_file.hpp
index a2608489..c63d535b 100644
--- a/kapi/kapi/filesystem/character_special_file.hpp
+++ b/kapi/kapi/filesystem/character_special_file.hpp
@@ -25,13 +25,13 @@ namespace kapi::filesystem
//!
//! @param buffer The buffer to read into.
//! @return The number of bytes read on success, an error otherwise.
- [[nodiscard]] auto virtual read(std::span<std::byte> buffer) -> kstd::result<kstd::units::bytes> = 0;
+ [[nodiscard]] auto virtual read(std::span<std::byte> buffer) -> kstd::result<kstd::bytes> = 0;
//! Write data from a buffer into the stream.
//!
//! @param buffer The buffer to write from.
//! @return The number of bytes written on success, an error otherwise.
- auto virtual write(std::span<std::byte const> buffer) -> kstd::result<kstd::units::bytes> = 0;
+ auto virtual write(std::span<std::byte const> buffer) -> kstd::result<kstd::bytes> = 0;
};
} // namespace kapi::filesystem
diff --git a/kapi/kapi/filesystem/file_status.hpp b/kapi/kapi/filesystem/file_status.hpp
index df48f9db..bb3c776a 100644
--- a/kapi/kapi/filesystem/file_status.hpp
+++ b/kapi/kapi/filesystem/file_status.hpp
@@ -15,7 +15,7 @@ namespace kapi::filesystem
struct file_status
{
std::uint32_t mode{};
- kstd::units::bytes size{};
+ kstd::bytes size{};
device_number raw_device{};
std::uint64_t inode_number{};
std::uint32_t link_count{};
diff --git a/kapi/kapi/memory/address.hpp b/kapi/kapi/memory/address.hpp
index d176d2b8..8ed6d37a 100644
--- a/kapi/kapi/memory/address.hpp
+++ b/kapi/kapi/memory/address.hpp
@@ -184,12 +184,12 @@ namespace kapi::memory
return static_cast<MaskType>(m_value & mask);
}
- constexpr auto operator+(kstd::units::bytes n) const noexcept -> address
+ constexpr auto operator+(kstd::bytes n) const noexcept -> address
{
return address{m_value + n.value};
}
- constexpr auto operator+=(kstd::units::bytes n) noexcept -> address &
+ constexpr auto operator+=(kstd::bytes n) noexcept -> address &
{
return *this = *this + n;
}
diff --git a/kapi/kapi/memory/chunk.hpp b/kapi/kapi/memory/chunk.hpp
index 36d83b2e..45e2ccfd 100644
--- a/kapi/kapi/memory/chunk.hpp
+++ b/kapi/kapi/memory/chunk.hpp
@@ -17,7 +17,7 @@ namespace kapi::memory
//! @tparam ChunkType The CRTP type of the deriving class
//! @tparam AddressType The type of addresses used to index this chunk
//! @tparam Size The size of this chunk.
- template<typename ChunkType, typename AddressType, kstd::units::bytes Size>
+ template<typename ChunkType, typename AddressType, kstd::bytes Size>
struct chunk
{
//! The type of addresses used to index this chunk
diff --git a/kapi/kapi/memory/layout.hpp b/kapi/kapi/memory/layout.hpp
index a39997ac..bcb27fbc 100644
--- a/kapi/kapi/memory/layout.hpp
+++ b/kapi/kapi/memory/layout.hpp
@@ -13,12 +13,12 @@ namespace kapi::memory
//! The size of a single page of virtual memory.
//!
//! Platforms that use different sizes of pages are expected to emulate 4 KiB pages towards the kernel.
- constexpr auto page_size = kstd::units::KiB(4u);
+ constexpr auto page_size = kstd::KiB(4u);
//! The size of a single frame of physical memory.
//!
//! Platforms that use different sizes of frames are expected to emulate 4 KiB pages towards the kernel.
- constexpr auto frame_size = kstd::units::KiB(4u);
+ constexpr auto frame_size = kstd::KiB(4u);
//! The linear base address of the higher-half direct map.
//!
diff --git a/kernel/kapi/devices/device.tests.cpp b/kernel/kapi/devices/device.tests.cpp
index 138e1161..0746445c 100644
--- a/kernel/kapi/devices/device.tests.cpp
+++ b/kernel/kapi/devices/device.tests.cpp
@@ -141,7 +141,7 @@ SCENARIO("Devices allow access to their resources", "[kapi][devices]")
WHEN("adding an MMIO resource")
{
- auto range = kapi::devices::mmio_range{{}, kstd::units::bytes{100}};
+ auto range = kapi::devices::mmio_range{{}, kstd::bytes{100}};
device->set_resources({kapi::devices::resource{range}});
AND_WHEN("trying to get the first MMIO resource via the type-safe accessor")
@@ -652,7 +652,7 @@ SCENARIO("Devices allow access to their resources", "[kapi][devices]")
{
auto device = kstd::make_shared<kapi::devices::device>("test_device");
- auto range = kapi::devices::mmio_range{{}, kstd::units::bytes{128}};
+ auto range = kapi::devices::mmio_range{{}, kstd::bytes{128}};
auto port_a = kapi::devices::io_port{0x40, 4};
auto port_b = kapi::devices::io_port{0x50, 1};
diff --git a/kernel/kapi/filesystem.cpp b/kernel/kapi/filesystem.cpp
index d37a4cf7..419c3234 100644
--- a/kernel/kapi/filesystem.cpp
+++ b/kernel/kapi/filesystem.cpp
@@ -43,22 +43,22 @@ namespace kapi::filesystem
.and_then([=]() { return kernel::filesystem::open_file_table::get().remove_file(file_descriptor); });
}
- auto read(size_t file_descriptor, std::span<std::byte> buffer) -> kstd::result<kstd::units::bytes>
+ auto read(size_t file_descriptor, std::span<std::byte> buffer) -> kstd::result<kstd::bytes>
{
return kernel::filesystem::open_file_table::get().file(file_descriptor).and_then([=](auto descriptor) {
return descriptor->read(buffer);
});
}
- auto write(size_t file_descriptor, std::span<std::byte const> buffer) -> kstd::result<kstd::units::bytes>
+ auto write(size_t file_descriptor, std::span<std::byte const> buffer) -> kstd::result<kstd::bytes>
{
return kernel::filesystem::open_file_table::get().file(file_descriptor).and_then([=](auto descriptor) {
return descriptor->write(buffer);
});
}
- auto seek(size_t file_descriptor, kstd::units::bytes offset, seek_direction direction, seek_origin origin)
- -> kstd::result<kstd::units::bytes>
+ auto seek(size_t file_descriptor, kstd::bytes offset, seek_direction direction, seek_origin origin)
+ -> kstd::result<kstd::bytes>
{
return kernel::filesystem::open_file_table::get().file(file_descriptor).and_then([=](auto file) {
return file->seek(offset, direction, origin);
diff --git a/kernel/kapi/memory.cpp b/kernel/kapi/memory.cpp
index 4cba7238..a0445645 100644
--- a/kernel/kapi/memory.cpp
+++ b/kernel/kapi/memory.cpp
@@ -117,7 +117,7 @@ namespace kapi::memory
{
using namespace kstd::units_literals;
- auto const bitmap_bytes = kstd::units::bytes{(frame_count + 7uz) / 8uz};
+ auto const bitmap_bytes = kstd::bytes{(frame_count + 7uz) / 8uz};
auto const bitmap_pages = (bitmap_bytes + page::size - 1_B) / page::size;
auto const bitmap_frames = allocate_many_frames(bitmap_pages);
diff --git a/kernel/kernel/devices/block_device_utils.cpp b/kernel/kernel/devices/block_device_utils.cpp
index 0f85acd0..398e5e2a 100644
--- a/kernel/kernel/devices/block_device_utils.cpp
+++ b/kernel/kernel/devices/block_device_utils.cpp
@@ -18,15 +18,14 @@ namespace kernel::devices::block_device_utils
namespace
{
- using block_op = kstd::result<kstd::units::bytes> (*)(size_t idx, kstd::units::bytes off, kstd::units::bytes len,
- kstd::units::bytes done,
- kapi::filesystem::block_special_file & device,
- std::span<std::byte> scratch, std::span<std::byte> buffer);
+ using block_op = kstd::result<kstd::bytes> (*)(size_t idx, kstd::bytes off, kstd::bytes len, kstd::bytes done,
+ kapi::filesystem::block_special_file & device,
+ std::span<std::byte> scratch, std::span<std::byte> buffer);
- auto process_blocks(kapi::filesystem::block_special_file & device, kstd::units::bytes offset,
- std::span<std::byte> buffer, block_op op) -> kstd::result<kstd::units::bytes>
+ auto process_blocks(kapi::filesystem::block_special_file & device, kstd::bytes offset, std::span<std::byte> buffer,
+ block_op op) -> kstd::result<kstd::bytes>
{
- auto requested_size = kstd::units::bytes{buffer.size()};
+ auto requested_size = kstd::bytes{buffer.size()};
if (requested_size == 0_B)
{
@@ -76,8 +75,8 @@ namespace kernel::devices::block_device_utils
return {offset, to_transfer, device.block_size() - to_transfer};
}
- auto read(kapi::filesystem::block_special_file & device, std::span<std::byte> buffer, kstd::units::bytes offset)
- -> kstd::result<kstd::units::bytes>
+ auto read(kapi::filesystem::block_special_file & device, std::span<std::byte> buffer, kstd::bytes offset)
+ -> kstd::result<kstd::bytes>
{
return process_blocks(
device, offset, buffer, [](auto idx, auto off, auto len, auto done, auto & device, auto scratch, auto buffer) {
@@ -97,8 +96,8 @@ namespace kernel::devices::block_device_utils
});
}
- auto write(kapi::filesystem::block_special_file & device, std::span<std::byte const> buffer,
- kstd::units::bytes offset) -> kstd::result<kstd::units::bytes>
+ auto write(kapi::filesystem::block_special_file & device, std::span<std::byte const> buffer, kstd::bytes offset)
+ -> kstd::result<kstd::bytes>
{
auto non_cost_span = std::span{const_cast<std::byte *>(buffer.data()), buffer.size()};
return process_blocks(device, offset, non_cost_span,
diff --git a/kernel/kernel/devices/block_device_utils.hpp b/kernel/kernel/devices/block_device_utils.hpp
index 02d2f0e8..c99adf67 100644
--- a/kernel/kernel/devices/block_device_utils.hpp
+++ b/kernel/kernel/devices/block_device_utils.hpp
@@ -24,9 +24,9 @@ namespace kernel::devices::block_device_utils
*/
struct transfer_info
{
- kstd::units::bytes offset;
- kstd::units::bytes to_transfer;
- kstd::units::bytes remainder;
+ kstd::bytes offset;
+ kstd::bytes to_transfer;
+ kstd::bytes remainder;
};
[[nodiscard]] auto calculate_transfer(kapi::filesystem::block_special_file const & device, size_t block_index)
@@ -38,8 +38,8 @@ namespace kernel::devices::block_device_utils
//! @param buffer The buffer to read data into.
//! @param offset The offset on the block device to start reading from.
//! @return The number of bytes actually read, which may be less than the requested size.
- auto read(kapi::filesystem::block_special_file & device, std::span<std::byte> buffer, kstd::units::bytes offset)
- -> kstd::result<kstd::units::bytes>;
+ auto read(kapi::filesystem::block_special_file & device, std::span<std::byte> buffer, kstd::bytes offset)
+ -> kstd::result<kstd::bytes>;
//! @brief Write data from a buffer to a given block device.
//!
@@ -47,8 +47,8 @@ namespace kernel::devices::block_device_utils
//! @param buffer The buffer to write data from.
//! @param offset The offset on the block device to start writing to.
//! @return The number of bytes actually written, which may be less than the requested size.
- auto write(kapi::filesystem::block_special_file & device, std::span<std::byte const> buffer,
- kstd::units::bytes offset) -> kstd::result<kstd::units::bytes>;
+ auto write(kapi::filesystem::block_special_file & device, std::span<std::byte const> buffer, kstd::bytes offset)
+ -> kstd::result<kstd::bytes>;
} // namespace kernel::devices::block_device_utils
#endif \ No newline at end of file
diff --git a/kernel/kernel/devices/block_device_utils.tests.cpp b/kernel/kernel/devices/block_device_utils.tests.cpp
index 16a1ca87..576c9284 100644
--- a/kernel/kernel/devices/block_device_utils.tests.cpp
+++ b/kernel/kernel/devices/block_device_utils.tests.cpp
@@ -37,7 +37,7 @@ SCENARIO("reading from a block device with block_device_utils", "[devices][block
THEN("the correct number of bytes is read")
{
- REQUIRE(bytes_read == kstd::units::bytes{read_buffer.size()});
+ REQUIRE(bytes_read == kstd::bytes{read_buffer.size()});
}
THEN("the data read matches the data written to the block device")
@@ -53,7 +53,7 @@ SCENARIO("reading from a block device with block_device_utils", "[devices][block
THEN("the correct number of bytes is read")
{
- REQUIRE(bytes_read == kstd::units::bytes{static_cast<std::size_t>(1.5 * block_size.value)});
+ REQUIRE(bytes_read == kstd::bytes{static_cast<std::size_t>(1.5 * block_size.value)});
}
THEN("the data read matches the expected data across block boundaries")
@@ -110,7 +110,7 @@ SCENARIO("writing to a block device using block_device_utils", "[devices][block_
THEN("the correct number of bytes is written")
{
- REQUIRE(bytes_written == kstd::units::bytes{write_buffer.size()});
+ REQUIRE(bytes_written == kstd::bytes{write_buffer.size()});
}
THEN("the data written matches the data read back from the block device")
@@ -133,7 +133,7 @@ SCENARIO("writing to a block device using block_device_utils", "[devices][block_
THEN("the correct number of bytes is written")
{
- REQUIRE(bytes_written == kstd::units::bytes{static_cast<std::size_t>(1.5 * block_size.value)});
+ REQUIRE(bytes_written == kstd::bytes{static_cast<std::size_t>(1.5 * block_size.value)});
}
THEN("the data written matches the data read back from the block device across block boundaries")
diff --git a/kernel/kernel/drivers/pseudo/null.cpp b/kernel/kernel/drivers/pseudo/null.cpp
index f6ecf5cc..d2ae81c6 100644
--- a/kernel/kernel/drivers/pseudo/null.cpp
+++ b/kernel/kernel/drivers/pseudo/null.cpp
@@ -47,14 +47,14 @@ namespace kernel::drivers::pseudo
struct null_node final : kapi::filesystem::character_special_file
{
public:
- [[nodiscard]] auto read(std::span<std::byte>) -> kstd::result<kstd::units::bytes> override
+ [[nodiscard]] auto read(std::span<std::byte>) -> kstd::result<kstd::bytes> override
{
return 0_B;
}
- auto write(std::span<std::byte const> buffer) -> kstd::result<kstd::units::bytes> override
+ auto write(std::span<std::byte const> buffer) -> kstd::result<kstd::bytes> override
{
- return kstd::units::bytes{buffer.size()};
+ return kstd::bytes{buffer.size()};
}
};
diff --git a/kernel/kernel/drivers/pseudo/zero.cpp b/kernel/kernel/drivers/pseudo/zero.cpp
index e486a985..0d5e0f8f 100644
--- a/kernel/kernel/drivers/pseudo/zero.cpp
+++ b/kernel/kernel/drivers/pseudo/zero.cpp
@@ -47,15 +47,15 @@ namespace kernel::drivers::pseudo
struct zero_node final : kapi::filesystem::character_special_file
{
public:
- [[nodiscard]] auto read(std::span<std::byte> buffer) -> kstd::result<kstd::units::bytes> override
+ [[nodiscard]] auto read(std::span<std::byte> buffer) -> kstd::result<kstd::bytes> override
{
std::ranges::fill(buffer, std::byte{0});
- return kstd::units::bytes{buffer.size()};
+ return kstd::bytes{buffer.size()};
}
- auto write(std::span<std::byte const> buffer) -> kstd::result<kstd::units::bytes> override
+ auto write(std::span<std::byte const> buffer) -> kstd::result<kstd::bytes> override
{
- return kstd::units::bytes{buffer.size()};
+ return kstd::bytes{buffer.size()};
}
};
diff --git a/kernel/kernel/drivers/storage/ram_disk.cpp b/kernel/kernel/drivers/storage/ram_disk.cpp
index 778feeeb..186f8cbc 100644
--- a/kernel/kernel/drivers/storage/ram_disk.cpp
+++ b/kernel/kernel/drivers/storage/ram_disk.cpp
@@ -54,10 +54,10 @@ namespace kernel::drivers::storage
{}
[[nodiscard]] auto read_block(std::size_t block_index, std::span<std::byte> buffer)
- -> kstd::result<kstd::units::bytes> override
+ -> kstd::result<kstd::bytes> override
{
auto const info = devices::block_device_utils::calculate_transfer(*this, block_index);
- auto const transfer_size = std::min(info.to_transfer, kstd::units::bytes{buffer.size()});
+ auto const transfer_size = std::min(info.to_transfer, kstd::bytes{buffer.size()});
if (transfer_size > 0_B)
{
@@ -68,11 +68,10 @@ namespace kernel::drivers::storage
return transfer_size;
}
- auto write_block(std::size_t block_index, std::span<std::byte const> buffer)
- -> kstd::result<kstd::units::bytes> override
+ auto write_block(std::size_t block_index, std::span<std::byte const> buffer) -> kstd::result<kstd::bytes> override
{
auto const info = devices::block_device_utils::calculate_transfer(*this, block_index);
- auto const transfer_size = std::min(info.to_transfer, kstd::units::bytes{buffer.size()});
+ auto const transfer_size = std::min(info.to_transfer, kstd::bytes{buffer.size()});
if (transfer_size > 0_B)
{
@@ -83,14 +82,14 @@ namespace kernel::drivers::storage
return transfer_size;
}
- [[nodiscard]] auto block_size() const -> kstd::units::bytes override
+ [[nodiscard]] auto block_size() const -> kstd::bytes override
{
return kapi::memory::page_size;
}
- [[nodiscard]] auto capacity() const -> kstd::units::bytes override
+ [[nodiscard]] auto capacity() const -> kstd::bytes override
{
- return kstd::units::bytes{m_module.size};
+ return kstd::bytes{m_module.size};
}
private:
diff --git a/kernel/kernel/filesystem/devfs/inode.cpp b/kernel/kernel/filesystem/devfs/inode.cpp
index 3f222f31..4153d3ac 100644
--- a/kernel/kernel/filesystem/devfs/inode.cpp
+++ b/kernel/kernel/filesystem/devfs/inode.cpp
@@ -10,12 +10,12 @@ using namespace kstd::units_literals;
namespace kernel::filesystem::devfs
{
- auto inode::read(std::span<std::byte>, kstd::units::bytes) const -> kstd::result<kstd::units::bytes>
+ auto inode::read(std::span<std::byte>, kstd::bytes) const -> kstd::result<kstd::bytes>
{
return 0_B;
}
- auto inode::write(std::span<std::byte const>, kstd::units::bytes) -> kstd::result<kstd::units::bytes>
+ auto inode::write(std::span<std::byte const>, kstd::bytes) -> kstd::result<kstd::bytes>
{
return 0_B;
}
diff --git a/kernel/kernel/filesystem/devfs/inode.hpp b/kernel/kernel/filesystem/devfs/inode.hpp
index 6639d180..a68baef6 100644
--- a/kernel/kernel/filesystem/devfs/inode.hpp
+++ b/kernel/kernel/filesystem/devfs/inode.hpp
@@ -24,8 +24,8 @@ namespace kernel::filesystem::devfs
@param size Number of bytes requested.
@return Number of bytes read (always 0 because this inode does not expose file data).
*/
- [[nodiscard]] auto read(std::span<std::byte> buffer, kstd::units::bytes offset) const
- -> kstd::result<kstd::units::bytes> override;
+ [[nodiscard]] auto read(std::span<std::byte> buffer, kstd::bytes offset) const
+ -> kstd::result<kstd::bytes> override;
/**
@brief Writes to the devfs directory inode.
@@ -34,8 +34,7 @@ namespace kernel::filesystem::devfs
@param size Number of bytes requested.
@return Number of bytes written (always 0 because writes are not supported for this inode).
*/
- auto write(std::span<std::byte const> buffer, kstd::units::bytes offset)
- -> kstd::result<kstd::units::bytes> override;
+ auto write(std::span<std::byte const> buffer, kstd::bytes offset) -> kstd::result<kstd::bytes> override;
/**
@brief Check if this inode represents a directory.
diff --git a/kernel/kernel/filesystem/device_inode.cpp b/kernel/kernel/filesystem/device_inode.cpp
index 53201e08..f45023d3 100644
--- a/kernel/kernel/filesystem/device_inode.cpp
+++ b/kernel/kernel/filesystem/device_inode.cpp
@@ -40,8 +40,7 @@ namespace kernel::filesystem
}
}
- auto device_inode::read(std::span<std::byte> buffer, kstd::units::bytes offset) const
- -> kstd::result<kstd::units::bytes>
+ auto device_inode::read(std::span<std::byte> buffer, kstd::bytes offset) const -> kstd::result<kstd::bytes>
{
if (m_device->state() == kapi::devices::state::removed)
{
@@ -62,8 +61,7 @@ namespace kernel::filesystem
return kstd::failure(vfs_errc::no_such_device);
}
- auto device_inode::write(std::span<std::byte const> buffer, kstd::units::bytes offset)
- -> kstd::result<kstd::units::bytes>
+ auto device_inode::write(std::span<std::byte const> buffer, kstd::bytes offset) -> kstd::result<kstd::bytes>
{
if (m_device->state() == kapi::devices::state::removed)
{
diff --git a/kernel/kernel/filesystem/device_inode.hpp b/kernel/kernel/filesystem/device_inode.hpp
index 759119e7..663974ed 100644
--- a/kernel/kernel/filesystem/device_inode.hpp
+++ b/kernel/kernel/filesystem/device_inode.hpp
@@ -42,8 +42,8 @@ namespace kernel::filesystem
@param size The number of bytes to read.
@return The number of bytes read.
*/
- [[nodiscard]] auto read(std::span<std::byte> buffer, kstd::units::bytes offset) const
- -> kstd::result<kstd::units::bytes> override;
+ [[nodiscard]] auto read(std::span<std::byte> buffer, kstd::bytes offset) const
+ -> kstd::result<kstd::bytes> override;
/**
@brief Write data to the device inode (and in the background from the associated device) from a @p buffer, starting
@@ -53,8 +53,7 @@ namespace kernel::filesystem
@param size The number of bytes to write.
@return The number of bytes written.
*/
- auto write(std::span<std::byte const> buffer, kstd::units::bytes offset)
- -> kstd::result<kstd::units::bytes> override;
+ auto write(std::span<std::byte const> buffer, kstd::bytes offset) -> kstd::result<kstd::bytes> override;
/**
@brief Get the associated device.
diff --git a/kernel/kernel/filesystem/device_inode.tests.cpp b/kernel/kernel/filesystem/device_inode.tests.cpp
index 2a5e54c7..c4b117fb 100644
--- a/kernel/kernel/filesystem/device_inode.tests.cpp
+++ b/kernel/kernel/filesystem/device_inode.tests.cpp
@@ -39,12 +39,12 @@ namespace
struct mock_origin_inode : kernel::filesystem::inode
{
- auto read(std::span<std::byte>, kstd::units::bytes) const -> kstd::result<kstd::units::bytes> override
+ auto read(std::span<std::byte>, kstd::bytes) const -> kstd::result<kstd::bytes> override
{
return 0_B;
}
- auto write(std::span<std::byte const>, kstd::units::bytes) -> kstd::result<kstd::units::bytes> override
+ auto write(std::span<std::byte const>, kstd::bytes) -> kstd::result<kstd::bytes> override
{
return 0_B;
}
diff --git a/kernel/kernel/filesystem/device_number_registry.tests.cpp b/kernel/kernel/filesystem/device_number_registry.tests.cpp
index 865a6de9..913acf9a 100644
--- a/kernel/kernel/filesystem/device_number_registry.tests.cpp
+++ b/kernel/kernel/filesystem/device_number_registry.tests.cpp
@@ -23,7 +23,7 @@ using namespace kstd::units_literals;
namespace
{
auto make_bound_block_device(kapi::devices::facet_registry & facets, kstd::string const & name,
- kstd::units::bytes block_size, std::optional<std::uint8_t> major)
+ kstd::bytes block_size, std::optional<std::uint8_t> major)
-> kstd::shared_ptr<kernel::tests::devices::block_device>
{
auto device = kstd::make_shared<kernel::tests::devices::block_device>(name, block_size);
diff --git a/kernel/kernel/filesystem/ext2/filesystem.cpp b/kernel/kernel/filesystem/ext2/filesystem.cpp
index 08f827a6..7a1153e4 100644
--- a/kernel/kernel/filesystem/ext2/filesystem.cpp
+++ b/kernel/kernel/filesystem/ext2/filesystem.cpp
@@ -163,7 +163,7 @@ namespace kernel::filesystem::ext2
return read_inode(entry->inode);
}
- bytes_read += kstd::units::bytes{entry->rec_len};
+ bytes_read += kstd::bytes{entry->rec_len};
entry = reinterpret_cast<linked_directory_entry const *>(buffer.data() + bytes_read);
}
}
@@ -273,21 +273,21 @@ namespace kernel::filesystem::ext2
while (true)
{
auto const * entry = reinterpret_cast<linked_directory_entry const *>(buffer.data() + offset);
- if (offset + kstd::units::bytes{entry->rec_len} >= block_size())
+ if (offset + kstd::bytes{entry->rec_len} >= block_size())
{
break;
}
- offset += kstd::units::bytes{entry->rec_len};
+ offset += kstd::bytes{entry->rec_len};
}
auto const file_type = map_inode_mode_to_file_type(mode);
auto const name_len = static_cast<uint8_t>(name.size());
- auto const needed_rec_len = static_cast<kstd::units::bytes>((8u + name_len + 3u) & ~3u);
+ auto const needed_rec_len = static_cast<kstd::bytes>((8u + name_len + 3u) & ~3u);
auto * last_entry = reinterpret_cast<linked_directory_entry *>(buffer.data() + offset);
- auto const last_entry_actual_len = static_cast<kstd::units::bytes>((8u + last_entry->name_len + 3u) & ~3u);
+ auto const last_entry_actual_len = static_cast<kstd::bytes>((8u + last_entry->name_len + 3u) & ~3u);
- if (kstd::units::bytes{last_entry->rec_len} - last_entry_actual_len >= needed_rec_len)
+ if (kstd::bytes{last_entry->rec_len} - last_entry_actual_len >= needed_rec_len)
{
last_entry->rec_len = last_entry_actual_len.value;
write_directory_entry_to_buffer(buffer.data(), offset + last_entry_actual_len, child_inode_number, name,
@@ -339,7 +339,7 @@ namespace kernel::filesystem::ext2
kstd::vector<uint8_t> buffer(block_size().value, 0);
write_directory_entry_to_buffer(buffer.data(), 0_B, new_inode->number(), ".", 2);
- auto const dot_actual_len = static_cast<kstd::units::bytes>((8u + 1 + 3u) & ~3u);
+ auto const dot_actual_len = static_cast<kstd::bytes>((8u + 1 + 3u) & ~3u);
auto * entry = reinterpret_cast<linked_directory_entry *>(buffer.data());
entry->rec_len = dot_actual_len.value;
@@ -355,7 +355,7 @@ namespace kernel::filesystem::ext2
.transform([](auto) {});
}
- auto filesystem::write_directory_entry_to_buffer(uint8_t * block_buffer, kstd::units::bytes offset,
+ auto filesystem::write_directory_entry_to_buffer(uint8_t * block_buffer, kstd::bytes offset,
uint32_t child_inode_number, std::string_view name,
uint8_t file_type) -> void
{
@@ -402,7 +402,7 @@ namespace kernel::filesystem::ext2
}
}
- auto filesystem::calculate_inode_offset(uint32_t inode_number) const -> kstd::result<kstd::units::bytes>
+ auto filesystem::calculate_inode_offset(uint32_t inode_number) const -> kstd::result<kstd::bytes>
{
auto const inodes_per_group = m_superblock.inodes_per_group;
auto const block_group_index = (inode_number - 1) / inodes_per_group;
@@ -699,13 +699,13 @@ namespace kernel::filesystem::ext2
return kstd::success();
}
- auto filesystem::read_block(uint32_t block_number, void * buffer) const -> kstd::result<kstd::units::bytes>
+ auto filesystem::read_block(uint32_t block_number, void * buffer) const -> kstd::result<kstd::bytes>
{
auto const block_offset = static_cast<size_t>(block_number) * block_size();
return m_backing_inode->read(std::span{static_cast<std::byte *>(buffer), block_size().value}, block_offset);
}
- auto filesystem::write_block(uint32_t block_number, void const * buffer) -> kstd::result<kstd::units::bytes>
+ auto filesystem::write_block(uint32_t block_number, void const * buffer) -> kstd::result<kstd::bytes>
{
auto const block_offset = static_cast<size_t>(block_number) * block_size();
return m_backing_inode->write(std::span{static_cast<std::byte const *>(buffer), block_size().value}, block_offset);
@@ -784,9 +784,9 @@ namespace kernel::filesystem::ext2
return block_numbers_per_doubly_indirect_block() * block_numbers_per_block();
}
- auto filesystem::block_size() const -> kstd::units::bytes
+ auto filesystem::block_size() const -> kstd::bytes
{
- return kstd::units::bytes{constants::base_block_size.value << m_superblock.log_block_size};
+ return kstd::bytes{constants::base_block_size.value << m_superblock.log_block_size};
}
auto filesystem::revision_level() const -> uint32_t
@@ -794,9 +794,9 @@ namespace kernel::filesystem::ext2
return m_superblock.rev_level;
}
- auto filesystem::inode_size() const -> kstd::units::bytes
+ auto filesystem::inode_size() const -> kstd::bytes
{
- return kstd::units::bytes(revision_level() == constants::good_old_revision ? 128 : m_superblock.inode_size);
+ return kstd::bytes(revision_level() == constants::good_old_revision ? 128 : m_superblock.inode_size);
}
auto filesystem::inode_block_count(inode_data const & data) const -> uint32_t
@@ -809,7 +809,7 @@ namespace kernel::filesystem::ext2
data.blocks += delta * (2 << m_superblock.log_block_size);
}
- auto filesystem::block_group_descriptor_table_offset() const -> kstd::units::bytes
+ auto filesystem::block_group_descriptor_table_offset() const -> kstd::bytes
{
return block_size() == 1024_B ? 2 * block_size() : block_size();
}
diff --git a/kernel/kernel/filesystem/ext2/filesystem.hpp b/kernel/kernel/filesystem/ext2/filesystem.hpp
index b8794a14..d7132f39 100644
--- a/kernel/kernel/filesystem/ext2/filesystem.hpp
+++ b/kernel/kernel/filesystem/ext2/filesystem.hpp
@@ -29,8 +29,8 @@ namespace kernel::filesystem::ext2
*/
namespace constants
{
- constexpr kstd::units::bytes inline base_block_size = kstd::units::bytes{1024};
- constexpr kstd::units::bytes inline superblock_offset = base_block_size;
+ 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 uint32_t inline good_old_revision = 0;
@@ -89,7 +89,7 @@ namespace kernel::filesystem::ext2
@brief Gets the size of a block in the filesystem.
@return The size of a block in bytes.
*/
- [[nodiscard]] auto block_size() const -> kstd::units::bytes;
+ [[nodiscard]] auto block_size() const -> kstd::bytes;
/**
@brief Gets the revision level of the filesystem.
@@ -103,7 +103,7 @@ namespace kernel::filesystem::ext2
@param buffer The buffer to read the block data into.
@return The number of bytes read.
*/
- auto read_block(uint32_t block_number, void * buffer) const -> kstd::result<kstd::units::bytes>;
+ auto read_block(uint32_t block_number, void * buffer) const -> kstd::result<kstd::bytes>;
/**
@brief Writes a block of data from the provided buffer to the backing device.
@@ -111,7 +111,7 @@ namespace kernel::filesystem::ext2
@param buffer The buffer containing the data to write.
@return The number of bytes written.
*/
- auto write_block(uint32_t block_number, void const * buffer) -> kstd::result<kstd::units::bytes>;
+ auto write_block(uint32_t block_number, void const * buffer) -> kstd::result<kstd::bytes>;
/**
@brief Allocates a specified number of blocks.
@@ -124,7 +124,7 @@ namespace kernel::filesystem::ext2
@brief Gets the size of an inode in the filesystem.
@return The size of an inode in bytes.
*/
- [[nodiscard]] auto inode_size() const -> kstd::units::bytes;
+ [[nodiscard]] auto inode_size() const -> kstd::bytes;
/**
@brief Gets the number of blocks allocated to an inode.
@@ -179,14 +179,14 @@ namespace kernel::filesystem::ext2
-> kstd::result<void>;
auto init_directory(kstd::shared_ptr<kernel::filesystem::ext2::inode> const & new_inode,
kernel::filesystem::ext2::inode * parent_inode) -> kstd::result<void>;
- auto write_directory_entry_to_buffer(uint8_t * block_buffer, kstd::units::bytes offset, uint32_t child_inode_number,
+ auto write_directory_entry_to_buffer(uint8_t * block_buffer, kstd::bytes offset, uint32_t child_inode_number,
std::string_view name, uint8_t file_type) -> void;
- [[nodiscard]] auto calculate_inode_offset(uint32_t inode_number) const -> kstd::result<kstd::units::bytes>;
+ [[nodiscard]] auto calculate_inode_offset(uint32_t inode_number) const -> kstd::result<kstd::bytes>;
[[nodiscard]] auto read_inode(uint32_t inode_number) const -> kstd::result<kstd::shared_ptr<inode>>;
[[nodiscard]] auto read_block_number_at_index(uint32_t block_number, size_t index) const -> kstd::result<uint32_t>;
- [[nodiscard]] auto block_group_descriptor_table_offset() const -> kstd::units::bytes;
+ [[nodiscard]] auto block_group_descriptor_table_offset() const -> kstd::bytes;
[[nodiscard]] auto block_numbers_per_block() const -> size_t;
[[nodiscard]] auto block_numbers_per_singly_indirect_block() const -> size_t;
diff --git a/kernel/kernel/filesystem/ext2/filesystem.tests.cpp b/kernel/kernel/filesystem/ext2/filesystem.tests.cpp
index 6bd17188..f6ade274 100644
--- a/kernel/kernel/filesystem/ext2/filesystem.tests.cpp
+++ b/kernel/kernel/filesystem/ext2/filesystem.tests.cpp
@@ -150,11 +150,11 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_fixture,
std::vector{std::byte{'H'}, std::byte{'e'}, std::byte{'l'}, std::byte{'l'}, std::byte{'o'}, std::byte{' '},
std::byte{'W'}, std::byte{'o'}, std::byte{'r'}, std::byte{'l'}, std::byte{'d'}, std::byte{'!'}};
auto bytes_written = new_inode.value()->write(buffer, 0_B);
- REQUIRE(bytes_written == kstd::units::bytes{buffer.size()});
+ REQUIRE(bytes_written == kstd::bytes{buffer.size()});
auto read_buffer = std::vector<std::byte>(5, std::byte{0xAA});
auto bytes_read = new_inode.value()->read(read_buffer, 0_B);
- REQUIRE(bytes_read == kstd::units::bytes{read_buffer.size()});
+ REQUIRE(bytes_read == kstd::bytes{read_buffer.size()});
std::string_view result{reinterpret_cast<char *>(read_buffer.data()), static_cast<size_t>(*bytes_read)};
REQUIRE(result == "Hello");
@@ -276,7 +276,7 @@ SCENARIO("Ext2 block writing includes direct and all indirect levels", "[filesys
auto fs = kernel::filesystem::ext2::filesystem{};
REQUIRE(fs.mount(dev_inode));
- auto read_u32 = [&](kstd::units::bytes offset) -> uint32_t {
+ auto read_u32 = [&](kstd::bytes offset) -> uint32_t {
auto value = uint32_t{0};
std::memcpy(&value, device->data.data() + offset, sizeof(value));
return value;
@@ -301,12 +301,12 @@ SCENARIO("Ext2 block writing includes direct and all indirect levels", "[filesys
REQUIRE(fs.write_global_block_number_to_inode_block_index(singly_start, inode_data, singly_global_block_number));
REQUIRE(inode_data.block[12] == 16);
- REQUIRE(read_u32(static_cast<kstd::units::bytes>(inode_data.block[12]) * block_size.value) ==
+ REQUIRE(read_u32(static_cast<kstd::bytes>(inode_data.block[12]) * block_size.value) ==
singly_global_block_number);
REQUIRE(fs.write_global_block_number_to_inode_block_index(singly_start + 1, inode_data,
singly_global_block_number + 1));
- REQUIRE(read_u32(static_cast<kstd::units::bytes>(inode_data.block[12]) * block_size.value +
+ REQUIRE(read_u32(static_cast<kstd::bytes>(inode_data.block[12]) * block_size.value +
1 * kstd::size_of<uint32_t>()) == singly_global_block_number + 1);
REQUIRE(fs.write_global_block_number_to_inode_block_index(doubly_start, inode_data, doubly_global_block_number));
diff --git a/kernel/kernel/filesystem/ext2/inode.cpp b/kernel/kernel/filesystem/ext2/inode.cpp
index cba0e70c..5f161e82 100644
--- a/kernel/kernel/filesystem/ext2/inode.cpp
+++ b/kernel/kernel/filesystem/ext2/inode.cpp
@@ -31,12 +31,12 @@ namespace kernel::filesystem::ext2
}
}
- auto inode::read(std::span<std::byte> buffer, kstd::units::bytes offset) const -> kstd::result<kstd::units::bytes>
+ auto inode::read(std::span<std::byte> buffer, kstd::bytes offset) const -> kstd::result<kstd::bytes>
{
auto const max_readable = this->size() - offset;
- auto const requested_size = std::min(kstd::units::bytes{buffer.size()}, max_readable);
+ auto const requested_size = std::min(kstd::bytes{buffer.size()}, max_readable);
- if (is_symbolic_link() && this->size() <= kstd::units::bytes{sizeof(m_data.block)})
+ if (is_symbolic_link() && this->size() <= kstd::bytes{sizeof(m_data.block)})
{
auto inline_target = reinterpret_cast<uint8_t const *>(m_data.block.data());
kstd::libc::memcpy(buffer.data(), inline_target + offset, requested_size.value);
@@ -83,7 +83,7 @@ namespace kernel::filesystem::ext2
return bytes_read;
}
- auto inode::write(std::span<std::byte const> buffer, kstd::units::bytes offset) -> kstd::result<kstd::units::bytes>
+ auto inode::write(std::span<std::byte const> buffer, kstd::bytes offset) -> kstd::result<kstd::bytes>
{
if (!is_regular())
{
@@ -93,7 +93,7 @@ namespace kernel::filesystem::ext2
// TODO check maximum file size of filesystem
// TODO handle sparse files
- auto const new_inode_size = std::max(this->size(), offset + kstd::units::bytes{buffer.size()});
+ auto const new_inode_size = std::max(this->size(), offset + kstd::bytes{buffer.size()});
auto const current_block_count = m_filesystem->inode_block_count(m_data);
auto const max_new_inode_size_without_new_blocks = current_block_count * m_filesystem->block_size();
@@ -116,7 +116,7 @@ namespace kernel::filesystem::ext2
auto bytes_written = 0_B;
- while (bytes_written < kstd::units::bytes{buffer.size()})
+ while (bytes_written < kstd::bytes{buffer.size()})
{
auto const block_number = m_filesystem->map_inode_block_index_to_global_block_number(block_index, m_data);
// TODO BA-FS26 if blocknumber == 0 --> handle sparse file
@@ -126,7 +126,7 @@ namespace kernel::filesystem::ext2
}
auto const bytes_to_write =
- std::min(kstd::units::bytes{buffer.size()} - bytes_written, m_filesystem->block_size() - in_block_offset);
+ std::min(kstd::bytes{buffer.size()} - bytes_written, m_filesystem->block_size() - in_block_offset);
auto const block_start_offset = block_number.value() * m_filesystem->block_size();
auto const write_offset = block_start_offset + in_block_offset;
@@ -244,7 +244,7 @@ namespace kernel::filesystem::ext2
};
}
- auto inode::size() const -> kstd::units::bytes
+ auto inode::size() const -> kstd::bytes
{
uint64_t size = m_data.size;
@@ -253,10 +253,10 @@ namespace kernel::filesystem::ext2
size |= static_cast<uint64_t>(m_data.dir_acl) << 32;
}
- return kstd::units::bytes{size};
+ return kstd::bytes{size};
}
- auto inode::set_size(kstd::units::bytes new_size) -> void
+ auto inode::set_size(kstd::bytes new_size) -> void
{
if (m_filesystem->revision_level() > constants::good_old_revision && is_regular())
{
diff --git a/kernel/kernel/filesystem/ext2/inode.hpp b/kernel/kernel/filesystem/ext2/inode.hpp
index 9d145dfc..7937c643 100644
--- a/kernel/kernel/filesystem/ext2/inode.hpp
+++ b/kernel/kernel/filesystem/ext2/inode.hpp
@@ -61,8 +61,8 @@ namespace kernel::filesystem::ext2
@param size Number of bytes requested.
@return Number of bytes read.
*/
- [[nodiscard]] auto read(std::span<std::byte> buffer, kstd::units::bytes offset) const
- -> kstd::result<kstd::units::bytes> override;
+ [[nodiscard]] auto read(std::span<std::byte> buffer, kstd::bytes offset) const
+ -> kstd::result<kstd::bytes> override;
/**
@brief Writes to the ext2 inode into a @p buffer, starting at the specified @p offset and for a given @p size.
@@ -71,8 +71,7 @@ namespace kernel::filesystem::ext2
@param size Number of bytes requested.
@return Number of bytes written.
*/
- auto write(std::span<std::byte const> buffer, kstd::units::bytes offset)
- -> kstd::result<kstd::units::bytes> override;
+ auto write(std::span<std::byte const> buffer, kstd::bytes offset) -> kstd::result<kstd::bytes> override;
/**
@brief Appends the specified number of blocks to the inode.
@@ -123,13 +122,13 @@ namespace kernel::filesystem::ext2
@brief Get the size of the file represented by this inode.
@return The size of the file in bytes.
*/
- [[nodiscard]] auto size() const -> kstd::units::bytes;
+ [[nodiscard]] auto size() const -> kstd::bytes;
/**
@brief Set the size of the file represented by this inode.
@param new_size The new size of the file in bytes.
*/
- auto set_size(kstd::units::bytes new_size) -> void;
+ auto set_size(kstd::bytes new_size) -> void;
/**
@brief Get the inode number of this inode.
diff --git a/kernel/kernel/filesystem/ext2/inode.tests.cpp b/kernel/kernel/filesystem/ext2/inode.tests.cpp
index 78695b51..13e9d414 100644
--- a/kernel/kernel/filesystem/ext2/inode.tests.cpp
+++ b/kernel/kernel/filesystem/ext2/inode.tests.cpp
@@ -169,7 +169,7 @@ SCENARIO("Ext2 inode handles zeros in block mappings as file holes", "[filesyste
THEN("correct number of bytes are read and holes are returned as zeros")
{
auto const bytes_read = inode.read(buffer, 0_B);
- REQUIRE(bytes_read == kstd::units::bytes{data.size});
+ REQUIRE(bytes_read == kstd::bytes{data.size});
auto const text = std::string_view{reinterpret_cast<char const *>(buffer.data()), bytes_read->value};
REQUIRE(text.substr(0, 5) == "Hello");
@@ -211,7 +211,7 @@ SCENARIO("Ext2 inode handles zeros in block mappings as file holes", "[filesyste
THEN("correct number of bytes are read and holes are returned as zeros")
{
auto const bytes_read = inode.read(buffer, 0_B);
- REQUIRE(bytes_read == kstd::units::bytes{data.size});
+ REQUIRE(bytes_read == kstd::bytes{data.size});
auto const text = std::string_view{reinterpret_cast<char const *>(buffer.data()), bytes_read->value};
REQUIRE(text.substr(0, 5) == "Hello");
@@ -247,7 +247,7 @@ SCENARIO("Ext2 inode handles zeros in block mappings as file holes", "[filesyste
THEN("all direct blocks are zero when singly indirect block pointer is zero")
{
auto const bytes_read = inode.read(buffer, 0_B);
- REQUIRE(bytes_read == kstd::units::bytes{buffer.size()});
+ REQUIRE(bytes_read == kstd::bytes{buffer.size()});
REQUIRE(std::ranges::all_of(buffer, [](std::byte c) { return c == std::byte{0x00}; }));
}
}
@@ -280,7 +280,7 @@ SCENARIO("Ext2 inode read across block boundaries", "[filesystem][ext2][inode]")
THEN("reading across the block boundary returns the combined content")
{
auto const bytes_read = inode.read(buffer, block_size - 6_B);
- REQUIRE(bytes_read == kstd::units::bytes{12});
+ REQUIRE(bytes_read == kstd::bytes{12});
auto const text = std::string_view{reinterpret_cast<char const *>(buffer.data()), bytes_read->value};
REQUIRE(text == "Hello World!");
@@ -318,11 +318,11 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_fixture, "Ext2 in
std::byte{'r'}, std::byte{'l'}, std::byte{'d'}, std::byte{'!'}};
auto const bytes_written = file.value()->write(write_buffer, 0_B);
- REQUIRE(bytes_written == kstd::units::bytes{12});
+ REQUIRE(bytes_written == kstd::bytes{12});
auto read_buffer = kstd::vector<std::byte>(42, std::byte{0x00});
auto const bytes_read = file.value()->read(read_buffer, 0_B);
- REQUIRE(bytes_read == kstd::units::bytes{12});
+ REQUIRE(bytes_read == kstd::bytes{12});
auto const text = std::string_view{reinterpret_cast<char const *>(read_buffer.data()), bytes_read->value};
REQUIRE(text == "Hello World!");
@@ -450,7 +450,7 @@ SCENARIO("Ext2 inode write across block boundaries", "[filesystem][ext2][inode]"
{
auto const offset = block_size - 4_B;
auto const bytes_written = inode.write(buffer, offset);
- REQUIRE(bytes_written == kstd::units::bytes{buffer.size()});
+ REQUIRE(bytes_written == kstd::bytes{buffer.size()});
auto const text = std::string_view{
reinterpret_cast<char const *>(device->data.data() + 21 * block_size.value - 4), bytes_written->value};
@@ -461,7 +461,7 @@ SCENARIO("Ext2 inode write across block boundaries", "[filesystem][ext2][inode]"
REQUIRE(block_bitmap == read_block_bitmap);
auto read_inode = do_read_inode();
- REQUIRE(offset + kstd::units::bytes{buffer.size()} == read_inode.size());
+ REQUIRE(offset + kstd::bytes{buffer.size()} == read_inode.size());
REQUIRE(inode_data.blocks == read_inode.data().blocks);
auto const current_blocks = inode_data.block;
@@ -473,7 +473,7 @@ SCENARIO("Ext2 inode write across block boundaries", "[filesystem][ext2][inode]"
{
auto const offset = block_size * 2 - 4_B;
auto const bytes_written = inode.write(buffer, offset);
- REQUIRE(bytes_written == kstd::units::bytes{buffer.size()});
+ REQUIRE(bytes_written == kstd::bytes{buffer.size()});
auto read_buffer = std::vector<std::byte>(buffer.size(), std::byte{0x00});
auto const bytes_read = inode.read(read_buffer, offset);
@@ -488,7 +488,7 @@ SCENARIO("Ext2 inode write across block boundaries", "[filesystem][ext2][inode]"
REQUIRE(expected_block_bitmap == read_block_bitmap);
auto read_inode = do_read_inode();
- REQUIRE(offset + kstd::units::bytes{buffer.size()} == read_inode.size());
+ REQUIRE(offset + kstd::bytes{buffer.size()} == read_inode.size());
REQUIRE(inode_data.blocks + 2 == read_inode.data().blocks);
auto expected_blocks = inode_data.block;
@@ -535,7 +535,7 @@ 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::units::bytes expected_initial_size,
+ auto const verify_size_and_set_size = [&](uint16_t mode, kstd::bytes expected_initial_size,
uint32_t expected_dir_acl_after_set_size) {
data.mode = mode;
@@ -578,7 +578,7 @@ 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::units::bytes expected_initial_size,
+ auto const verify_size_and_set_size = [&](uint16_t mode, kstd::bytes expected_initial_size,
uint32_t expected_dir_acl_after_set_size) {
data.mode = mode;
diff --git a/kernel/kernel/filesystem/inode.hpp b/kernel/kernel/filesystem/inode.hpp
index 7ebac995..f0fbf689 100644
--- a/kernel/kernel/filesystem/inode.hpp
+++ b/kernel/kernel/filesystem/inode.hpp
@@ -27,8 +27,8 @@ namespace kernel::filesystem
//! @param offset Read offset in bytes.
//! @param size Number of bytes requested.
//! @return The number of bytes read on success, an error otherwise.
- [[nodiscard]] virtual auto read(std::span<std::byte> buffer, kstd::units::bytes offset) const
- -> kstd::result<kstd::units::bytes> = 0;
+ [[nodiscard]] virtual auto read(std::span<std::byte> buffer, kstd::bytes offset) const
+ -> kstd::result<kstd::bytes> = 0;
//! Writes data from a buffer into this inode.
//!
@@ -36,8 +36,7 @@ namespace kernel::filesystem
//! @param offset Write offset in bytes.
//! @param size Number of bytes to write.
//! @return The number of bytes written on success, an error otherwise.
- virtual auto write(std::span<std::byte const> buffer, kstd::units::bytes offset)
- -> kstd::result<kstd::units::bytes> = 0;
+ virtual auto write(std::span<std::byte const> buffer, kstd::bytes offset) -> kstd::result<kstd::bytes> = 0;
//! Check if this inode is a directory.
//!
diff --git a/kernel/kernel/filesystem/open_file_descriptor.cpp b/kernel/kernel/filesystem/open_file_descriptor.cpp
index 379b0708..a6d97b8e 100644
--- a/kernel/kernel/filesystem/open_file_descriptor.cpp
+++ b/kernel/kernel/filesystem/open_file_descriptor.cpp
@@ -25,7 +25,7 @@ namespace kernel::filesystem
}
}
- auto open_file_descriptor::read(std::span<std::byte> buffer) -> kstd::result<kstd::units::bytes>
+ auto open_file_descriptor::read(std::span<std::byte> buffer) -> kstd::result<kstd::bytes>
{
if (auto result = m_dentry->get_inode()->read(buffer, m_offset); !result)
{
@@ -39,7 +39,7 @@ namespace kernel::filesystem
}
}
- auto open_file_descriptor::write(std::span<std::byte const> buffer) -> kstd::result<kstd::units::bytes>
+ auto open_file_descriptor::write(std::span<std::byte const> buffer) -> kstd::result<kstd::bytes>
{
if (auto result = m_dentry->get_inode()->write(buffer, m_offset); !result)
{
@@ -53,8 +53,8 @@ namespace kernel::filesystem
}
}
- auto open_file_descriptor::seek(kstd::units::bytes offset, kapi::filesystem::seek_direction direction,
- kapi::filesystem::seek_origin origin) -> kstd::result<kstd::units::bytes>
+ auto open_file_descriptor::seek(kstd::bytes offset, kapi::filesystem::seek_direction direction,
+ kapi::filesystem::seek_origin origin) -> kstd::result<kstd::bytes>
{
switch (origin)
{
@@ -96,7 +96,7 @@ namespace kernel::filesystem
return kstd::failure(vfs_errc::invalid_argument);
}
- auto open_file_descriptor::offset() const -> kstd::units::bytes
+ auto open_file_descriptor::offset() const -> kstd::bytes
{
return m_offset;
}
diff --git a/kernel/kernel/filesystem/open_file_descriptor.hpp b/kernel/kernel/filesystem/open_file_descriptor.hpp
index f0b55d72..25dbf719 100644
--- a/kernel/kernel/filesystem/open_file_descriptor.hpp
+++ b/kernel/kernel/filesystem/open_file_descriptor.hpp
@@ -38,7 +38,7 @@ namespace kernel::filesystem
@param buffer The buffer to read data into.
@return The number of bytes read.
*/
- auto read(std::span<std::byte> buffer) -> kstd::result<kstd::units::bytes>;
+ auto read(std::span<std::byte> buffer) -> kstd::result<kstd::bytes>;
/**
@brief Writes data to the open file descriptor from a @p buffer, starting at the current file offset and for a
@@ -47,7 +47,7 @@ namespace kernel::filesystem
@param buffer The buffer to write data from.
@return The number of bytes written.
*/
- auto write(std::span<std::byte const> buffer) -> kstd::result<kstd::units::bytes>;
+ auto write(std::span<std::byte const> buffer) -> kstd::result<kstd::bytes>;
//! Move the read/write offset of the file.
//!
@@ -55,14 +55,14 @@ namespace kernel::filesystem
//! @param offset The direction to seek in, relative to the given origin.
//! @param origin The origin of the offset.
//! @return the new offset on success, an error otherwise.
- auto seek(kstd::units::bytes offset, kapi::filesystem::seek_direction direction,
- kapi::filesystem::seek_origin origin) -> kstd::result<kstd::units::bytes>;
+ auto seek(kstd::bytes offset, kapi::filesystem::seek_direction direction, kapi::filesystem::seek_origin origin)
+ -> kstd::result<kstd::bytes>;
/**
@brief Returns the current file offset for this open file descriptor.
@return The current file offset in bytes.
*/
- [[nodiscard]] auto offset() const -> kstd::units::bytes;
+ [[nodiscard]] auto offset() const -> kstd::bytes;
/**
@brief Return a reference to the dentry associated with this open file descriptor.
@@ -72,7 +72,7 @@ namespace kernel::filesystem
private:
kstd::shared_ptr<dentry> m_dentry;
- kstd::units::bytes m_offset;
+ kstd::bytes m_offset;
};
} // namespace kernel::filesystem
diff --git a/kernel/kernel/filesystem/open_file_descriptor.tests.cpp b/kernel/kernel/filesystem/open_file_descriptor.tests.cpp
index ec86e8d3..a2e30c16 100644
--- a/kernel/kernel/filesystem/open_file_descriptor.tests.cpp
+++ b/kernel/kernel/filesystem/open_file_descriptor.tests.cpp
@@ -118,12 +118,12 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "Ope
{
kstd::vector<std::byte> buffer(4);
auto bytes_read_1 = ofd->read(std::span{buffer}.first(buffer.size() / 2));
- REQUIRE(bytes_read_1 == kstd::units::bytes{buffer.size() / 2});
- REQUIRE(ofd->offset() == kstd::units::bytes{buffer.size() / 2});
+ REQUIRE(bytes_read_1 == kstd::bytes{buffer.size() / 2});
+ REQUIRE(ofd->offset() == kstd::bytes{buffer.size() / 2});
auto bytes_read_2 = ofd->read(std::span{buffer}.last(buffer.size() / 2));
- REQUIRE(bytes_read_2 == kstd::units::bytes{buffer.size() / 2});
- REQUIRE(ofd->offset() == kstd::units::bytes{buffer.size()});
+ REQUIRE(bytes_read_2 == kstd::bytes{buffer.size() / 2});
+ REQUIRE(ofd->offset() == kstd::bytes{buffer.size()});
std::string_view buffer_as_str{reinterpret_cast<char *>(buffer.data()),
bytes_read_1->value + bytes_read_2->value};
@@ -142,12 +142,12 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "Ope
{
auto write_buffer = kstd::vector<std::byte>(8, std::byte{0xAA});
auto const bytes_written_1 = ofd->write(std::span{write_buffer}.first(write_buffer.size() / 2));
- REQUIRE(bytes_written_1 == kstd::units::bytes{write_buffer.size() / 2});
- REQUIRE(ofd->offset() == kstd::units::bytes{write_buffer.size() / 2});
+ REQUIRE(bytes_written_1 == kstd::bytes{write_buffer.size() / 2});
+ REQUIRE(ofd->offset() == kstd::bytes{write_buffer.size() / 2});
auto const bytes_written_2 = ofd->write(std::span{write_buffer}.last(write_buffer.size() / 2));
- REQUIRE(bytes_written_2 == kstd::units::bytes{write_buffer.size() / 2});
- REQUIRE(ofd->offset() == kstd::units::bytes{write_buffer.size()});
+ REQUIRE(bytes_written_2 == kstd::bytes{write_buffer.size() / 2});
+ REQUIRE(ofd->offset() == kstd::bytes{write_buffer.size()});
}
}
}
diff --git a/kernel/kernel/filesystem/rootfs/inode.cpp b/kernel/kernel/filesystem/rootfs/inode.cpp
index 07607417..0ee0b517 100644
--- a/kernel/kernel/filesystem/rootfs/inode.cpp
+++ b/kernel/kernel/filesystem/rootfs/inode.cpp
@@ -10,14 +10,14 @@
namespace kernel::filesystem::rootfs
{
- auto inode::read(std::span<std::byte>, kstd::units::bytes) const -> kstd::result<kstd::units::bytes>
+ auto inode::read(std::span<std::byte>, kstd::bytes) const -> kstd::result<kstd::bytes>
{
- return kstd::units::bytes{};
+ return kstd::bytes{};
}
- auto inode::write(std::span<std::byte const>, kstd::units::bytes) -> kstd::result<kstd::units::bytes>
+ auto inode::write(std::span<std::byte const>, kstd::bytes) -> kstd::result<kstd::bytes>
{
- return kstd::units::bytes{};
+ return kstd::bytes{};
}
auto inode::is_directory() const -> bool
diff --git a/kernel/kernel/filesystem/rootfs/inode.hpp b/kernel/kernel/filesystem/rootfs/inode.hpp
index e9c6e738..82df2f1a 100644
--- a/kernel/kernel/filesystem/rootfs/inode.hpp
+++ b/kernel/kernel/filesystem/rootfs/inode.hpp
@@ -25,8 +25,8 @@ namespace kernel::filesystem::rootfs
@param offset Read offset in bytes.
@return Number of bytes read (always 0 because this inode does not expose file data).
*/
- [[nodiscard]] auto read(std::span<std::byte> buffer, kstd::units::bytes offset) const
- -> kstd::result<kstd::units::bytes> override;
+ [[nodiscard]] auto read(std::span<std::byte> buffer, kstd::bytes offset) const
+ -> kstd::result<kstd::bytes> override;
/**
@brief Writes to the rootfs directory inode.
@@ -34,8 +34,7 @@ namespace kernel::filesystem::rootfs
@param offset Write offset in bytes.
@return Number of bytes written (always 0 because writes are not supported for this inode).
*/
- auto write(std::span<std::byte const> buffer, kstd::units::bytes offset)
- -> kstd::result<kstd::units::bytes> override;
+ auto write(std::span<std::byte const> buffer, kstd::bytes offset) -> kstd::result<kstd::bytes> override;
/**
@brief Check if this inode represents a directory.
diff --git a/kernel/kernel/filesystem/vfs.tests.cpp b/kernel/kernel/filesystem/vfs.tests.cpp
index 8693b9f5..a035e083 100644
--- a/kernel/kernel/filesystem/vfs.tests.cpp
+++ b/kernel/kernel/filesystem/vfs.tests.cpp
@@ -666,11 +666,11 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
auto marker = kstd::vector{std::byte{'M'}, std::byte{'K'}, std::byte{'N'}, std::byte{'O'}, std::byte{'D'}};
auto written = (*via_persistent_fs)->get_inode()->write(marker, 0_B);
- REQUIRE(written == kstd::units::bytes{marker.size()});
+ REQUIRE(written == kstd::bytes{marker.size()});
auto read_back = kstd::vector<std::byte>(marker.size());
auto read = (*via_devfs)->get_inode()->read(read_back, 0_B);
- REQUIRE(read == kstd::units::bytes{marker.size()});
+ REQUIRE(read == kstd::bytes{marker.size()});
REQUIRE(read_back == marker);
}
diff --git a/kernel/kernel/memory.cpp b/kernel/kernel/memory.cpp
index 663137eb..b65a89db 100644
--- a/kernel/kernel/memory.cpp
+++ b/kernel/kernel/memory.cpp
@@ -21,7 +21,7 @@ namespace kernel::memory
{
null_allocator static instance;
- [[nodiscard]] auto allocate(kstd::units::bytes, kstd::units::bytes) noexcept -> void * override
+ [[nodiscard]] auto allocate(kstd::bytes, kstd::bytes) noexcept -> void * override
{
kstd::print(kstd::print_sink::stderr, "Tried to allocate memory without an active heap!");
return nullptr;
diff --git a/kernel/kernel/memory/block_list_allocator.cpp b/kernel/kernel/memory/block_list_allocator.cpp
index a682051f..993dd470 100644
--- a/kernel/kernel/memory/block_list_allocator.cpp
+++ b/kernel/kernel/memory/block_list_allocator.cpp
@@ -20,7 +20,7 @@ namespace kernel::memory
namespace
{
- [[nodiscard]] constexpr auto align_up(std::byte * pointer, kstd::units::bytes alignment) noexcept -> std::byte *
+ [[nodiscard]] constexpr auto align_up(std::byte * pointer, kstd::bytes alignment) noexcept -> std::byte *
{
auto const remainder = std::bit_cast<std::uintptr_t>(pointer) % static_cast<std::size_t>(alignment);
return remainder == 0 ? pointer : pointer + static_cast<std::size_t>(alignment) - remainder;
@@ -35,7 +35,7 @@ namespace kernel::memory
, m_lock{}
{}
- auto block_list_allocator::allocate(kstd::units::bytes size, kstd::units::bytes alignment) noexcept -> void *
+ auto block_list_allocator::allocate(kstd::bytes size, kstd::bytes alignment) noexcept -> void *
{
kstd::lock_guard guard{m_lock};
@@ -49,13 +49,13 @@ namespace kernel::memory
auto const raw_block = reinterpret_cast<std::byte *>(current);
auto const unaligned_payload = raw_block + allocated_metadata_size;
auto const aligned_payload = align_up(unaligned_payload, alignment);
- auto const required_padding = static_cast<kstd::units::bytes>(aligned_payload - unaligned_payload);
+ auto const required_padding = static_cast<kstd::bytes>(aligned_payload - unaligned_payload);
auto const total_required_size = required_padding + allocated_metadata_size + size;
if (current->usable_size >= total_required_size)
{
auto const payload_header = aligned_payload - sizeof(block_header *) - sizeof(block_header);
- auto const front_padding = static_cast<kstd::units::bytes>(payload_header - raw_block);
+ auto const front_padding = static_cast<kstd::bytes>(payload_header - raw_block);
auto payload_block = current;
@@ -75,7 +75,7 @@ namespace kernel::memory
}
auto const header_size =
- static_cast<kstd::units::bytes>(aligned_payload - reinterpret_cast<std::byte *>(payload_block));
+ static_cast<kstd::bytes>(aligned_payload - reinterpret_cast<std::byte *>(payload_block));
auto const payload_size = header_size - allocated_metadata_size + size;
split(payload_block, payload_size, 0_B);
@@ -117,7 +117,7 @@ namespace kernel::memory
coalesce(block);
}
- auto block_list_allocator::expand(kstd::units::bytes size) noexcept -> bool
+ auto block_list_allocator::expand(kstd::bytes size) noexcept -> bool
{
auto const total_required_size = size + allocated_metadata_size;
auto const frames_needed = (total_required_size + kapi::memory::frame::size - 1_B) / kapi::memory::frame::size;
@@ -190,8 +190,7 @@ namespace kernel::memory
}
}
- auto block_list_allocator::split(block_header * block, kstd::units::bytes size, kstd::units::bytes padding) noexcept
- -> void
+ auto block_list_allocator::split(block_header * block, kstd::bytes size, kstd::bytes padding) noexcept -> void
{
auto const new_block_size = size + padding;
diff --git a/kernel/kernel/memory/block_list_allocator.hpp b/kernel/kernel/memory/block_list_allocator.hpp
index ac6257c0..55d9e361 100644
--- a/kernel/kernel/memory/block_list_allocator.hpp
+++ b/kernel/kernel/memory/block_list_allocator.hpp
@@ -33,7 +33,7 @@ namespace kernel::memory
//! @param size The size of the block to allocate
//! @param alignment The desired alignment of the allocated block
//! @return A pointer to the beginning of the block on success, @p nullptr otherwise.
- [[nodiscard]] auto allocate(kstd::units::bytes size, kstd::units::bytes alignment) noexcept -> void * override;
+ [[nodiscard]] auto allocate(kstd::bytes size, kstd::bytes alignment) noexcept -> void * override;
//! Deallocate a block of memory previously allocated.
//!
@@ -43,7 +43,7 @@ namespace kernel::memory
private:
struct block_header final
{
- kstd::units::bytes usable_size{};
+ kstd::bytes usable_size{};
bool free{};
block_header * next{};
block_header * prev{};
@@ -53,16 +53,16 @@ namespace kernel::memory
//!
//! Each allocated block carries a block header, like any unallocated one, but in addition also has a back-pointer
//! to the block header to support padding due to alignment.
- constexpr auto static allocated_metadata_size = kstd::units::bytes{sizeof(block_header) + sizeof(block_header *)};
+ constexpr auto static allocated_metadata_size = kstd::bytes{sizeof(block_header) + sizeof(block_header *)};
//! The minimum number of bytes for an allocation.
- constexpr auto static minimum_allocation_size = kstd::units::bytes{16uz};
+ constexpr auto static minimum_allocation_size = kstd::bytes{16uz};
//! Try to expand the heap to accommodate the given size.
//!
//! @param delta The size to expand the heap by.
//! @return @p true if the heap was expanded, @p false otherwise.
- auto expand(kstd::units::bytes delta) noexcept -> bool;
+ auto expand(kstd::bytes delta) noexcept -> bool;
//! Split a given free block to accommodate and allocation.
//!
@@ -71,7 +71,7 @@ namespace kernel::memory
//! @param block The block to split.
//! @param size The size of the allocation.
//! @param padding The amount of padding to apply.
- auto split(block_header * block, kstd::units::bytes size, kstd::units::bytes padding) noexcept -> void;
+ auto split(block_header * block, kstd::bytes size, kstd::bytes padding) noexcept -> void;
//! Try to coalesce a given block with it's preceding and/or following block.
//!
diff --git a/kernel/kernel/memory/heap_allocator.hpp b/kernel/kernel/memory/heap_allocator.hpp
index 59fa98b0..3a5a023b 100644
--- a/kernel/kernel/memory/heap_allocator.hpp
+++ b/kernel/kernel/memory/heap_allocator.hpp
@@ -16,7 +16,7 @@ namespace kernel::memory
//! @param size The size of the block to allocate
//! @param alignment The desired alignment of the allocated block
//! @return A pointer to the beginning of the block on success, @p nullptr otherwise.
- [[nodiscard]] virtual auto allocate(kstd::units::bytes size, kstd::units::bytes alignment) noexcept -> void * = 0;
+ [[nodiscard]] virtual auto allocate(kstd::bytes size, kstd::bytes alignment) noexcept -> void * = 0;
//! Deallocate a block of memory previously allocated.
//!
diff --git a/kernel/kernel/memory/operators.cpp b/kernel/kernel/memory/operators.cpp
index 5de5101d..45ba5152 100644
--- a/kernel/kernel/memory/operators.cpp
+++ b/kernel/kernel/memory/operators.cpp
@@ -10,8 +10,8 @@
[[nodiscard]] auto operator new(std::size_t size, std::align_val_t alignment, std::nothrow_t const &) noexcept -> void *
{
auto & allocator = kernel::memory::get_heap_allocator();
- return allocator.allocate(static_cast<kstd::units::bytes>(size),
- static_cast<kstd::units::bytes>(static_cast<std::size_t>(alignment)));
+ return allocator.allocate(static_cast<kstd::bytes>(size),
+ static_cast<kstd::bytes>(static_cast<std::size_t>(alignment)));
}
[[nodiscard]] auto operator new(std::size_t size, std::align_val_t alignment) -> void *
diff --git a/kernel/kernel/test_support/devices/block_device.cpp b/kernel/kernel/test_support/devices/block_device.cpp
index 8ac1e23c..c9ab4a5e 100644
--- a/kernel/kernel/test_support/devices/block_device.cpp
+++ b/kernel/kernel/test_support/devices/block_device.cpp
@@ -18,14 +18,14 @@ using namespace kstd::units_literals;
namespace kernel::tests::devices
{
- block_device::block_device(kstd::string const & name, kstd::units::bytes block_size, kstd::units::bytes initial_size)
+ block_device::block_device(kstd::string const & name, kstd::bytes block_size, kstd::bytes initial_size)
: kapi::devices::device{name}
, m_block_size{block_size}
{
data.resize(initial_size.value, 0);
}
- auto block_device::read_block(size_t block_index, std::span<std::byte> buffer) -> kstd::result<kstd::units::bytes>
+ auto block_device::read_block(size_t block_index, std::span<std::byte> buffer) -> kstd::result<kstd::bytes>
{
auto const offset = block_index * block_size();
if (offset.value >= data.size())
@@ -34,7 +34,7 @@ namespace kernel::tests::devices
return 0_B;
}
- auto const bytes_to_read = std::min(block_size(), kstd::units::bytes{data.size()} - offset);
+ auto const bytes_to_read = std::min(block_size(), kstd::bytes{data.size()} - offset);
kstd::libc::memcpy(buffer.data(), data.data() + offset, bytes_to_read.value);
if (bytes_to_read < block_size())
{
@@ -44,8 +44,7 @@ namespace kernel::tests::devices
return bytes_to_read;
}
- auto block_device::write_block(size_t block_index, std::span<std::byte const> buffer)
- -> kstd::result<kstd::units::bytes>
+ auto block_device::write_block(size_t block_index, std::span<std::byte const> buffer) -> kstd::result<kstd::bytes>
{
auto const offset = block_index * block_size();
auto const write_end = offset + block_size();
@@ -58,14 +57,14 @@ namespace kernel::tests::devices
return block_size();
}
- auto block_device::block_size() const -> kstd::units::bytes
+ auto block_device::block_size() const -> kstd::bytes
{
return m_block_size;
}
- auto block_device::capacity() const -> kstd::units::bytes
+ auto block_device::capacity() const -> kstd::bytes
{
- return kstd::units::bytes{data.size()};
+ return kstd::bytes{data.size()};
}
auto block_device::query_facet(kapi::capabilities::facet_id facet) -> void *
diff --git a/kernel/kernel/test_support/devices/block_device.hpp b/kernel/kernel/test_support/devices/block_device.hpp
index 11065109..5f00f27e 100644
--- a/kernel/kernel/test_support/devices/block_device.hpp
+++ b/kernel/kernel/test_support/devices/block_device.hpp
@@ -18,21 +18,20 @@ namespace kernel::tests::devices
struct block_device final : kapi::devices::device, kapi::filesystem::block_special_file
{
- block_device(kstd::string const & name, kstd::units::bytes block_size, kstd::units::bytes initial_size = {});
+ block_device(kstd::string const & name, kstd::bytes block_size, kstd::bytes initial_size = {});
- auto read_block(size_t block_index, std::span<std::byte> buffer) -> kstd::result<kstd::units::bytes> override;
- auto write_block(size_t block_index, std::span<std::byte const> buffer)
- -> kstd::result<kstd::units::bytes> override;
+ auto read_block(size_t block_index, std::span<std::byte> buffer) -> kstd::result<kstd::bytes> override;
+ auto write_block(size_t block_index, std::span<std::byte const> buffer) -> kstd::result<kstd::bytes> override;
- [[nodiscard]] auto block_size() const -> kstd::units::bytes override;
- [[nodiscard]] auto capacity() const -> kstd::units::bytes override;
+ [[nodiscard]] auto block_size() const -> kstd::bytes override;
+ [[nodiscard]] auto capacity() const -> kstd::bytes override;
kstd::vector<uint8_t> data{};
private:
[[nodiscard]] auto query_facet(kapi::capabilities::facet_id facet) -> void * override;
- kstd::units::bytes m_block_size{};
+ kstd::bytes m_block_size{};
};
} // namespace kernel::tests::devices
diff --git a/kernel/kernel/test_support/filesystem/ext2.cpp b/kernel/kernel/test_support/filesystem/ext2.cpp
index 6ea41bab..96d94ea1 100644
--- a/kernel/kernel/test_support/filesystem/ext2.cpp
+++ b/kernel/kernel/test_support/filesystem/ext2.cpp
@@ -20,11 +20,11 @@ namespace kernel::tests::filesystem::ext2
constexpr uint32_t root_directory_data_block = 20;
} // namespace
- auto write_bytes(kernel::tests::devices::block_device & device, kstd::units::bytes offset, void const * source,
- kstd::units::bytes size) -> void
+ auto write_bytes(kernel::tests::devices::block_device & device, kstd::bytes offset, void const * source,
+ kstd::bytes size) -> void
{
auto const required_size = offset + size;
- if (kstd::units::bytes{device.data.size()} < required_size)
+ if (kstd::bytes{device.data.size()} < required_size)
{
device.data.resize(required_size.value, 0);
}
@@ -32,7 +32,7 @@ namespace kernel::tests::filesystem::ext2
std::memcpy(device.data.data() + offset, source, size.value);
}
- auto write_u32(kernel::tests::devices::block_device & device, kstd::units::bytes offset, uint32_t value) -> void
+ auto write_u32(kernel::tests::devices::block_device & device, kstd::bytes offset, uint32_t value) -> void
{
write_bytes(device, offset, &value, kstd::size_of(value));
}
@@ -73,7 +73,7 @@ namespace kernel::tests::filesystem::ext2
auto const root_inode_offset =
static_cast<size_t>(group_descriptor.inode_table) * kernel::filesystem::ext2::constants::base_block_size +
- (kernel::filesystem::ext2::constants::root_inode_number - 1) * kstd::units::bytes{superblock.inode_size};
+ (kernel::filesystem::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));
}
} // namespace kernel::tests::filesystem::ext2 \ No newline at end of file
diff --git a/kernel/kernel/test_support/filesystem/ext2.hpp b/kernel/kernel/test_support/filesystem/ext2.hpp
index a8f73ab5..a83bdd94 100644
--- a/kernel/kernel/test_support/filesystem/ext2.hpp
+++ b/kernel/kernel/test_support/filesystem/ext2.hpp
@@ -11,9 +11,9 @@
namespace kernel::tests::filesystem::ext2
{
- auto write_bytes(kernel::tests::devices::block_device & device, kstd::units::bytes offset, void const * source,
- kstd::units::bytes size) -> void;
- auto write_u32(kernel::tests::devices::block_device & device, kstd::units::bytes offset, uint32_t value) -> void;
+ 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 setup_mock_ext2_layout(kernel::tests::devices::block_device & device) -> void;
auto setup_mock_ext2_layout(kernel::tests::devices::block_device & device,
kernel::filesystem::ext2::superblock const & superblock) -> void;
diff --git a/kernel/kernel/test_support/filesystem/inode.cpp b/kernel/kernel/test_support/filesystem/inode.cpp
index 96a30c33..409efe77 100644
--- a/kernel/kernel/test_support/filesystem/inode.cpp
+++ b/kernel/kernel/test_support/filesystem/inode.cpp
@@ -10,14 +10,14 @@
namespace kernel::tests::filesystem
{
- auto inode::read(std::span<std::byte> buffer, kstd::units::bytes) const -> kstd::result<kstd::units::bytes>
+ auto inode::read(std::span<std::byte> buffer, kstd::bytes) const -> kstd::result<kstd::bytes>
{
- return kstd::units::bytes{buffer.size()};
+ return kstd::bytes{buffer.size()};
}
- auto inode::write(std::span<std::byte const> buffer, kstd::units::bytes) -> kstd::result<kstd::units::bytes>
+ auto inode::write(std::span<std::byte const> buffer, kstd::bytes) -> kstd::result<kstd::bytes>
{
- return kstd::units::bytes{buffer.size()};
+ return kstd::bytes{buffer.size()};
}
auto inode::is_regular() const -> bool
diff --git a/kernel/kernel/test_support/filesystem/inode.hpp b/kernel/kernel/test_support/filesystem/inode.hpp
index 383ca6f5..51773f15 100644
--- a/kernel/kernel/test_support/filesystem/inode.hpp
+++ b/kernel/kernel/test_support/filesystem/inode.hpp
@@ -13,10 +13,8 @@ namespace kernel::tests::filesystem
{
struct inode : kernel::filesystem::inode
{
- auto read(std::span<std::byte> buffer, kstd::units::bytes offset) const
- -> kstd::result<kstd::units::bytes> override;
- auto write(std::span<std::byte const> buffer, kstd::units::bytes offset)
- -> kstd::result<kstd::units::bytes> override;
+ auto read(std::span<std::byte> buffer, kstd::bytes offset) const -> kstd::result<kstd::bytes> override;
+ auto write(std::span<std::byte const> buffer, kstd::bytes offset) -> kstd::result<kstd::bytes> override;
[[nodiscard]] auto is_regular() const -> bool override;
};
diff --git a/kernel/kernel/test_support/kapi/memory.cpp b/kernel/kernel/test_support/kapi/memory.cpp
index 01fc078a..e554145d 100644
--- a/kernel/kernel/test_support/kapi/memory.cpp
+++ b/kernel/kernel/test_support/kapi/memory.cpp
@@ -12,8 +12,8 @@
namespace
{
//! The size of the simulated RAM.
- constexpr auto physical_size = kstd::units::MiB(32u);
- constexpr auto virtual_size = kstd::units::GiB(1u);
+ constexpr auto physical_size = kstd::MiB(32u);
+ constexpr auto virtual_size = kstd::GiB(1u);
constexpr auto number_of_frames = physical_size / kapi::memory::frame::size;
diff --git a/kernel/kernel/test_support/page_mapper.cpp b/kernel/kernel/test_support/page_mapper.cpp
index b1a6f92b..3a0072b4 100644
--- a/kernel/kernel/test_support/page_mapper.cpp
+++ b/kernel/kernel/test_support/page_mapper.cpp
@@ -11,7 +11,7 @@
namespace kernel::tests
{
- page_mapper::page_mapper(kstd::units::bytes physical_size, kstd::units::bytes virtual_size)
+ page_mapper::page_mapper(kstd::bytes physical_size, kstd::bytes virtual_size)
: memory{physical_size, virtual_size}
{}
diff --git a/kernel/kernel/test_support/page_mapper.hpp b/kernel/kernel/test_support/page_mapper.hpp
index a9985393..ee02217c 100644
--- a/kernel/kernel/test_support/page_mapper.hpp
+++ b/kernel/kernel/test_support/page_mapper.hpp
@@ -20,7 +20,7 @@ namespace kernel::tests
//!
//! @param physical_size The size of the physical memory.
//! @param virtual_size The size of the virtual address space.
- page_mapper(kstd::units::bytes physical_size, kstd::units::bytes virtual_size);
+ page_mapper(kstd::bytes physical_size, kstd::bytes virtual_size);
//! @copydoc kapi::memory::page_mapper::map
//!
diff --git a/kernel/kernel/test_support/simulated_memory.cpp b/kernel/kernel/test_support/simulated_memory.cpp
index 07adab17..7614816b 100644
--- a/kernel/kernel/test_support/simulated_memory.cpp
+++ b/kernel/kernel/test_support/simulated_memory.cpp
@@ -17,7 +17,7 @@
namespace kernel::tests
{
- simulated_memory::simulated_memory(kstd::units::bytes physical_size, kstd::units::bytes virtual_size)
+ simulated_memory::simulated_memory(kstd::bytes physical_size, kstd::bytes virtual_size)
: m_descriptor{memfd_create("teachos_simulated_memory", 0)}
, m_physical_size{physical_size}
, m_virtual_size{virtual_size}
@@ -76,7 +76,7 @@ namespace kernel::tests
return m_physical_base;
}
- auto simulated_memory::physical_size() const noexcept -> kstd::units::bytes
+ auto simulated_memory::physical_size() const noexcept -> kstd::bytes
{
return m_physical_size;
}
@@ -86,12 +86,12 @@ namespace kernel::tests
return kapi::memory::linear_address{m_virtual_base};
}
- auto simulated_memory::virtual_size() const noexcept -> kstd::units::bytes
+ auto simulated_memory::virtual_size() const noexcept -> kstd::bytes
{
return m_virtual_size;
}
- auto simulated_memory::map(kstd::units::bytes size, std::byte * to, off_t offset) -> std::byte *
+ auto simulated_memory::map(kstd::bytes size, std::byte * to, off_t offset) -> std::byte *
{
auto mapped_ptr = mmap(to, size.value, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, m_descriptor, offset);
if (mapped_ptr == MAP_FAILED)
diff --git a/kernel/kernel/test_support/simulated_memory.hpp b/kernel/kernel/test_support/simulated_memory.hpp
index e7ca9f6c..e1046ef4 100644
--- a/kernel/kernel/test_support/simulated_memory.hpp
+++ b/kernel/kernel/test_support/simulated_memory.hpp
@@ -23,7 +23,7 @@ namespace kernel::tests
//! Construct a new simulated memory device.
//! @param physical_size The size of the physical memory.
//! @param virtual_size The size of the virtual address space.
- simulated_memory(kstd::units::bytes physical_size, kstd::units::bytes virtual_size);
+ simulated_memory(kstd::bytes physical_size, kstd::bytes virtual_size);
//! Destroy this device
~simulated_memory();
@@ -38,13 +38,13 @@ namespace kernel::tests
[[nodiscard]] auto physical_base() const noexcept -> std::byte const *;
//! Get the size of the physical memory of this device.
- [[nodiscard]] auto physical_size() const noexcept -> kstd::units::bytes;
+ [[nodiscard]] auto physical_size() const noexcept -> kstd::bytes;
//! Get the base address of the virtual address space of this device.
[[nodiscard]] auto virtual_base() const noexcept -> kapi::memory::linear_address;
//! Get the size of the virtual address space of this device.
- [[nodiscard]] auto virtual_size() const noexcept -> kstd::units::bytes;
+ [[nodiscard]] auto virtual_size() const noexcept -> kstd::bytes;
//! Map a region of physical memory to a region of virtual memory.
//!
@@ -52,12 +52,12 @@ namespace kernel::tests
//! @param to The base address of the virtual region.
//! @param offset The offset into the physical memory to map.
//! @return A pointer to the first byte of the mapped region.
- [[nodiscard]] auto map(kstd::units::bytes size, std::byte * to, off_t offset) -> std::byte *;
+ [[nodiscard]] auto map(kstd::bytes size, std::byte * to, off_t offset) -> std::byte *;
private:
int m_descriptor{};
- kstd::units::bytes m_physical_size{0};
- kstd::units::bytes m_virtual_size{0};
+ kstd::bytes m_physical_size{0};
+ kstd::bytes m_virtual_size{0};
std::byte * m_physical_base{nullptr};
std::byte * m_virtual_base{nullptr};
};
diff --git a/libs/acpi/acpi/common/table_header.cpp b/libs/acpi/acpi/common/table_header.cpp
index ebceca1d..cf2e7c23 100644
--- a/libs/acpi/acpi/common/table_header.cpp
+++ b/libs/acpi/acpi/common/table_header.cpp
@@ -52,7 +52,7 @@ namespace acpi
return std::string_view{base + offset, size};
}
- auto table_header::length() const noexcept -> kstd::units::bytes
+ auto table_header::length() const noexcept -> kstd::bytes
{
using type = decltype(common_table_header_data::length);
@@ -64,7 +64,7 @@ namespace acpi
kstd::libc::memcpy(&raw_value, data.data(), size);
- return kstd::units::bytes{raw_value};
+ return kstd::bytes{raw_value};
}
auto table_header::oem_id() const noexcept -> std::string_view
diff --git a/libs/acpi/acpi/common/table_header.hpp b/libs/acpi/acpi/common/table_header.hpp
index 8e1d7c59..18e1dfdf 100644
--- a/libs/acpi/acpi/common/table_header.hpp
+++ b/libs/acpi/acpi/common/table_header.hpp
@@ -30,7 +30,7 @@ namespace acpi
[[nodiscard]] auto creator_id() const noexcept -> std::string_view;
//! Get the length of the entire table, including this header.
- [[nodiscard]] auto length() const noexcept -> kstd::units::bytes;
+ [[nodiscard]] auto length() const noexcept -> kstd::bytes;
//! Get the ID of the OEM.
[[nodiscard]] auto oem_id() const noexcept -> std::string_view;
diff --git a/libs/acpi/acpi/pointers.cpp b/libs/acpi/acpi/pointers.cpp
index 0393292c..85329bf2 100644
--- a/libs/acpi/acpi/pointers.cpp
+++ b/libs/acpi/acpi/pointers.cpp
@@ -38,9 +38,9 @@ namespace acpi
return signature() == "RSD PTR " && validate_checksum({reinterpret_cast<std::byte const *>(this), sizeof(rsdp)});
}
- auto xsdp::length() const noexcept -> kstd::units::bytes
+ auto xsdp::length() const noexcept -> kstd::bytes
{
- return kstd::units::bytes{m_length};
+ return kstd::bytes{m_length};
}
auto xsdp::table_address() const noexcept -> std::uintptr_t
diff --git a/libs/acpi/acpi/pointers.hpp b/libs/acpi/acpi/pointers.hpp
index 310447f5..761d8748 100644
--- a/libs/acpi/acpi/pointers.hpp
+++ b/libs/acpi/acpi/pointers.hpp
@@ -50,7 +50,7 @@ namespace acpi
struct [[gnu::packed]] xsdp : rsdp
{
//! Get the length of the data contained in this pointer.
- [[nodiscard]] auto length() const noexcept -> kstd::units::bytes;
+ [[nodiscard]] auto length() const noexcept -> kstd::bytes;
//! Get the physical address of the pointed-to Extended System Description Table.
[[nodiscard]] auto table_address() const noexcept -> std::uintptr_t;
diff --git a/libs/kstd/kstd/units.hpp b/libs/kstd/kstd/units.hpp
index cb33af21..e3868aa7 100644
--- a/libs/kstd/kstd/units.hpp
+++ b/libs/kstd/kstd/units.hpp
@@ -9,71 +9,76 @@
namespace kstd
{
- namespace units
- {
-
- using bytes = basic_unit<std::size_t, struct bytes_tag>;
-
- // NOLINTNEXTLINE(readability-identifier-naming)
- constexpr auto KiB(std::unsigned_integral auto value) noexcept -> bytes
- {
- return bytes{static_cast<bytes::value_type>(value) * 1024};
- }
+ using bytes = basic_unit<std::size_t, struct bytes_tag>;
- // NOLINTNEXTLINE(readability-identifier-naming)
- constexpr auto MiB(std::unsigned_integral auto value) noexcept -> bytes
- {
- return bytes{static_cast<bytes::value_type>(value) * 1024 * 1024};
- }
-
- // NOLINTNEXTLINE(readability-identifier-naming)
- constexpr auto GiB(std::unsigned_integral auto value) noexcept -> bytes
- {
- return bytes{static_cast<bytes::value_type>(value) * 1024 * 1024 * 1024};
- }
-
- template<typename ValueType>
- constexpr auto operator+(ValueType * pointer, bytes offset) -> ValueType *
- {
- return pointer + offset.value;
- }
-
- } // namespace units
+ // NOLINTNEXTLINE(readability-identifier-naming)
+ constexpr auto KiB(std::unsigned_integral auto value) noexcept -> bytes
+ {
+ return bytes{static_cast<bytes::value_type>(value) * 1024};
+ }
- namespace units_literals
+ // NOLINTNEXTLINE(readability-identifier-naming)
+ constexpr auto MiB(std::unsigned_integral auto value) noexcept -> bytes
{
- constexpr auto operator""_B(unsigned long long value) noexcept -> units::bytes
- {
- return units::bytes{value};
- }
+ return bytes{static_cast<bytes::value_type>(value) * 1024 * 1024};
+ }
- constexpr auto operator""_KiB(unsigned long long value) noexcept -> units::bytes
- {
- return units::KiB(value);
- }
+ // NOLINTNEXTLINE(readability-identifier-naming)
+ constexpr auto GiB(std::unsigned_integral auto value) noexcept -> bytes
+ {
+ return bytes{static_cast<bytes::value_type>(value) * 1024 * 1024 * 1024};
+ }
- constexpr auto operator""_MiB(unsigned long long value) noexcept -> units::bytes
- {
- return units::MiB(value);
- }
+ template<typename ValueType>
+ constexpr auto operator+(ValueType * pointer, bytes offset) -> ValueType *
+ {
+ return pointer + offset.value;
+ }
- constexpr auto operator""_GiB(unsigned long long value) noexcept -> units::bytes
+ inline namespace literals
+ {
+ inline namespace units_literals
{
- return units::GiB(value);
- }
-
- } // namespace units_literals
-
- template<typename ValueType>
- consteval auto size_of(ValueType const &) noexcept -> units::bytes
+ constexpr auto operator""_B(unsigned long long value) noexcept -> bytes
+ {
+ return bytes{value};
+ }
+
+ constexpr auto operator""_KiB(unsigned long long value) noexcept -> bytes
+ {
+ return KiB(value);
+ }
+
+ constexpr auto operator""_MiB(unsigned long long value) noexcept -> bytes
+ {
+ return MiB(value);
+ }
+
+ constexpr auto operator""_GiB(unsigned long long value) noexcept -> bytes
+ {
+ return GiB(value);
+ }
+
+ } // namespace units_literals
+ } // namespace literals
+
+ //! Calculate the size of a given object.
+ //!
+ //! @param object The object to calculate the size for.
+ //! @return the size, in bytes, of the given object.
+ consteval auto size_of(auto const & object) noexcept -> bytes
{
- return units::bytes{sizeof(ValueType)};
+ return bytes{sizeof(object)};
}
- template<typename ValueType>
- consteval auto size_of() noexcept -> units::bytes
+ //! Calculate the size of a given type.
+ //!
+ //! @tparam Type The type to calculate the size for.
+ //! @return the size, in bytes, of the given type.
+ template<typename Type>
+ consteval auto size_of() noexcept -> bytes
{
- return units::bytes{sizeof(ValueType)};
+ return bytes{sizeof(Type)};
}
} // namespace kstd
diff --git a/libs/multiboot2/multiboot2/information.hpp b/libs/multiboot2/multiboot2/information.hpp
index f12969e8..709d64a8 100644
--- a/libs/multiboot2/multiboot2/information.hpp
+++ b/libs/multiboot2/multiboot2/information.hpp
@@ -124,9 +124,9 @@ namespace multiboot2
return {data(), vla_tag::size()};
}
- [[nodiscard]] constexpr auto size() const noexcept -> kstd::units::bytes
+ [[nodiscard]] constexpr auto size() const noexcept -> kstd::bytes
{
- return kstd::units::bytes{end_address - start_address};
+ return kstd::bytes{end_address - start_address};
}
};
@@ -157,9 +157,9 @@ namespace multiboot2
using pointer = iterator::pointer;
using reference = iterator::reference;
- [[nodiscard]] auto size() const noexcept -> kstd::units::bytes
+ [[nodiscard]] auto size() const noexcept -> kstd::bytes
{
- return kstd::units::bytes{m_size};
+ return kstd::bytes{m_size};
}
// Range access
diff --git a/libs/multiboot2/multiboot2/information/data.hpp b/libs/multiboot2/multiboot2/information/data.hpp
index 734bbc6f..59d82b9e 100644
--- a/libs/multiboot2/multiboot2/information/data.hpp
+++ b/libs/multiboot2/multiboot2/information/data.hpp
@@ -29,14 +29,14 @@ namespace multiboot2
//! loader.
struct basic_memory : tag_data<information_id::basic_memory_information>
{
- [[nodiscard]] constexpr auto lower() const noexcept -> kstd::units::bytes
+ [[nodiscard]] constexpr auto lower() const noexcept -> kstd::bytes
{
- return kstd::units::bytes{lower_KiB * 1024};
+ return kstd::bytes{lower_KiB * 1024};
}
- [[nodiscard]] constexpr auto upper() const noexcept -> kstd::units::bytes
+ [[nodiscard]] constexpr auto upper() const noexcept -> kstd::bytes
{
- return kstd::units::bytes{upper_KiB * 1024};
+ return kstd::bytes{upper_KiB * 1024};
}
//! The amount of lower memory available to the system.
@@ -84,9 +84,9 @@ namespace multiboot2
//! time. The array begins after the last member of this structure.
struct elf_symbols : tag_data<information_id::elf_sections>
{
- [[nodiscard]] constexpr auto entry_size() const noexcept -> kstd::units::bytes
+ [[nodiscard]] constexpr auto entry_size() const noexcept -> kstd::bytes
{
- return kstd::units::bytes{entry_size_in_B};
+ return kstd::bytes{entry_size_in_B};
}
//! The number of section header table entries.
@@ -119,9 +119,9 @@ namespace multiboot2
return type == memory_type::available;
}
- [[nodiscard]] constexpr auto size() const noexcept -> kstd::units::bytes
+ [[nodiscard]] constexpr auto size() const noexcept -> kstd::bytes
{
- return kstd::units::bytes{size_in_B};
+ return kstd::bytes{size_in_B};
}
//! The physical start address of this region
@@ -139,9 +139,9 @@ namespace multiboot2
std::uint32_t : 0;
};
- [[nodiscard]] constexpr auto entry_size() const noexcept -> kstd::units::bytes
+ [[nodiscard]] constexpr auto entry_size() const noexcept -> kstd::bytes
{
- return kstd::units::bytes{entry_size_in_B};
+ return kstd::bytes{entry_size_in_B};
}
//! The size of each entry present in the map.