aboutsummaryrefslogtreecommitdiff
path: root/kernel/devices/src/storage/RAMDisk/RAMDiskDevice.cpp
blob: 339e7faed73e2543736b936ad2b9247dd0f3aeab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "devices/storage/RAMDisk/RAMDiskDevice.hpp"

#include "kapi/boot_module/boot_module.hpp"
#include "kapi/system.hpp"

#include <kstd/cstring>

#include <cstddef>

namespace devices::storage::ram_disk
{
  ram_disk_device::ram_disk_device(kapi::boot_modules::boot_module const & module)
      : 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.");
    }

    // TODO BA-FS26 add bounds checking based on module size?
    // TODO BA-FS26 fill with 0 after the end of the module, if the block extends beyond it?

    auto const offset = block_index * block_size;
    auto const source = static_cast<std::byte *>(m_boot_module.start_address) + offset;

    kstd::libc::memcpy(buffer, source, block_size);
  }
}  // namespace devices::storage::ram_disk