mirror of https://github.com/ARMmbed/mbed-os.git
commit
6c74dce434
|
@ -163,6 +163,46 @@ void test_read_write() {
|
|||
TEST_ASSERT_EQUAL(0, err);
|
||||
}
|
||||
|
||||
void test_single_mbr() {
|
||||
int err = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
const bd_addr_t MBR_OFFSET = 0;
|
||||
const bd_addr_t FAT1_OFFSET = 1;
|
||||
const bd_addr_t FAT2_OFFSET = BLOCK_COUNT/2;
|
||||
|
||||
uint8_t *buffer = (uint8_t *)malloc(BLOCK_SIZE);
|
||||
TEST_ASSERT(buffer);
|
||||
|
||||
// Check that all three header blocks have the 0x55aa signature
|
||||
err = bd.read(buffer, MBR_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE-2], "\x55\xaa", 2) == 0);
|
||||
|
||||
err = bd.read(buffer, FAT1_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE-2], "\x55\xaa", 2) == 0);
|
||||
|
||||
err = bd.read(buffer, FAT2_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE-2], "\x55\xaa", 2) == 0);
|
||||
|
||||
// Check that the headers for both filesystems contain a jump code
|
||||
// indicating they are actual FAT superblocks and not an extra MBR
|
||||
err = bd.read(buffer, FAT1_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
TEST_ASSERT(buffer[0] == 0xe9 || buffer[0] == 0xeb || buffer[0] == 0xe8);
|
||||
|
||||
err = bd.read(buffer, FAT2_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
TEST_ASSERT(buffer[0] == 0xe9 || buffer[0] == 0xeb || buffer[0] == 0xe8);
|
||||
|
||||
free(buffer);
|
||||
|
||||
bd.deinit();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
}
|
||||
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
|
@ -174,6 +214,7 @@ Case cases[] = {
|
|||
Case("Testing formating", test_format),
|
||||
Case("Testing read write < block", test_read_write<BLOCK_SIZE/2>),
|
||||
Case("Testing read write > block", test_read_write<2*BLOCK_SIZE>),
|
||||
Case("Testing for no extra MBRs", test_single_mbr),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
|
|
@ -211,7 +211,11 @@ int MBRBlockDevice::init()
|
|||
}
|
||||
|
||||
// Check for valid entry
|
||||
if (table->entries[_part-1].type == 0x00) {
|
||||
// 0x00 = no entry
|
||||
// 0x05, 0x0f = extended partitions, currently not supported
|
||||
if ((table->entries[_part-1].type == 0x00 ||
|
||||
table->entries[_part-1].type == 0x05 ||
|
||||
table->entries[_part-1].type == 0x0f)) {
|
||||
delete[] buffer;
|
||||
return BD_ERROR_INVALID_PARTITION;
|
||||
}
|
||||
|
|
|
@ -340,7 +340,7 @@ int FATFileSystem::format(BlockDevice *bd, bd_size_t cluster_size)
|
|||
|
||||
// Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
|
||||
fs.lock();
|
||||
FRESULT res = f_mkfs(fs._fsid, FM_ANY, cluster_size, NULL, 0);
|
||||
FRESULT res = f_mkfs(fs._fsid, FM_ANY | FM_SFD, cluster_size, NULL, 0);
|
||||
fs.unlock();
|
||||
if (res != FR_OK) {
|
||||
return fat_error_remap(res);
|
||||
|
|
Loading…
Reference in New Issue