aboutsummaryrefslogtreecommitdiff
path: root/kernel/devices/src/storage
diff options
context:
space:
mode:
authorLukas Oesch <lukasoesch20@gmail.com>2026-03-03 14:11:49 +0100
committerLukas Oesch <lukasoesch20@gmail.com>2026-03-17 16:42:42 +0100
commit2ae7a868b867289b9591d662972f559d412315c3 (patch)
tree3e9cb5401a40e942fe0cc435c01e476701f70287 /kernel/devices/src/storage
parentfe0aadec94834b72f4511ce5e300b9fb22e66e60 (diff)
downloadteachos-2ae7a868b867289b9591d662972f559d412315c3.tar.xz
teachos-2ae7a868b867289b9591d662972f559d412315c3.zip
refactoring read and write block calculations
Diffstat (limited to 'kernel/devices/src/storage')
-rw-r--r--kernel/devices/src/storage/RAMDisk/RAMDiskDevice.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/kernel/devices/src/storage/RAMDisk/RAMDiskDevice.cpp b/kernel/devices/src/storage/RAMDisk/RAMDiskDevice.cpp
index 627641c..f3b8799 100644
--- a/kernel/devices/src/storage/RAMDisk/RAMDiskDevice.cpp
+++ b/kernel/devices/src/storage/RAMDisk/RAMDiskDevice.cpp
@@ -11,12 +11,17 @@
namespace devices::storage::ram_disk
{
+ namespace
+ {
+ constexpr size_t RAM_DISK_BLOCK_SIZE = 512uz; // TODO BA-FS26 really correct / good??
+ } // namespace
+
ram_disk_device::ram_disk_device() // TODO BA-FS26 remove when kstd::vector is available
- : block_device(0, 0)
+ : block_device(0, 0, RAM_DISK_BLOCK_SIZE)
{}
ram_disk_device::ram_disk_device(kapi::boot_modules::boot_module const & module, size_t major, size_t minor)
- : block_device(major, minor)
+ : block_device(major, minor, RAM_DISK_BLOCK_SIZE)
, m_boot_module(module)
{}
@@ -27,21 +32,17 @@ namespace devices::storage::ram_disk
kapi::system::panic("[RAM DISK DEVICE] read_block called with null buffer.");
}
- size_t const offset = block_index * block_size;
- size_t const limit = m_boot_module.size;
+ auto const info = calculate_transfer(block_index);
- size_t const available = (offset < limit) ? (limit - offset) : 0;
- size_t const to_copy = (available < block_size) ? available : block_size;
-
- if (to_copy > 0)
+ if (info.to_transfer > 0)
{
- auto const source = static_cast<std::byte const *>(m_boot_module.start_address) + offset;
- kstd::libc::memcpy(buffer, source, to_copy);
+ auto const src = static_cast<std::byte const *>(m_boot_module.start_address) + info.offset;
+ kstd::libc::memcpy(buffer, src, info.to_transfer);
}
- if (to_copy < block_size)
+ if (info.remainder > 0)
{
- kstd::libc::memset(static_cast<std::byte *>(buffer) + to_copy, std::byte{0}, block_size - to_copy);
+ kstd::libc::memset(static_cast<std::byte *>(buffer) + info.to_transfer, 0, info.remainder);
}
}
@@ -52,16 +53,17 @@ namespace devices::storage::ram_disk
kapi::system::panic("[RAM DISK DEVICE] write_block called with null buffer.");
}
- size_t const offset = block_index * block_size;
- size_t const limit = m_boot_module.size;
-
- if (offset >= limit)
- return;
+ auto const info = calculate_transfer(block_index);
- size_t const available = limit - offset;
- size_t const to_write = (available < block_size) ? available : block_size;
+ if (info.to_transfer > 0)
+ {
+ auto const dest = static_cast<std::byte *>(m_boot_module.start_address) + info.offset;
+ kstd::libc::memcpy(dest, buffer, info.to_transfer);
+ }
+ }
- auto const destination = static_cast<std::byte *>(m_boot_module.start_address) + offset;
- kstd::libc::memcpy(destination, buffer, to_write);
+ auto ram_disk_device::size() const -> size_t
+ {
+ return m_boot_module.size;
}
} // namespace devices::storage::ram_disk \ No newline at end of file