BufferedBlockDevice
BufferedBlockDevice 类层次结构
BufferedBlockDevice 类是块设备 adpator,其目的是将底层块设备的读取和程序大小减少到 1。大的读取和/或程序大小可能使块设备用户的生活变得困难,因此 BufferedBlockDevice 将两个大小减小到最小值,对底层 BD 的读写操作使用内部缓冲区。调用同步 API 可确保将写入刷新到底层 BD。
构造函数只需要底层块设备指针。
- bd - 块设备支持 BufferedBlockDevice。
BufferedBlockDevice 类参考
公共成员函数 | |
BufferedBlockDevice (BlockDevice *bd) | |
virtual | ~BufferedBlockDevice () |
virtual int | init () |
virtual int | deinit () |
virtual int | sync () |
virtual int | read (void *buffer, bd_addr_t addr, bd_size_t size) |
virtual int | program (const void *buffer, bd_addr_t addr, bd_size_t size) |
virtual int | erase (bd_addr_t addr, bd_size_t size) |
virtual int | trim (bd_addr_t addr, bd_size_t size) |
virtual bd_size_t | get_read_size () const |
virtual bd_size_t | get_program_size () const |
virtual bd_size_t | get_erase_size () const |
virtual bd_size_t | get_erase_size (bd_addr_t addr) const |
virtual int | get_erase_value () const |
virtual bd_size_t | size () const |
公共成员函数继承自 BlockDevice | |
virtual | ~BlockDevice () |
bool | is_valid_read (bd_addr_t addr, bd_size_t size) const |
bool | is_valid_program (bd_addr_t addr, bd_size_t size) const |
bool | is_valid_erase (bd_addr_t addr, bd_size_t size) const |
受保护的成员函数 | |
int | flush () |
受保护的属性 | |
BlockDevice * | _bd |
bd_size_t | _bd_program_size |
bd_size_t | _curr_aligned_addr |
bool | _flushed |
uint8_t * | _cache |
uint32_t | _init_ref_count |
BufferedBlockDevice 示例
这个 BufferedBlockDevice 示例采用 HeapBlockDevice,其读取大小为 256 字节,程序大小为 512 字节,并显示了如何使用 BufferedBlockDevice 读取或编程具有更小读取/程序大小的块设备。
HeapBlockDevice heap_bd(1024, 256, 512, 512);
BufferedBlockDevice buf_bd(&heap_bd);
// This initializes the buffered block device (as well as the underlying heap block device)
int err = buf_bd.init();
uint8_t buf[8];
for (int i = 0; i < sizeof(buf); i++) {
buf[i] = i;
}
// Now we can program an 8 byte buffer (couldn't do that in underlying BD, having 512-byte program size)
err = buf_bd.program(buf, 0, sizeof(buf));
// Now we can also read one byte
err = buf_bd.read(buf, 0, 1);
// Ensure programmed data is flushed to the underlying block device
err = buf_bd.sync();
相关内容
- HeapBlockDevice API 参考。