storage: fix astyle coding style

pull/8591/head
Martin Kojtal 2018-10-30 14:57:42 +00:00
parent 5c79ba5189
commit e54ce88bca
30 changed files with 241 additions and 224 deletions

View File

@ -38,7 +38,7 @@ void functionality_test()
uint8_t *dummy = new (std::nothrow) uint8_t[num_blocks * erase_size];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;
HeapBlockDevice heap_bd(num_blocks * erase_size, read_size, prog_size, erase_size);
FlashSimBlockDevice bd(&heap_bd, blank);

View File

@ -82,11 +82,11 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
int val_rand;
for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) {
val_rand = rand();
if ( (0xff & val_rand) != read_block[i_ind] ) {
if ((0xff & val_rand) != read_block[i_ind]) {
utest_printf("\n Assert Failed Buf Read - block:size: %llx:%llu \n", block, block_size);
utest_printf("\n pos: %llu, exp: %02x, act: %02x, wrt: %02x \n", i_ind, (0xff & val_rand),
utest_printf("\n pos: %llu, exp: %02x, act: %02x, wrt: %02x \n", i_ind, (0xff & val_rand),
read_block[i_ind],
write_block[i_ind] );
write_block[i_ind]);
}
TEST_ASSERT_EQUAL(0xff & val_rand, read_block[i_ind]);
}
@ -153,7 +153,7 @@ static void test_thread_job(void *block_device_ptr)
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
uint8_t *read_block = new (std::nothrow) uint8_t[block_size];
if (!write_block || !read_block ) {
if (!write_block || !read_block) {
utest_printf("\n Not enough memory for test");
goto end;
}

View File

@ -25,7 +25,7 @@ using namespace utest::v1;
// TODO HACK, replace with available ram/heap property
#if defined(TARGET_MTB_MTS_XDOT)
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#endif
#define TEST_BLOCK_SIZE 128
@ -45,7 +45,8 @@ const struct {
// Simple test that read/writes random set of blocks
void test_read_write() {
void test_read_write()
{
uint8_t *dummy = new (std::nothrow) uint8_t[TEST_BLOCK_DEVICE_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;
@ -55,19 +56,19 @@ void test_read_write() {
int err = bd.init();
TEST_ASSERT_EQUAL(0, err);
for (unsigned a = 0; a < sizeof(ATTRS)/sizeof(ATTRS[0]); a++) {
for (unsigned a = 0; a < sizeof(ATTRS) / sizeof(ATTRS[0]); a++) {
static const char *prefixes[] = {"", "k", "M", "G"};
for (int i = 3; i >= 0; i--) {
bd_size_t size = (bd.*ATTRS[a].method)();
if (size >= (1ULL << 10*i)) {
if (size >= (1ULL << 10 * i)) {
printf("%s: %llu%sbytes (%llubytes)\n",
ATTRS[a].name, size >> 10*i, prefixes[i], size);
ATTRS[a].name, size >> 10 * i, prefixes[i], size);
break;
}
}
}
unsigned addrwidth = ceil(log(float(bd.size()-1)) / log(float(16)))+1;
unsigned addrwidth = ceil(log(float(bd.size() - 1)) / log(float(16))) + 1;
bd_size_t block_size = bd.get_erase_size();
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
@ -81,7 +82,7 @@ void test_read_write() {
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
// Find a random block
bd_addr_t block = (rand()*block_size) % bd.size();
bd_addr_t block = (rand() * block_size) % bd.size();
// Use next random number as temporary seed to keep
// the address progressing in the pseudorandom sequence
@ -119,13 +120,13 @@ void test_read_write() {
// Find error mask for debugging
memset(error_mask, 0, TEST_ERROR_MASK);
bd_size_t error_scale = block_size / (TEST_ERROR_MASK*8);
bd_size_t error_scale = block_size / (TEST_ERROR_MASK * 8);
srand(seed);
for (bd_size_t i = 0; i < TEST_ERROR_MASK*8; i++) {
for (bd_size_t i = 0; i < TEST_ERROR_MASK * 8; i++) {
for (bd_size_t j = 0; j < error_scale; j++) {
if ((0xff & rand()) != read_block[i*error_scale + j]) {
error_mask[i/8] |= 1 << (i%8);
if ((0xff & rand()) != read_block[i * error_scale + j]) {
error_mask[i / 8] |= 1 << (i % 8);
}
}
}
@ -142,7 +143,7 @@ void test_read_write() {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}
}
err = bd.deinit();
TEST_ASSERT_EQUAL(0, err);
@ -155,7 +156,8 @@ end:
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(30, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
@ -166,6 +168,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -26,13 +26,13 @@ using namespace utest::v1;
// TODO HACK, replace with available ram/heap property
#if defined(TARGET_MTB_MTS_XDOT)
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#endif
#define BLOCK_COUNT 16
#define BLOCK_SIZE 512
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd(BLOCK_COUNT *BLOCK_SIZE, BLOCK_SIZE);
// Testing formatting of master boot record
void test_mbr_format()
@ -42,10 +42,10 @@ void test_mbr_format()
delete[] dummy;
// Create two partitions splitting device in ~half
int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT/2)*BLOCK_SIZE);
int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT / 2) * BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
err = MBRBlockDevice::partition(&bd, 2, 0x83, -(BLOCK_COUNT/2)*BLOCK_SIZE);
err = MBRBlockDevice::partition(&bd, 2, 0x83, -(BLOCK_COUNT / 2) * BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Load both partitions, as well as a third to check for invalid partitions
@ -95,13 +95,13 @@ void test_mbr_attr()
printf("partition 1 erase size: %llu bytes\n", part1.get_erase_size());
printf("partition 1 size: %llu bytes\n", part1.size());
TEST_ASSERT_EQUAL(1, part1.get_partition_number());
TEST_ASSERT_EQUAL(1*BLOCK_SIZE, part1.get_partition_start());
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, part1.get_partition_stop());
TEST_ASSERT_EQUAL(1 * BLOCK_SIZE, part1.get_partition_start());
TEST_ASSERT_EQUAL((BLOCK_COUNT / 2)*BLOCK_SIZE, part1.get_partition_stop());
TEST_ASSERT_EQUAL(0x83, part1.get_partition_type());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part1.get_read_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part1.get_program_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part1.get_erase_size());
TEST_ASSERT_EQUAL(((BLOCK_COUNT/2)-1)*BLOCK_SIZE, part1.size());
TEST_ASSERT_EQUAL(((BLOCK_COUNT / 2) - 1)*BLOCK_SIZE, part1.size());
printf("partition 2 partition number: %d\n", part2.get_partition_number());
printf("partition 2 partition start: 0x%llx\n", part2.get_partition_start());
@ -112,13 +112,13 @@ void test_mbr_attr()
printf("partition 2 erase size: %llu bytes\n", part2.get_erase_size());
printf("partition 2 size: %llu bytes\n", part2.size());
TEST_ASSERT_EQUAL(2, part2.get_partition_number());
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, part2.get_partition_start());
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, part2.get_partition_stop());
TEST_ASSERT_EQUAL((BLOCK_COUNT / 2)*BLOCK_SIZE, part2.get_partition_start());
TEST_ASSERT_EQUAL(BLOCK_COUNT * BLOCK_SIZE, part2.get_partition_stop());
TEST_ASSERT_EQUAL(0x83, part2.get_partition_type());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part2.get_read_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part2.get_program_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part2.get_erase_size());
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, part2.size());
TEST_ASSERT_EQUAL((BLOCK_COUNT / 2)*BLOCK_SIZE, part2.size());
// Deinit partitions
err = part1.deinit();
@ -177,7 +177,7 @@ void test_mbr_read_write()
}
// Check with original block device
err = bd.read(read_block, 1*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(read_block, 1 * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Check that the data was unmodified
@ -209,7 +209,7 @@ void test_mbr_read_write()
}
// Check with original block device
err = bd.read(read_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(read_block, (BLOCK_COUNT / 2) * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Check that the data was unmodified
@ -232,7 +232,8 @@ end:
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
@ -245,6 +246,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -28,7 +28,7 @@ using namespace utest::v1;
// TODO HACK, replace with available ram/heap property
#if defined(TARGET_MTB_MTS_XDOT)
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#endif
#define BLOCK_COUNT 16
@ -36,17 +36,18 @@ using namespace utest::v1;
// Simple test which read/writes blocks on a sliced block device
void test_slicing() {
void test_slicing()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;
int err;
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd(BLOCK_COUNT * BLOCK_SIZE, BLOCK_SIZE);
SlicingBlockDevice slice1(&bd, 0, (BLOCK_COUNT/2)*BLOCK_SIZE);
SlicingBlockDevice slice2(&bd, -(BLOCK_COUNT/2)*BLOCK_SIZE);
SlicingBlockDevice slice1(&bd, 0, (BLOCK_COUNT / 2)*BLOCK_SIZE);
SlicingBlockDevice slice2(&bd, -(BLOCK_COUNT / 2)*BLOCK_SIZE);
// Test with first slice of block device
err = slice1.init();
@ -54,7 +55,7 @@ void test_slicing() {
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_program_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_erase_size(BLOCK_SIZE));
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice1.size());
TEST_ASSERT_EQUAL((BLOCK_COUNT / 2)*BLOCK_SIZE, slice1.size());
uint8_t *write_block = new (std::nothrow) uint8_t[BLOCK_SIZE];
uint8_t *read_block = new (std::nothrow) uint8_t[BLOCK_SIZE];
@ -97,7 +98,7 @@ void test_slicing() {
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice2.get_program_size());
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice2.size());
TEST_ASSERT_EQUAL((BLOCK_COUNT / 2)*BLOCK_SIZE, slice2.size());
// Fill with random sequence
srand(1);
@ -123,7 +124,7 @@ void test_slicing() {
}
// Check with original block device
err = bd.read(read_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(read_block, (BLOCK_COUNT / 2) * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Check that the data was unmodified
@ -141,15 +142,16 @@ end:
}
// Simple test which read/writes blocks on a chain of block devices
void test_chaining() {
void test_chaining()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;
int err;
HeapBlockDevice bd1((BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd2((BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd1((BLOCK_COUNT / 2)*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd2((BLOCK_COUNT / 2)*BLOCK_SIZE, BLOCK_SIZE);
// Test with chain of block device
BlockDevice *bds[] = {&bd1, &bd2};
@ -167,8 +169,8 @@ void test_chaining() {
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_program_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_erase_size((BLOCK_COUNT/2)*BLOCK_SIZE+1));
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, chain.size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_erase_size((BLOCK_COUNT / 2)*BLOCK_SIZE + 1));
TEST_ASSERT_EQUAL(BLOCK_COUNT * BLOCK_SIZE, chain.size());
// Fill with random sequence
srand(1);
@ -190,10 +192,10 @@ void test_chaining() {
}
// Write, sync, and read the block
err = chain.program(write_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
err = chain.program(write_block, (BLOCK_COUNT / 2) * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
err = chain.read(read_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
err = chain.read(read_block, (BLOCK_COUNT / 2) * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Check that the data was unmodified
@ -211,7 +213,8 @@ end:
}
// Simple test which read/writes blocks on a chain of block devices
void test_profiling() {
void test_profiling()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;
@ -219,7 +222,7 @@ void test_profiling() {
int err;
bd_size_t read_count, program_count, erase_count;
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd(BLOCK_COUNT * BLOCK_SIZE, BLOCK_SIZE);
// Test under profiling
ProfilingBlockDevice profiler(&bd);
@ -227,7 +230,7 @@ void test_profiling() {
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT_EQUAL(BLOCK_SIZE, profiler.get_erase_size());
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, profiler.size());
TEST_ASSERT_EQUAL(BLOCK_COUNT * BLOCK_SIZE, profiler.size());
uint8_t *write_block = new (std::nothrow) uint8_t[BLOCK_SIZE];
uint8_t *read_block = new (std::nothrow) uint8_t[BLOCK_SIZE];
@ -287,7 +290,8 @@ end:
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
@ -300,6 +304,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -26,16 +26,17 @@
using namespace utest::v1;
#ifndef MBED_EXTENDED_TESTS
#error [NOT_SUPPORTED] Filesystem tests not supported by default
#error [NOT_SUPPORTED] Filesystem tests not supported by default
#endif
// Test block device
#define BLOCK_SIZE 512
HeapBlockDevice bd(128*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd(128 * BLOCK_SIZE, BLOCK_SIZE);
// Test formatting
void test_format() {
void test_format()
{
int err = FATFileSystem::format(&bd);
TEST_ASSERT_EQUAL(0, err);
}
@ -43,7 +44,8 @@ void test_format() {
// Simple test for reading/writing files
template <ssize_t TEST_SIZE>
void test_read_write() {
void test_read_write()
{
FATFileSystem fs("fat");
int err = fs.mount(&bd);
@ -51,7 +53,7 @@ void test_read_write() {
uint8_t *buffer = (uint8_t *)malloc(TEST_SIZE);
TEST_ASSERT(buffer);
// Fill with random sequence
srand(1);
for (int i = 0; i < TEST_SIZE; i++) {
@ -86,7 +88,8 @@ void test_read_write() {
// Simple test for iterating dir entries
void test_read_dir() {
void test_read_dir()
{
FATFileSystem fs("fat");
int err = fs.mount(&bd);
@ -147,20 +150,22 @@ void test_read_dir() {
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
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 read write < block", test_read_write < BLOCK_SIZE / 2 >),
Case("Testing read write > block", test_read_write<2 * BLOCK_SIZE>),
Case("Testing dir iteration", test_read_dir),
};
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -1959,7 +1959,7 @@ static void FS_fill_data_and_seek()
for (i = 1; i <= 255; i++) {
res = fseek(fd[0], (long)-i, SEEK_END);
res = fseek(fd[0], (long) - i, SEEK_END);
TEST_ASSERT_EQUAL(0, res);
j = getc(fd[0]);

View File

@ -27,22 +27,23 @@
using namespace utest::v1;
#ifndef MBED_EXTENDED_TESTS
#error [NOT_SUPPORTED] Filesystem tests not supported by default
#error [NOT_SUPPORTED] Filesystem tests not supported by default
#endif
// Test block device
#define BLOCK_SIZE 512
#define BLOCK_COUNT 512
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd(BLOCK_COUNT *BLOCK_SIZE, BLOCK_SIZE);
// Test formatting and partitioning
void test_format() {
void test_format()
{
// Create two partitions splitting device in ~half
int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT/2)*BLOCK_SIZE);
int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT / 2) * BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
err = MBRBlockDevice::partition(&bd, 2, 0x83, -(BLOCK_COUNT/2)*BLOCK_SIZE);
err = MBRBlockDevice::partition(&bd, 2, 0x83, -(BLOCK_COUNT / 2) * BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Load both partitions
@ -72,7 +73,8 @@ void test_format() {
// Simple multipartition test for reading/writing files
template <ssize_t TEST_SIZE>
void test_read_write() {
void test_read_write()
{
// Load both partitions
MBRBlockDevice part1(&bd, 1);
int err = part1.init();
@ -97,7 +99,7 @@ void test_read_write() {
uint8_t *buffer2 = (uint8_t *)malloc(TEST_SIZE);
TEST_ASSERT(buffer2);
// Fill with random sequence
srand(1);
@ -163,37 +165,38 @@ void test_read_write() {
TEST_ASSERT_EQUAL(0, err);
}
void test_single_mbr() {
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;
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);
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);
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE - 2], "\x55\xaa", 2) == 0);
err = bd.read(buffer, FAT1_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
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);
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE - 2], "\x55\xaa", 2) == 0);
err = bd.read(buffer, FAT2_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
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);
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);
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);
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);
@ -205,20 +208,22 @@ void test_single_mbr() {
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
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 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);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -40,8 +40,7 @@ typedef uint64_t bd_size_t;
/** A hardware device capable of writing and reading blocks
*/
class BlockDevice
{
class BlockDevice {
public:
/** Return the default block device
@ -198,9 +197,9 @@ public:
bool is_valid_read(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_read_size() == 0 &&
size % get_read_size() == 0 &&
addr + size <= this->size());
addr % get_read_size() == 0 &&
size % get_read_size() == 0 &&
addr + size <= this->size());
}
/** Convenience function for checking block program validity
@ -212,9 +211,9 @@ public:
bool is_valid_program(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_program_size() == 0 &&
size % get_program_size() == 0 &&
addr + size <= this->size());
addr % get_program_size() == 0 &&
size % get_program_size() == 0 &&
addr + size <= this->size());
}
/** Convenience function for checking block erase validity
@ -226,9 +225,9 @@ public:
bool is_valid_erase(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_erase_size(addr) == 0 &&
(addr + size) % get_erase_size(addr + size - 1) == 0 &&
addr + size <= this->size());
addr % get_erase_size(addr) == 0 &&
(addr + size) % get_erase_size(addr + size - 1) == 0 &&
addr + size <= this->size());
}
};

View File

@ -119,7 +119,7 @@ int BufferedBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
bd_addr_t aligned_addr = align_down(addr, _bd_program_size);
uint8_t *buf = static_cast<uint8_t *> (b);
uint8_t *buf = static_cast<uint8_t *>(b);
if (aligned_addr != _curr_aligned_addr) {
// Need to flush if moved to another program unit
@ -159,7 +159,7 @@ int BufferedBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
bd_addr_t aligned_addr = align_down(addr, _bd_program_size);
const uint8_t *buf = static_cast <const uint8_t *> (b);
const uint8_t *buf = static_cast <const uint8_t *>(b);
// Need to flush if moved to another program unit
if (aligned_addr != _curr_aligned_addr) {

View File

@ -141,7 +141,7 @@ int ChainingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
return BD_ERROR_DEVICE_ERROR;
}
uint8_t *buffer = static_cast<uint8_t*>(b);
uint8_t *buffer = static_cast<uint8_t *>(b);
// Find block devices containing blocks, may span multiple block devices
for (size_t i = 0; i < _bd_count && size > 0; i++) {
@ -176,7 +176,7 @@ int ChainingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
return BD_ERROR_DEVICE_ERROR;
}
const uint8_t *buffer = static_cast<const uint8_t*>(b);
const uint8_t *buffer = static_cast<const uint8_t *>(b);
// Find block devices containing blocks, may span multiple block devices
for (size_t i = 0; i < _bd_count && size > 0; i++) {

View File

@ -61,7 +61,7 @@ public:
* @note All block devices must have the same block size
*/
template <size_t Size>
ChainingBlockDevice(BlockDevice *(&bds)[Size])
ChainingBlockDevice(BlockDevice * (&bds)[Size])
: _bds(bds), _bd_count(sizeof(bds) / sizeof(bds[0]))
, _read_size(0), _program_size(0), _erase_size(0), _size(0), _init_ref_count(0)
{

View File

@ -31,8 +31,7 @@
* after a configurable number of cycles.
*
*/
class ExhaustibleBlockDevice : public BlockDevice
{
class ExhaustibleBlockDevice : public BlockDevice {
public:
/** Lifetime of the block device
*

View File

@ -53,7 +53,7 @@ int HeapBlockDevice::init()
}
if (!_blocks) {
_blocks = new uint8_t*[_count];
_blocks = new uint8_t *[_count];
for (size_t i = 0; i < _count; i++) {
_blocks[i] = 0;
}
@ -120,7 +120,7 @@ int HeapBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
return BD_ERROR_DEVICE_ERROR;
}
uint8_t *buffer = static_cast<uint8_t*>(b);
uint8_t *buffer = static_cast<uint8_t *>(b);
while (size > 0) {
bd_addr_t hi = addr / _erase_size;
@ -148,14 +148,14 @@ int HeapBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
return BD_ERROR_DEVICE_ERROR;
}
const uint8_t *buffer = static_cast<const uint8_t*>(b);
const uint8_t *buffer = static_cast<const uint8_t *>(b);
while (size > 0) {
bd_addr_t hi = addr / _erase_size;
bd_addr_t lo = addr % _erase_size;
if (!_blocks[hi]) {
_blocks[hi] = (uint8_t*)malloc(_erase_size);
_blocks[hi] = (uint8_t *)malloc(_erase_size);
if (!_blocks[hi]) {
return BD_ERROR_DEVICE_ERROR;
}

View File

@ -50,8 +50,7 @@
* }
* @endcode
*/
class HeapBlockDevice : public BlockDevice
{
class HeapBlockDevice : public BlockDevice {
public:
/** Lifetime of the memory block device
@ -60,7 +59,7 @@ public:
* @param block Block size in bytes. Minimum read, program, and erase sizes are
* configured to this value
*/
HeapBlockDevice(bd_size_t size, bd_size_t block=512);
HeapBlockDevice(bd_size_t size, bd_size_t block = 512);
/** Lifetime of the memory block device
*
* @param size Size of the Block Device in bytes

View File

@ -60,7 +60,7 @@ static inline uint32_t fromle32(uint32_t a)
static void tochs(uint32_t lba, uint8_t chs[3])
{
uint32_t sector = std::min<uint32_t>(lba, 0xfffffd)+1;
uint32_t sector = std::min<uint32_t>(lba, 0xfffffd) + 1;
chs[0] = (sector >> 6) & 0xff;
chs[1] = ((sector >> 0) & 0x3f) | ((sector >> 16) & 0xc0);
chs[2] = (sector >> 14) & 0xff;
@ -70,28 +70,28 @@ static void tochs(uint32_t lba, uint8_t chs[3])
// Partition after address are turned into absolute
// addresses, assumes bd is initialized
static int partition_absolute(
BlockDevice *bd, int part, uint8_t type,
bd_size_t offset, bd_size_t size)
BlockDevice *bd, int part, uint8_t type,
bd_size_t offset, bd_size_t size)
{
// Allocate smallest buffer necessary to write MBR
uint32_t buffer_size = std::max<uint32_t>(bd->get_program_size(), sizeof(struct mbr_table));
// Prevent alignment issues
if(buffer_size % bd->get_program_size() != 0) {
if (buffer_size % bd->get_program_size() != 0) {
buffer_size += bd->get_program_size() - (buffer_size % bd->get_program_size());
}
uint8_t *buffer = new uint8_t[buffer_size];
// Check for existing MBR
int err = bd->read(buffer, 512-buffer_size, buffer_size);
int err = bd->read(buffer, 512 - buffer_size, buffer_size);
if (err) {
delete[] buffer;
return err;
}
struct mbr_table *table = reinterpret_cast<struct mbr_table*>(
&buffer[buffer_size - sizeof(struct mbr_table)]);
struct mbr_table *table = reinterpret_cast<struct mbr_table *>(
&buffer[buffer_size - sizeof(struct mbr_table)]);
if (table->signature[0] != 0x55 || table->signature[1] != 0xaa) {
// Setup default values for MBR
table->signature[0] = 0x55;
@ -104,8 +104,8 @@ static int partition_absolute(
// partitions if we only check partition type. We add check by only accepting 0x00 (inactive)
// /0x80 (active) for valid partition status.
for (int i = 1; i <= 4; i++) {
if (table->entries[i-1].status != 0x00 &&
table->entries[i-1].status != 0x80) {
if (table->entries[i - 1].status != 0x00 &&
table->entries[i - 1].status != 0x80) {
memset(table->entries, 0, sizeof(table->entries));
break;
}
@ -113,29 +113,29 @@ static int partition_absolute(
// Setup new partition
MBED_ASSERT(part >= 1 && part <= 4);
table->entries[part-1].status = 0x00; // inactive (not bootable)
table->entries[part-1].type = type;
table->entries[part - 1].status = 0x00; // inactive (not bootable)
table->entries[part - 1].type = type;
// lba dimensions
MBED_ASSERT(bd->is_valid_erase(offset, size));
uint32_t sector = std::max<uint32_t>(bd->get_erase_size(), 512);
uint32_t lba_offset = offset / sector;
uint32_t lba_size = size / sector;
table->entries[part-1].lba_offset = tole32(lba_offset);
table->entries[part-1].lba_size = tole32(lba_size);
table->entries[part - 1].lba_offset = tole32(lba_offset);
table->entries[part - 1].lba_size = tole32(lba_size);
// chs dimensions
tochs(lba_offset, table->entries[part-1].chs_start);
tochs(lba_offset+lba_size-1, table->entries[part-1].chs_stop);
tochs(lba_offset, table->entries[part - 1].chs_start);
tochs(lba_offset + lba_size - 1, table->entries[part - 1].chs_stop);
// Check that we don't overlap other entries
for (int i = 1; i <= 4; i++) {
if (i != part && table->entries[i-1].type != 0x00) {
uint32_t neighbor_lba_offset = fromle32(table->entries[i-1].lba_offset);
uint32_t neighbor_lba_size = fromle32(table->entries[i-1].lba_size);
if (i != part && table->entries[i - 1].type != 0x00) {
uint32_t neighbor_lba_offset = fromle32(table->entries[i - 1].lba_offset);
uint32_t neighbor_lba_size = fromle32(table->entries[i - 1].lba_size);
MBED_ASSERT(
(lba_offset >= neighbor_lba_offset + neighbor_lba_size) ||
(lba_offset + lba_size <= neighbor_lba_offset));
(lba_offset >= neighbor_lba_offset + neighbor_lba_size) ||
(lba_offset + lba_size <= neighbor_lba_offset));
(void)neighbor_lba_offset;
(void)neighbor_lba_size;
}
@ -148,7 +148,7 @@ static int partition_absolute(
return err;
}
err = bd->program(buffer, 512-buffer_size, buffer_size);
err = bd->program(buffer, 512 - buffer_size, buffer_size);
delete[] buffer;
return err;
}
@ -184,7 +184,7 @@ int MBRBlockDevice::partition(BlockDevice *bd, int part, uint8_t type, bd_addr_t
}
int MBRBlockDevice::partition(BlockDevice *bd, int part, uint8_t type,
bd_addr_t start, bd_addr_t stop)
bd_addr_t start, bd_addr_t stop)
{
int err = bd->init();
if (err) {
@ -243,13 +243,13 @@ int MBRBlockDevice::init()
buffer_size = std::max<uint32_t>(_bd->get_read_size(), sizeof(struct mbr_table));
buffer = new uint8_t[buffer_size];
err = _bd->read(buffer, 512-buffer_size, buffer_size);
err = _bd->read(buffer, 512 - buffer_size, buffer_size);
if (err) {
goto fail;
}
// Check for valid table
table = reinterpret_cast<struct mbr_table*>(&buffer[buffer_size - sizeof(struct mbr_table)]);
table = reinterpret_cast<struct mbr_table *>(&buffer[buffer_size - sizeof(struct mbr_table)]);
if (table->signature[0] != 0x55 || table->signature[1] != 0xaa) {
err = BD_ERROR_INVALID_MBR;
goto fail;
@ -257,8 +257,8 @@ int MBRBlockDevice::init()
// Check for valid partition status
// Same reason as in partition_absolute regarding Windows-formatted SD card
if (table->entries[_part-1].status != 0x00 &&
table->entries[_part-1].status != 0x80) {
if (table->entries[_part - 1].status != 0x00 &&
table->entries[_part - 1].status != 0x80) {
err = BD_ERROR_INVALID_PARTITION;
goto fail;
}
@ -266,18 +266,18 @@ int MBRBlockDevice::init()
// Check for valid entry
// 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)) {
if ((table->entries[_part - 1].type == 0x00 ||
table->entries[_part - 1].type == 0x05 ||
table->entries[_part - 1].type == 0x0f)) {
err = BD_ERROR_INVALID_PARTITION;
goto fail;
}
// Get partition attributes
sector = std::max<uint32_t>(_bd->get_erase_size(), 512);
_type = table->entries[_part-1].type;
_offset = fromle32(table->entries[_part-1].lba_offset) * sector;
_size = fromle32(table->entries[_part-1].lba_size) * sector;
_type = table->entries[_part - 1].type;
_offset = fromle32(table->entries[_part - 1].lba_offset) * sector;
_size = fromle32(table->entries[_part - 1].lba_size) * sector;
// Check that block addresses are valid
if (!_bd->is_valid_erase(_offset, _size)) {
@ -408,7 +408,7 @@ bd_size_t MBRBlockDevice::get_partition_start() const
bd_size_t MBRBlockDevice::get_partition_stop() const
{
return _offset+_size;
return _offset + _size;
}
uint8_t MBRBlockDevice::get_partition_type() const

View File

@ -87,15 +87,14 @@ enum {
* - At most 4 partitions are supported
* - Extended partitions are currently not supported and will error during init
*/
class MBRBlockDevice : public BlockDevice
{
class MBRBlockDevice : public BlockDevice {
public:
/** Format the MBR to contain the following partition
*
* @param bd Block device to partition
* @param part Partition to use, 1-4
* @param type 8-bit partition type to identitfy partition's contents
* @param start Start block address to map to block 0 of partition,
* @param start Start block address to map to block 0 of partition,
* negative addresses are calculated from the end of the
* underlying block devices. Block 0 is implicitly ignored
* from the range to store the MBR.
@ -109,7 +108,7 @@ public:
* @param bd Block device to partition
* @param part Partition to use, 1-4
* @param type 8-bit partition type to identitfy partition's contents
* @param start Start block address to map to block 0 of partition,
* @param start Start block address to map to block 0 of partition,
* negative addresses are calculated from the end of the
* underlying block devices. Block 0 is implicitly ignored
* from the range to store the MBR.

View File

@ -27,8 +27,7 @@
#include "platform/Callback.h"
class ObservingBlockDevice : public BlockDevice
{
class ObservingBlockDevice : public BlockDevice {
public:
/** Lifetime of the block device

View File

@ -43,8 +43,7 @@
* printf("erase count: %lld\n", profiler.get_erase_count());
* @endcode
*/
class ProfilingBlockDevice : public BlockDevice
{
class ProfilingBlockDevice : public BlockDevice {
public:
/** Lifetime of the memory block device
*

View File

@ -26,8 +26,7 @@
#include "PlatformMutex.h"
class ReadOnlyBlockDevice : public BlockDevice
{
class ReadOnlyBlockDevice : public BlockDevice {
public:
/** Lifetime of the block device

View File

@ -45,8 +45,7 @@
* SlicingBlockDevice slice3(&mem, 16*512, -16*512);
* @endcode
*/
class SlicingBlockDevice : public BlockDevice
{
class SlicingBlockDevice : public BlockDevice {
public:
/** Lifetime of the memory block device
*

View File

@ -35,7 +35,7 @@ public:
*/
Dir();
/** Open a directory on a filesystem
/** Open a directory on a filesystem
*
* @param fs Filesystem as target for a directory
* @param path Name of the directory to open
@ -86,7 +86,7 @@ public:
*/
virtual void rewind();
/** Get the sizeof the directory
/** Get the sizeof the directory
*
* @return Number of files in the directory
*/

View File

@ -35,7 +35,7 @@ public:
*/
File();
/** Create a file on a filesystem
/** Create a file on a filesystem
*
* Creates and opens a file on a filesystem
*
@ -60,7 +60,7 @@ public:
* bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
* @return 0 on success, negative error code on failure
*/
virtual int open(FileSystem *fs, const char *path, int flags=O_RDONLY);
virtual int open(FileSystem *fs, const char *path, int flags = O_RDONLY);
/** Close a file
*
@ -80,7 +80,7 @@ public:
/** Write the contents of a buffer to a file
*
* @param buffer The buffer to write from
* @param size The number of bytes to write
* @param size The number of bytes to write
* @return The number of bytes written, negative error on failure
*/
virtual ssize_t write(const void *buffer, size_t size);

View File

@ -139,7 +139,8 @@ size_t FileSystem::dir_size(fs_dir_t dir)
template <typename F>
class Managed : public F {
public:
virtual int close() {
virtual int close()
{
int err = F::close();
delete this;
return err;
@ -159,7 +160,8 @@ int FileSystem::open(FileHandle **file, const char *path, int flags)
return 0;
}
int FileSystem::open(DirHandle **dir, const char *path) {
int FileSystem::open(DirHandle **dir, const char *path)
{
Dir *d = new Managed<Dir>;
int err = d->open(this, path);
if (err) {

View File

@ -131,7 +131,7 @@ public:
* @param buf The stat buffer to write to
* @return 0 on success, negative error code on failure
*/
virtual int statvfs(const char *path, struct statvfs *buf);
virtual int statvfs(const char *path, struct statvfs *buf);
protected:
friend class File;

View File

@ -33,7 +33,7 @@ using namespace mbed;
static int fat_error_remap(FRESULT res)
{
switch(res) {
switch (res) {
case FR_OK: // (0) Succeeded
return 0;
case FR_DISK_ERR: // (1) A hard error occurred in the low level disk I/O layer
@ -86,8 +86,8 @@ public:
T _t;
Callback<void(T)> _ondefer;
Deferred(const Deferred&);
Deferred &operator=(const Deferred&);
Deferred(const Deferred &);
Deferred &operator=(const Deferred &);
public:
Deferred(T t, Callback<void(T)> ondefer = NULL)
@ -115,7 +115,7 @@ static void dodelete(const char *data)
// Adds prefix needed internally by fatfs, this can be avoided for the first fatfs
// (id 0) otherwise a prefix of "id:/" is inserted in front of the string.
static Deferred<const char*> fat_path_prefix(int id, const char *path)
static Deferred<const char *> fat_path_prefix(int id, const char *path)
{
// We can avoid dynamic allocation when only on fatfs is in use
if (id == 0) {
@ -132,7 +132,7 @@ static Deferred<const char*> fat_path_prefix(int id, const char *path)
buffer[1] = ':';
buffer[2] = '/';
strcpy(buffer + strlen("0:/"), path);
return Deferred<const char*>(buffer, dodelete);
return Deferred<const char *>(buffer, dodelete);
}
@ -150,11 +150,11 @@ DWORD get_fattime(void)
time(&rawtime);
struct tm *ptm = localtime(&rawtime);
return (DWORD)(ptm->tm_year - 80) << 25
| (DWORD)(ptm->tm_mon + 1 ) << 21
| (DWORD)(ptm->tm_mday ) << 16
| (DWORD)(ptm->tm_hour ) << 11
| (DWORD)(ptm->tm_min ) << 5
| (DWORD)(ptm->tm_sec/2 );
| (DWORD)(ptm->tm_mon + 1) << 21
| (DWORD)(ptm->tm_mday) << 16
| (DWORD)(ptm->tm_hour) << 11
| (DWORD)(ptm->tm_min) << 5
| (DWORD)(ptm->tm_sec / 2);
}
void *ff_memalloc(UINT size)
@ -207,8 +207,8 @@ DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
{
debug_if(FFS_DBG, "disk_read(sector %lu, count %u) on pdrv [%d]\n", sector, count, pdrv);
DWORD ssize = disk_get_sector_size(pdrv);
bd_addr_t addr = (bd_addr_t)sector*ssize;
bd_size_t size = (bd_size_t)count*ssize;
bd_addr_t addr = (bd_addr_t)sector * ssize;
bd_size_t size = (bd_size_t)count * ssize;
int err = _ffs[pdrv]->read(buff, addr, size);
return err ? RES_PARERR : RES_OK;
}
@ -217,8 +217,8 @@ DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
{
debug_if(FFS_DBG, "disk_write(sector %lu, count %u) on pdrv [%d]\n", sector, count, pdrv);
DWORD ssize = disk_get_sector_size(pdrv);
bd_addr_t addr = (bd_addr_t)sector*ssize;
bd_size_t size = (bd_size_t)count*ssize;
bd_addr_t addr = (bd_addr_t)sector * ssize;
bd_size_t size = (bd_size_t)count * ssize;
int err = _ffs[pdrv]->erase(addr, size);
if (err) {
return RES_PARERR;
@ -246,27 +246,27 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
if (_ffs[pdrv] == NULL) {
return RES_NOTRDY;
} else {
*((DWORD*)buff) = disk_get_sector_count(pdrv);
*((DWORD *)buff) = disk_get_sector_count(pdrv);
return RES_OK;
}
case GET_SECTOR_SIZE:
if (_ffs[pdrv] == NULL) {
return RES_NOTRDY;
} else {
*((WORD*)buff) = disk_get_sector_size(pdrv);
*((WORD *)buff) = disk_get_sector_size(pdrv);
return RES_OK;
}
case GET_BLOCK_SIZE:
*((DWORD*)buff) = 1; // default when not known
*((DWORD *)buff) = 1; // default when not known
return RES_OK;
case CTRL_TRIM:
if (_ffs[pdrv] == NULL) {
return RES_NOTRDY;
} else {
DWORD *sectors = (DWORD*)buff;
DWORD *sectors = (DWORD *)buff;
DWORD ssize = disk_get_sector_size(pdrv);
bd_addr_t addr = (bd_addr_t)sectors[0]*ssize;
bd_size_t size = (bd_size_t)(sectors[1]-sectors[0]+1)*ssize;
bd_addr_t addr = (bd_addr_t)sectors[0] * ssize;
bd_size_t size = (bd_size_t)(sectors[1] - sectors[0] + 1) * ssize;
int err = _ffs[pdrv]->trim(addr, size);
return err ? RES_PARERR : RES_OK;
}
@ -280,7 +280,8 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
// Filesystem implementation (See FATFilySystem.h)
FATFileSystem::FATFileSystem(const char *name, BlockDevice *bd)
: FileSystem(name), _id(-1) {
: FileSystem(name), _id(-1)
{
if (bd) {
mount(bd);
}
@ -353,7 +354,7 @@ int FATFileSystem::format(BlockDevice *bd, bd_size_t cluster_size)
}
// erase first handful of blocks
bd_size_t header = 2*bd->get_erase_size();
bd_size_t header = 2 * bd->get_erase_size();
err = bd->erase(0, header);
if (err) {
bd->deinit();
@ -457,7 +458,7 @@ int FATFileSystem::reformat(BlockDevice *bd, int allocation_unit)
int FATFileSystem::remove(const char *path)
{
Deferred<const char*> fpath = fat_path_prefix(_id, path);
Deferred<const char *> fpath = fat_path_prefix(_id, path);
lock();
FRESULT res = f_unlink(fpath);
@ -474,8 +475,8 @@ int FATFileSystem::remove(const char *path)
int FATFileSystem::rename(const char *oldpath, const char *newpath)
{
Deferred<const char*> oldfpath = fat_path_prefix(_id, oldpath);
Deferred<const char*> newfpath = fat_path_prefix(_id, newpath);
Deferred<const char *> oldfpath = fat_path_prefix(_id, oldpath);
Deferred<const char *> newfpath = fat_path_prefix(_id, newpath);
lock();
FRESULT res = f_rename(oldfpath, newfpath);
@ -489,7 +490,7 @@ int FATFileSystem::rename(const char *oldpath, const char *newpath)
int FATFileSystem::mkdir(const char *path, mode_t mode)
{
Deferred<const char*> fpath = fat_path_prefix(_id, path);
Deferred<const char *> fpath = fat_path_prefix(_id, path);
lock();
FRESULT res = f_mkdir(fpath);
@ -503,7 +504,7 @@ int FATFileSystem::mkdir(const char *path, mode_t mode)
int FATFileSystem::stat(const char *path, struct stat *st)
{
Deferred<const char*> fpath = fat_path_prefix(_id, path);
Deferred<const char *> fpath = fat_path_prefix(_id, path);
lock();
FILINFO f;
@ -521,8 +522,8 @@ int FATFileSystem::stat(const char *path, struct stat *st)
st->st_mode = 0;
st->st_mode |= (f.fattrib & AM_DIR) ? S_IFDIR : S_IFREG;
st->st_mode |= (f.fattrib & AM_RDO) ?
(S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) :
(S_IRWXU | S_IRWXG | S_IRWXO);
(S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) :
(S_IRWXU | S_IRWXG | S_IRWXO);
#endif /* TOOLCHAIN_GCC */
unlock();
@ -575,7 +576,7 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags)
debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%d]\n", path, getName(), _id);
FIL *fh = new FIL;
Deferred<const char*> fpath = fat_path_prefix(_id, path);
Deferred<const char *> fpath = fat_path_prefix(_id, path);
/* POSIX flags -> FatFS open mode */
BYTE openmode;
@ -617,7 +618,7 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags)
int FATFileSystem::file_close(fs_file_t file)
{
FIL *fh = static_cast<FIL*>(file);
FIL *fh = static_cast<FIL *>(file);
lock();
FRESULT res = f_close(fh);
@ -629,7 +630,7 @@ int FATFileSystem::file_close(fs_file_t file)
ssize_t FATFileSystem::file_read(fs_file_t file, void *buffer, size_t len)
{
FIL *fh = static_cast<FIL*>(file);
FIL *fh = static_cast<FIL *>(file);
lock();
UINT n;
@ -646,7 +647,7 @@ ssize_t FATFileSystem::file_read(fs_file_t file, void *buffer, size_t len)
ssize_t FATFileSystem::file_write(fs_file_t file, const void *buffer, size_t len)
{
FIL *fh = static_cast<FIL*>(file);
FIL *fh = static_cast<FIL *>(file);
lock();
UINT n;
@ -663,7 +664,7 @@ ssize_t FATFileSystem::file_write(fs_file_t file, const void *buffer, size_t len
int FATFileSystem::file_sync(fs_file_t file)
{
FIL *fh = static_cast<FIL*>(file);
FIL *fh = static_cast<FIL *>(file);
lock();
FRESULT res = f_sync(fh);
@ -677,12 +678,12 @@ int FATFileSystem::file_sync(fs_file_t file)
off_t FATFileSystem::file_seek(fs_file_t file, off_t offset, int whence)
{
FIL *fh = static_cast<FIL*>(file);
FIL *fh = static_cast<FIL *>(file);
lock();
if (whence == SEEK_END) {
offset += f_size(fh);
} else if(whence==SEEK_CUR) {
} else if (whence == SEEK_CUR) {
offset += f_tell(fh);
}
@ -700,7 +701,7 @@ off_t FATFileSystem::file_seek(fs_file_t file, off_t offset, int whence)
off_t FATFileSystem::file_tell(fs_file_t file)
{
FIL *fh = static_cast<FIL*>(file);
FIL *fh = static_cast<FIL *>(file);
lock();
off_t res = f_tell(fh);
@ -711,7 +712,7 @@ off_t FATFileSystem::file_tell(fs_file_t file)
off_t FATFileSystem::file_size(fs_file_t file)
{
FIL *fh = static_cast<FIL*>(file);
FIL *fh = static_cast<FIL *>(file);
lock();
off_t res = f_size(fh);
@ -725,7 +726,7 @@ off_t FATFileSystem::file_size(fs_file_t file)
int FATFileSystem::dir_open(fs_dir_t *dir, const char *path)
{
FATFS_DIR *dh = new FATFS_DIR;
Deferred<const char*> fpath = fat_path_prefix(_id, path);
Deferred<const char *> fpath = fat_path_prefix(_id, path);
lock();
FRESULT res = f_opendir(dh, fpath);
@ -743,7 +744,7 @@ int FATFileSystem::dir_open(fs_dir_t *dir, const char *path)
int FATFileSystem::dir_close(fs_dir_t dir)
{
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
FATFS_DIR *dh = static_cast<FATFS_DIR *>(dir);
lock();
FRESULT res = f_closedir(dh);
@ -755,7 +756,7 @@ int FATFileSystem::dir_close(fs_dir_t dir)
ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent)
{
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
FATFS_DIR *dh = static_cast<FATFS_DIR *>(dir);
FILINFO finfo;
lock();
@ -784,7 +785,7 @@ ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent)
void FATFileSystem::dir_seek(fs_dir_t dir, off_t offset)
{
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
FATFS_DIR *dh = static_cast<FATFS_DIR *>(dir);
off_t dptr = static_cast<off_t>(dh->dptr);
lock();
@ -809,7 +810,7 @@ void FATFileSystem::dir_seek(fs_dir_t dir, off_t offset)
off_t FATFileSystem::dir_tell(fs_dir_t dir)
{
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
FATFS_DIR *dh = static_cast<FATFS_DIR *>(dir);
lock();
off_t offset = dh->dptr;
@ -820,7 +821,7 @@ off_t FATFileSystem::dir_tell(fs_dir_t dir)
void FATFileSystem::dir_rewind(fs_dir_t dir)
{
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
FATFS_DIR *dh = static_cast<FATFS_DIR *>(dir);
lock();
f_rewinddir(dh);

View File

@ -146,7 +146,7 @@ public:
* @param buf The stat buffer to write to
* @return 0 on success, negative error code on failure
*/
virtual int statvfs(const char *path, struct statvfs *buf);
virtual int statvfs(const char *path, struct statvfs *buf);
protected:
/** Open a file on the filesystem

View File

@ -465,7 +465,7 @@ static void nvstore_multi_thread_test()
if (!threads) {
goto mem_fail;
}
memset(threads, 0, thr_test_num_threads * sizeof(rtos::Thread*));
memset(threads, 0, thr_test_num_threads * sizeof(rtos::Thread *));
ret = nvstore.reset();
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, ret);
@ -666,7 +666,8 @@ clean:
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) {
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{
greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE;
}

View File

@ -38,8 +38,7 @@ static const uint16_t master_record_key = 0xFFE;
static const uint16_t no_key = 0xFFF;
static const uint16_t last_reserved_key = master_record_key;
typedef struct
{
typedef struct {
uint16_t key_and_flags;
uint16_t size_and_owner;
uint32_t crc;
@ -88,10 +87,12 @@ static const uint8_t blank_flash_val = 0xFF;
#endif
NVStore::nvstore_area_data_t NVStore::initial_area_params[] = {{NVSTORE_AREA_1_ADDRESS, NVSTORE_AREA_1_SIZE},
{NVSTORE_AREA_2_ADDRESS, NVSTORE_AREA_2_SIZE}};
{NVSTORE_AREA_2_ADDRESS, NVSTORE_AREA_2_SIZE}
};
#else
NVStore::nvstore_area_data_t NVStore::initial_area_params[] = {{0, 0},
{0, 0}};
{0, 0}
};
#endif
typedef enum {
@ -130,18 +131,18 @@ static uint32_t crc32(uint32_t init_crc, uint32_t data_size, uint8_t *data_buf)
crc = init_crc;
for (i = 0; i < data_size; i++) {
crc = crc ^ (uint32_t) (data_buf[i]);
crc = crc ^ (uint32_t)(data_buf[i]);
for (j = 0; j < 8; j++) {
mask = -(crc & 1);
crc = (crc >> 1) ^ (0xEDB88320 & mask);
mask = -(crc & 1);
crc = (crc >> 1) ^ (0xEDB88320 & mask);
}
}
return crc;
}
NVStore::NVStore() : _init_done(0), _init_attempts(0), _active_area(0), _max_keys(NVSTORE_MAX_KEYS),
_active_area_version(0), _free_space_offset(0), _size(0), _mutex(0), _offset_by_key(0), _flash(0),
_min_prog_size(0), _page_buf(0)
_active_area_version(0), _free_space_offset(0), _size(0), _mutex(0), _offset_by_key(0), _flash(0),
_min_prog_size(0), _page_buf(0)
{
}
@ -270,7 +271,7 @@ void NVStore::calc_validate_area_params()
_flash_area_params[area].size = 0;
int i;
for (i = num_sectors - 1; i >= 0; i--) {
sector_size = sector_map[i+1] - sector_map[i];
sector_size = sector_map[i + 1] - sector_map[i];
_flash_area_params[area].size += sector_size;
if (_flash_area_params[area].size >= min_area_size) {
_flash_area_params[area].address = sector_map[i];
@ -534,8 +535,8 @@ int NVStore::garbage_collection(uint16_t key, uint16_t flags, uint8_t owner, uin
return ret;
}
_offset_by_key[key] = new_area_offset | (1 - _active_area) << offs_by_key_area_bit_pos |
(((flags & set_once_flag) != 0) << offs_by_key_set_once_bit_pos) |
(owner << offs_by_key_owner_bit_pos);
(((flags & set_once_flag) != 0) << offs_by_key_set_once_bit_pos) |
(owner << offs_by_key_owner_bit_pos);
new_area_offset = next_offset;
}
@ -608,7 +609,7 @@ int NVStore::do_get(uint16_t key, uint16_t buf_size, void *buf, uint16_t &actual
}
_mutex->lock();
record_offset = _offset_by_key[key];
area = (uint8_t)(record_offset >> offs_by_key_area_bit_pos) & 1;
record_offset &= offs_by_key_offset_mask;

View File

@ -84,7 +84,7 @@ public:
*
* @returns Singleton instance reference.
*/
static NVStore& get_instance()
static NVStore &get_instance()
{
// Use this implementation of singleton (Meyer's) rather than the one that allocates
// the instance on the heap because it ensures destruction at program end (preventing warnings