#include "devices/storage/RAMDisk/RAMDiskDevice.hpp" #include "kapi/boot_module/boot_module.hpp" #include "kapi/system.hpp" #include "devices/BlockDevice.hpp" #include #include 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, 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, RAM_DISK_BLOCK_SIZE) , m_boot_module(module) {} auto ram_disk_device::read_block(size_t block_index, void * buffer) const -> void { if (buffer == nullptr) { kapi::system::panic("[RAM DISK DEVICE] read_block called with null buffer."); } auto const info = calculate_transfer(block_index); if (info.to_transfer > 0) { auto const src = static_cast(m_boot_module.start_address) + info.offset; kstd::libc::memcpy(buffer, src, info.to_transfer); } if (info.remainder > 0) { kstd::libc::memset(static_cast(buffer) + info.to_transfer, 0, info.remainder); } } auto ram_disk_device::write_block(size_t block_index, void const * buffer) -> void { if (buffer == nullptr) { kapi::system::panic("[RAM DISK DEVICE] write_block called with null buffer."); } auto const info = calculate_transfer(block_index); if (info.to_transfer > 0) { auto const dest = static_cast(m_boot_module.start_address) + info.offset; kstd::libc::memcpy(dest, buffer, info.to_transfer); } } auto ram_disk_device::size() const -> size_t { return m_boot_module.size; } } // namespace devices::storage::ram_disk