MBRBlockDevice
MBRBlockDevice 类层次结构
MBRBlockDevice 类提供了一种管理存储设备上的主引导记录(MBR)的方法,允许您对设备进行分区。如果没有 MBR,您仍然可以使用文件系统格式化存储设备,但包括 MBR 将允许将来的分区修改。
MBRBlockDevices 在构造函数中具有以下可配置参数:
- bd - 块设备返回 MBRBlockDevice
- part - 分区使用,1 - 4
您可以在类引用中查看有关可配置设置和函数的更多信息。
MBRBlockDevice 类参考
公共成员函数 | |
MBRBlockDevice (BlockDevice *bd, int part) | |
virtual | ~MBRBlockDevice () |
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 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 |
virtual bd_addr_t | get_partition_start () const |
virtual bd_addr_t | get_partition_stop () const |
virtual uint8_t | get_partition_type () const |
virtual int | get_partition_number () const |
公共成员函数继承自 BlockDevice | |
virtual | ~BlockDevice () |
virtual int | trim (bd_addr_t addr, bd_size_t size) |
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 |
静态公共成员函数 | |
static int | partition (BlockDevice *bd, int part, uint8_t type, bd_addr_t start) |
static int | partition (BlockDevice *bd, int part, uint8_t type, bd_addr_t start, bd_addr_t stop) |
受保护的属性 | |
BlockDevice * | _bd |
bd_size_t | _offset |
bd_size_t | _size |
uint8_t | _type |
uint8_t | _part |
uint32_t | _init_ref_count |
MBRBlockDevice 示例
将堆支持的块设备分区为两个分区。此示例还使用 HeapBlockDevice。
#include "mbed.h"
#include "HeapBlockDevice.h"
#include "MBRBlockDevice.h"
int main(void) {
// Create a block device with 64 blocks of size 512
HeapBlockDevice mem(64*512, 512);
// Partition into two partitions with ~half the blocks
MBRBlockDevice::partition(&mem, 1, 0x83, 0*512, 32*512);
MBRBlockDevice::partition(&mem, 2, 0x83, 32*512);
// Create a block device that maps to the first 32 blocks (excluding MBR block)
MBRBlockDevice part1(&mem, 1);
// Create a block device that maps to the last 32 blocks
MBRBlockDevice part2(&mem, 2);
}
对 SD 卡进行分区,并使用 FAT 文件系统格式化新分区。PC 现在可以识别 SD 卡。
#include "mbed.h"
#include "SDBlockDevice.h"
#include "MBRBlockDevice.h"
#include "FATFileSystem.h"
// Pin mappings for K64F
PinName s0 = PTE3; // MOSI
PinName s1 = PTE1; // MISO
PinName s2 = PTE2; // SCLK
PinName s3 = PTE4; // CS
int main(void) {
// Create an SD card
SDBlockDevice sd(s0, s1, s2, s3);
// Create a partition with 1 GB of space
MBRBlockDevice::partition(&sd, 1, 0x83, 0, 1024*1024);
// Create the block device that represents the partition
MBRBlockDevice part1(&sd, 1);
// Format the partition with a FAT filesystem
FATFileSystem::format(&part1);
// Create the FAT filesystem instance, files can now be written to
// the FAT filesystem in partition 1
FATFileSystem fat("fat", &part1);
}
相关内容
- HeapBlockDevice API 参考。