mirror of https://github.com/ARMmbed/mbed-os.git
littlefs: fix coding style
parent
bc4101e5f3
commit
20646d3da1
|
@ -33,17 +33,28 @@ extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size)
|
|||
static int lfs_toerror(int err)
|
||||
{
|
||||
switch (err) {
|
||||
case LFS_ERR_OK: return 0;
|
||||
case LFS_ERR_IO: return -EIO;
|
||||
case LFS_ERR_NOENT: return -ENOENT;
|
||||
case LFS_ERR_EXIST: return -EEXIST;
|
||||
case LFS_ERR_NOTDIR: return -ENOTDIR;
|
||||
case LFS_ERR_ISDIR: return -EISDIR;
|
||||
case LFS_ERR_INVAL: return -EINVAL;
|
||||
case LFS_ERR_NOSPC: return -ENOSPC;
|
||||
case LFS_ERR_NOMEM: return -ENOMEM;
|
||||
case LFS_ERR_CORRUPT: return -EILSEQ;
|
||||
default: return err;
|
||||
case LFS_ERR_OK:
|
||||
return 0;
|
||||
case LFS_ERR_IO:
|
||||
return -EIO;
|
||||
case LFS_ERR_NOENT:
|
||||
return -ENOENT;
|
||||
case LFS_ERR_EXIST:
|
||||
return -EEXIST;
|
||||
case LFS_ERR_NOTDIR:
|
||||
return -ENOTDIR;
|
||||
case LFS_ERR_ISDIR:
|
||||
return -EISDIR;
|
||||
case LFS_ERR_INVAL:
|
||||
return -EINVAL;
|
||||
case LFS_ERR_NOSPC:
|
||||
return -ENOSPC;
|
||||
case LFS_ERR_NOMEM:
|
||||
return -ENOMEM;
|
||||
case LFS_ERR_CORRUPT:
|
||||
return -EILSEQ;
|
||||
default:
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,10 +73,14 @@ static int lfs_fromflags(int flags)
|
|||
static int lfs_fromwhence(int whence)
|
||||
{
|
||||
switch (whence) {
|
||||
case SEEK_SET: return LFS_SEEK_SET;
|
||||
case SEEK_CUR: return LFS_SEEK_CUR;
|
||||
case SEEK_END: return LFS_SEEK_END;
|
||||
default: return whence;
|
||||
case SEEK_SET:
|
||||
return LFS_SEEK_SET;
|
||||
case SEEK_CUR:
|
||||
return LFS_SEEK_CUR;
|
||||
case SEEK_END:
|
||||
return LFS_SEEK_END;
|
||||
default:
|
||||
return whence;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,39 +88,47 @@ static int lfs_tomode(int type)
|
|||
{
|
||||
int mode = S_IRWXU | S_IRWXG | S_IRWXO;
|
||||
switch (type) {
|
||||
case LFS_TYPE_DIR: return mode | S_IFDIR;
|
||||
case LFS_TYPE_REG: return mode | S_IFREG;
|
||||
default: return 0;
|
||||
case LFS_TYPE_DIR:
|
||||
return mode | S_IFDIR;
|
||||
case LFS_TYPE_REG:
|
||||
return mode | S_IFREG;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int lfs_totype(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case LFS_TYPE_DIR: return DT_DIR;
|
||||
case LFS_TYPE_REG: return DT_REG;
|
||||
default: return DT_UNKNOWN;
|
||||
case LFS_TYPE_DIR:
|
||||
return DT_DIR;
|
||||
case LFS_TYPE_REG:
|
||||
return DT_REG;
|
||||
default:
|
||||
return DT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////// Block device operations //////
|
||||
static int lfs_bd_read(const struct lfs_config *c, lfs_block_t block,
|
||||
lfs_off_t off, void *buffer, lfs_size_t size) {
|
||||
lfs_off_t off, void *buffer, lfs_size_t size)
|
||||
{
|
||||
BlockDevice *bd = (BlockDevice *)c->context;
|
||||
return bd->read(buffer, (bd_addr_t)block*c->block_size + off, size);
|
||||
return bd->read(buffer, (bd_addr_t)block * c->block_size + off, size);
|
||||
}
|
||||
|
||||
static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block,
|
||||
lfs_off_t off, const void *buffer, lfs_size_t size) {
|
||||
lfs_off_t off, const void *buffer, lfs_size_t size)
|
||||
{
|
||||
BlockDevice *bd = (BlockDevice *)c->context;
|
||||
return bd->program(buffer, (bd_addr_t)block*c->block_size + off, size);
|
||||
return bd->program(buffer, (bd_addr_t)block * c->block_size + off, size);
|
||||
}
|
||||
|
||||
static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block)
|
||||
{
|
||||
BlockDevice *bd = (BlockDevice *)c->context;
|
||||
return bd->erase((bd_addr_t)block*c->block_size, c->block_size);
|
||||
return bd->erase((bd_addr_t)block * c->block_size, c->block_size);
|
||||
}
|
||||
|
||||
static int lfs_bd_sync(const struct lfs_config *c)
|
||||
|
@ -125,13 +148,15 @@ LittleFileSystem::LittleFileSystem(const char *name, BlockDevice *bd,
|
|||
, _read_size(read_size)
|
||||
, _prog_size(prog_size)
|
||||
, _block_size(block_size)
|
||||
, _lookahead(lookahead) {
|
||||
, _lookahead(lookahead)
|
||||
{
|
||||
if (bd) {
|
||||
mount(bd);
|
||||
}
|
||||
}
|
||||
|
||||
LittleFileSystem::~LittleFileSystem() {
|
||||
LittleFileSystem::~LittleFileSystem()
|
||||
{
|
||||
// nop if unmounted
|
||||
unmount();
|
||||
}
|
||||
|
@ -168,7 +193,7 @@ int LittleFileSystem::mount(BlockDevice *bd)
|
|||
_config.block_size = _block_size;
|
||||
}
|
||||
_config.block_count = bd->size() / _config.block_size;
|
||||
_config.lookahead = 32 * ((_config.block_count+31)/32);
|
||||
_config.lookahead = 32 * ((_config.block_count + 31) / 32);
|
||||
if (_config.lookahead > _lookahead) {
|
||||
_config.lookahead = _lookahead;
|
||||
}
|
||||
|
@ -212,7 +237,8 @@ int LittleFileSystem::unmount()
|
|||
|
||||
int LittleFileSystem::format(BlockDevice *bd,
|
||||
lfs_size_t read_size, lfs_size_t prog_size,
|
||||
lfs_size_t block_size, lfs_size_t lookahead) {
|
||||
lfs_size_t block_size, lfs_size_t lookahead)
|
||||
{
|
||||
LFS_INFO("format(%p, %ld, %ld, %ld, %ld)",
|
||||
bd, read_size, prog_size, block_size, lookahead);
|
||||
int err = bd->init();
|
||||
|
@ -243,7 +269,7 @@ int LittleFileSystem::format(BlockDevice *bd,
|
|||
_config.block_size = block_size;
|
||||
}
|
||||
_config.block_count = bd->size() / _config.block_size;
|
||||
_config.lookahead = 32 * ((_config.block_count+31)/32);
|
||||
_config.lookahead = 32 * ((_config.block_count + 31) / 32);
|
||||
if (_config.lookahead > lookahead) {
|
||||
_config.lookahead = lookahead;
|
||||
}
|
||||
|
|
|
@ -51,11 +51,11 @@ public:
|
|||
* The lookahead buffer requires only 1 bit per block so it can be quite
|
||||
* large with little ram impact. Should be a multiple of 32.
|
||||
*/
|
||||
LittleFileSystem(const char *name=NULL, BlockDevice *bd=NULL,
|
||||
lfs_size_t read_size=MBED_LFS_READ_SIZE,
|
||||
lfs_size_t prog_size=MBED_LFS_PROG_SIZE,
|
||||
lfs_size_t block_size=MBED_LFS_BLOCK_SIZE,
|
||||
lfs_size_t lookahead=MBED_LFS_LOOKAHEAD);
|
||||
LittleFileSystem(const char *name = NULL, BlockDevice *bd = NULL,
|
||||
lfs_size_t read_size = MBED_LFS_READ_SIZE,
|
||||
lfs_size_t prog_size = MBED_LFS_PROG_SIZE,
|
||||
lfs_size_t block_size = MBED_LFS_BLOCK_SIZE,
|
||||
lfs_size_t lookahead = MBED_LFS_LOOKAHEAD);
|
||||
virtual ~LittleFileSystem();
|
||||
|
||||
/** Formats a block device with the LittleFileSystem
|
||||
|
@ -82,10 +82,10 @@ public:
|
|||
* large with little ram impact. Should be a multiple of 32.
|
||||
*/
|
||||
static int format(BlockDevice *bd,
|
||||
lfs_size_t read_size=MBED_LFS_READ_SIZE,
|
||||
lfs_size_t prog_size=MBED_LFS_PROG_SIZE,
|
||||
lfs_size_t block_size=MBED_LFS_BLOCK_SIZE,
|
||||
lfs_size_t lookahead=MBED_LFS_LOOKAHEAD);
|
||||
lfs_size_t read_size = MBED_LFS_READ_SIZE,
|
||||
lfs_size_t prog_size = MBED_LFS_PROG_SIZE,
|
||||
lfs_size_t block_size = MBED_LFS_BLOCK_SIZE,
|
||||
lfs_size_t lookahead = MBED_LFS_LOOKAHEAD);
|
||||
|
||||
/** Mounts a filesystem to a block device
|
||||
*
|
||||
|
|
|
@ -157,9 +157,9 @@ static int file_scanf(File *file, const char *format, ...)
|
|||
int res = file->read(buf, sizeof(buf) - 1);
|
||||
TEST_ASSERT_OR_EXIT(res >= 0);
|
||||
|
||||
va_start (args, format);
|
||||
int count = vsscanf((char*)buf, format, args);
|
||||
va_end (args);
|
||||
va_start(args, format);
|
||||
int count = vsscanf((char *)buf, format, args);
|
||||
va_end(args);
|
||||
TEST_ASSERT_OR_EXIT(count >= 0);
|
||||
|
||||
return count;
|
||||
|
@ -176,9 +176,9 @@ static int file_printf(File *file, const char *format, ...)
|
|||
{
|
||||
uint8_t buf[BUFFER_SIZE];
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
int size = vsprintf((char*)buf, format, args);
|
||||
va_end (args);
|
||||
va_start(args, format);
|
||||
int size = vsprintf((char *)buf, format, args);
|
||||
va_end(args);
|
||||
TEST_ASSERT_OR_EXIT((size >= 0) && (size <= (int)sizeof(buf)));
|
||||
|
||||
if (file_write(file, buf, size)) {
|
||||
|
@ -254,7 +254,7 @@ static void check_file_rename(FileSystem *fs)
|
|||
|
||||
int files = 0;
|
||||
int valids = 0;
|
||||
const char * const filenames[] = {FILE_RENAME_A, FILE_RENAME_B};
|
||||
const char *const filenames[] = {FILE_RENAME_A, FILE_RENAME_B};
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
File file;
|
||||
|
@ -300,7 +300,7 @@ static void setup_file_rename_replace(FileSystem *fs)
|
|||
uint32_t count = 0;
|
||||
uint8_t buf[BUFFER_SIZE];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
const int length = sprintf((char*)buf, FILE_RENAME_REPLACE_FMT, count);
|
||||
const int length = sprintf((char *)buf, FILE_RENAME_REPLACE_FMT, count);
|
||||
TEST_ASSERT_OR_EXIT(length > 0);
|
||||
|
||||
res = file.write(buf, length);
|
||||
|
@ -602,7 +602,7 @@ static bool format_required(BlockDevice *bd)
|
|||
|
||||
// Get the test version
|
||||
uint32_t version = 0;
|
||||
res = sscanf((char*)buf, FILE_SETUP_COMPLETE_FMT, &version);
|
||||
res = sscanf((char *)buf, FILE_SETUP_COMPLETE_FMT, &version);
|
||||
if (res != 1) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -300,8 +300,8 @@ void test_multi_block_directory()
|
|||
res = fs.mkdir("cactus", 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
for (int i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "cactus/test%d", i);
|
||||
res = fs.mkdir((char*)buffer, 0777);
|
||||
sprintf((char *)buffer, "cactus/test%d", i);
|
||||
res = fs.mkdir((char *)buffer, 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
res = fs.unmount();
|
||||
|
@ -326,10 +326,10 @@ void test_multi_block_directory()
|
|||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_DIR, res);
|
||||
for (int i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "test%d", i);
|
||||
sprintf((char *)buffer, "test%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
res = dir[0].read(&ent);
|
||||
|
|
|
@ -167,7 +167,7 @@ void test_small_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ void test_medium_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ void test_large_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
|
|
@ -113,13 +113,13 @@ void test_parallel_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
res = file[0].write((const void*)"a", 1);
|
||||
res = file[0].write((const void *)"a", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[1].write((const void*)"b", 1);
|
||||
res = file[1].write((const void *)"b", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[2].write((const void*)"c", 1);
|
||||
res = file[2].write((const void *)"c", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[3].write((const void*)"d", 1);
|
||||
res = file[3].write((const void *)"d", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ void test_parallel_remove_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = file[0].write((const void*)"e", 1);
|
||||
res = file[0].write((const void *)"e", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
res = fs.remove("a");
|
||||
|
@ -238,7 +238,7 @@ void test_parallel_remove_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = file[0].write((const void*)"e", 1);
|
||||
res = file[0].write((const void *)"e", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
@ -303,22 +303,22 @@ void test_remove_inconveniently_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = file[0].write((const void*)"e", 1);
|
||||
res = file[0].write((const void *)"e", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[1].write((const void*)"f", 1);
|
||||
res = file[1].write((const void *)"f", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[2].write((const void*)"g", 1);
|
||||
res = file[2].write((const void *)"g", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
res = fs.remove("f");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = file[0].write((const void*)"e", 1);
|
||||
res = file[0].write((const void *)"e", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[1].write((const void*)"f", 1);
|
||||
res = file[1].write((const void *)"f", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[2].write((const void*)"g", 1);
|
||||
res = file[2].write((const void *)"g", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
|
|
@ -94,8 +94,8 @@ void test_seek_tests()
|
|||
res = fs.mkdir("hello", 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
for (int i = 0; i < 132; i++) {
|
||||
sprintf((char*)buffer, "hello/kitty%d", i);
|
||||
res = file[0].open(&fs, (char*)buffer,
|
||||
sprintf((char *)buffer, "hello/kitty%d", i);
|
||||
res = file[0].open(&fs, (char *)buffer,
|
||||
O_WRONLY | O_CREAT | O_APPEND);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -137,10 +137,10 @@ void test_simple_dir_seek()
|
|||
off_t pos;
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
pos = dir[0].tell();
|
||||
}
|
||||
|
@ -148,14 +148,14 @@ void test_simple_dir_seek()
|
|||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
dir[0].rewind();
|
||||
sprintf((char*)buffer, "kitty%d", 0);
|
||||
sprintf((char *)buffer, "kitty%d", 0);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, ".");
|
||||
|
@ -166,14 +166,14 @@ void test_simple_dir_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -207,10 +207,10 @@ void test_large_dir_seek()
|
|||
off_t pos;
|
||||
int i;
|
||||
for (i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
pos = dir[0].tell();
|
||||
}
|
||||
|
@ -218,14 +218,14 @@ void test_large_dir_seek()
|
|||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
dir[0].rewind();
|
||||
sprintf((char*)buffer, "kitty%d", 0);
|
||||
sprintf((char *)buffer, "kitty%d", 0);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, ".");
|
||||
|
@ -236,14 +236,14 @@ void test_large_dir_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -580,26 +580,26 @@ void test_out_of_bounds_seek()
|
|||
|
||||
size = strlen("kittycatcat");
|
||||
res = file[0].size();
|
||||
TEST_ASSERT_EQUAL(132*size, res);
|
||||
res = file[0].seek((132+4)*size,
|
||||
TEST_ASSERT_EQUAL(132 * size, res);
|
||||
res = file[0].seek((132 + 4) * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL((132+4)*size, res);
|
||||
TEST_ASSERT_EQUAL((132 + 4)*size, res);
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
memcpy(buffer, "porcupineee", size);
|
||||
res = file[0].write(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = file[0].seek((132+4)*size,
|
||||
res = file[0].seek((132 + 4) * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL((132+4)*size, res);
|
||||
TEST_ASSERT_EQUAL((132 + 4)*size, res);
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "porcupineee", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].seek(132*size,
|
||||
res = file[0].seek(132 * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(132*size, res);
|
||||
TEST_ASSERT_EQUAL(132 * size, res);
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "\0\0\0\0\0\0\0\0\0\0\0", size);
|
||||
|
|
|
@ -117,10 +117,10 @@ void test_bad_mount()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
{
|
||||
res = bd.erase(0, 2*bd.get_erase_size());
|
||||
res = bd.erase(0, 2 * bd.get_erase_size());
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
memset(buffer, 0, bd.get_program_size());
|
||||
for (int i = 0; i < 2*bd.get_erase_size(); i += bd.get_program_size()) {
|
||||
for (int i = 0; i < 2 * bd.get_erase_size(); i += bd.get_program_size()) {
|
||||
res = bd.program(buffer, i, bd.get_program_size());
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ void test_resilience()
|
|||
bd_size_t block_size = bd.get_erase_size();
|
||||
bd.deinit();
|
||||
|
||||
SlicingBlockDevice slice(&bd, 0, MBED_TEST_BLOCK_COUNT*block_size);
|
||||
SlicingBlockDevice slice(&bd, 0, MBED_TEST_BLOCK_COUNT * block_size);
|
||||
|
||||
// Setup the test
|
||||
setup_atomic_operations(&slice, true);
|
||||
|
|
|
@ -62,11 +62,11 @@ static uint32_t test_wear_leveling_size(uint32_t block_count)
|
|||
bd_size_t block_size = bd.get_erase_size();
|
||||
bd.deinit();
|
||||
|
||||
SlicingBlockDevice slice(&bd, 0, block_count*block_size);
|
||||
SlicingBlockDevice slice(&bd, 0, block_count * block_size);
|
||||
ExhaustibleBlockDevice ebd(&slice, MBED_TEST_ERASE_CYCLES);
|
||||
|
||||
printf("Testing size %llu bytes (%lux%llu) blocks\n",
|
||||
block_count*block_size, block_count, block_size);
|
||||
block_count * block_size, block_count, block_size);
|
||||
setup_atomic_operations(&ebd, true);
|
||||
|
||||
int64_t cycles = 0;
|
||||
|
|
|
@ -301,8 +301,8 @@ void test_multi_block_directory()
|
|||
res = mkdir("/fs/" "cactus", 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
for (int i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "/fs/" "cactus/test%d", i);
|
||||
res = mkdir((char*)buffer, 0777);
|
||||
sprintf((char *)buffer, "/fs/" "cactus/test%d", i);
|
||||
res = mkdir((char *)buffer, 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
res = fs.unmount();
|
||||
|
@ -327,10 +327,10 @@ void test_multi_block_directory()
|
|||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_DIR, res);
|
||||
for (int i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "test%d", i);
|
||||
sprintf((char *)buffer, "test%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
|
|
|
@ -167,7 +167,7 @@ void test_small_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ void test_medium_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ void test_large_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
|
|
@ -113,13 +113,13 @@ void test_parallel_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
res = fwrite((const void*)"a", 1, 1, fd[0]);
|
||||
res = fwrite((const void *)"a", 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"b", 1, 1, fd[1]);
|
||||
res = fwrite((const void *)"b", 1, 1, fd[1]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"c", 1, 1, fd[2]);
|
||||
res = fwrite((const void *)"c", 1, 1, fd[2]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"d", 1, 1, fd[3]);
|
||||
res = fwrite((const void *)"d", 1, 1, fd[3]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ void test_parallel_remove_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = fwrite((const void*)"e", 1, 1, fd[0]);
|
||||
res = fwrite((const void *)"e", 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
res = remove("/fs/" "a");
|
||||
|
@ -238,7 +238,7 @@ void test_parallel_remove_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = fwrite((const void*)"e", 1, 1, fd[0]);
|
||||
res = fwrite((const void *)"e", 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
@ -303,22 +303,22 @@ void test_remove_inconveniently_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = fwrite((const void*)"e", 1, 1, fd[0]);
|
||||
res = fwrite((const void *)"e", 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"f", 1, 1, fd[1]);
|
||||
res = fwrite((const void *)"f", 1, 1, fd[1]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"g", 1, 1, fd[2]);
|
||||
res = fwrite((const void *)"g", 1, 1, fd[2]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
res = remove("/fs/" "f");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = fwrite((const void*)"e", 1, 1, fd[0]);
|
||||
res = fwrite((const void *)"e", 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"f", 1, 1, fd[1]);
|
||||
res = fwrite((const void *)"f", 1, 1, fd[1]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"g", 1, 1, fd[2]);
|
||||
res = fwrite((const void *)"g", 1, 1, fd[2]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
|
|
@ -94,8 +94,8 @@ void test_seek_tests()
|
|||
res = mkdir("/fs/" "hello", 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
for (int i = 0; i < 132; i++) {
|
||||
sprintf((char*)buffer, "/fs/" "hello/kitty%d", i);
|
||||
res = !((fd[0] = fopen((char*)buffer,
|
||||
sprintf((char *)buffer, "/fs/" "hello/kitty%d", i);
|
||||
res = !((fd[0] = fopen((char *)buffer,
|
||||
"ab")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -137,10 +137,10 @@ void test_simple_dir_seek()
|
|||
off_t pos;
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
pos = telldir(dd[0]);
|
||||
}
|
||||
|
@ -148,14 +148,14 @@ void test_simple_dir_seek()
|
|||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
seekdir(dd[0], pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
rewinddir(dd[0]);
|
||||
sprintf((char*)buffer, "kitty%d", 0);
|
||||
sprintf((char *)buffer, "kitty%d", 0);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, ".");
|
||||
|
@ -166,14 +166,14 @@ void test_simple_dir_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
seekdir(dd[0], pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = closedir(dd[0]);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -207,10 +207,10 @@ void test_large_dir_seek()
|
|||
off_t pos;
|
||||
int i;
|
||||
for (i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
pos = telldir(dd[0]);
|
||||
}
|
||||
|
@ -218,14 +218,14 @@ void test_large_dir_seek()
|
|||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
seekdir(dd[0], pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
rewinddir(dd[0]);
|
||||
sprintf((char*)buffer, "kitty%d", 0);
|
||||
sprintf((char *)buffer, "kitty%d", 0);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, ".");
|
||||
|
@ -236,14 +236,14 @@ void test_large_dir_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
seekdir(dd[0], pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = closedir(dd[0]);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -578,8 +578,8 @@ void test_out_of_bounds_seek()
|
|||
res = fseek(fd[0], 0, SEEK_END);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ftell(fd[0]);
|
||||
TEST_ASSERT_EQUAL(132*size, res);
|
||||
res = fseek(fd[0], (132+4)*size,
|
||||
TEST_ASSERT_EQUAL(132 * size, res);
|
||||
res = fseek(fd[0], (132 + 4) * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fread(buffer, 1, size, fd[0]);
|
||||
|
@ -588,14 +588,14 @@ void test_out_of_bounds_seek()
|
|||
memcpy(buffer, "porcupineee", size);
|
||||
res = fwrite(buffer, 1, size, fd[0]);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = fseek(fd[0], (132+4)*size,
|
||||
res = fseek(fd[0], (132 + 4) * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fread(buffer, 1, size, fd[0]);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "porcupineee", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fseek(fd[0], 132*size,
|
||||
res = fseek(fd[0], 132 * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fread(buffer, 1, size, fd[0]);
|
||||
|
|
Loading…
Reference in New Issue