1 | // SPDX-License-Identifier: GPL-3.0-or-later |
2 | |
3 | #pragma once |
4 | |
5 | #include <cstddef> |
6 | #include <cstdint> |
7 | #include <mos/types.h> |
8 | |
9 | #define BLOCKDEV_BLOCK_SIZE 512 |
10 | |
11 | class RAMDisk |
12 | { |
13 | public: |
14 | RAMDisk(const size_t nbytes); |
15 | ~RAMDisk(); |
16 | |
17 | size_t read_block(const size_t block, const size_t nblocks, uint8_t *buf); |
18 | size_t write_block(const size_t block, const size_t nblocks, const uint8_t *buf); |
19 | |
20 | u32 nblocks() const |
21 | { |
22 | return m_nblocks; |
23 | } |
24 | |
25 | u32 block_size() const |
26 | { |
27 | return BLOCKDEV_BLOCK_SIZE; |
28 | } |
29 | |
30 | private: |
31 | const size_t m_nbytes; |
32 | const size_t m_nblocks; |
33 | uint8_t *m_data; |
34 | }; |
35 | |