Skip to content

Commit

Permalink
Merge pull request #16 from ARMmbed/v2.2-alpha
Browse files Browse the repository at this point in the history
Bring in v2.2
  • Loading branch information
geky committed Apr 3, 2020
2 parents 19da65b + c9a6b88 commit 70aa179
Show file tree
Hide file tree
Showing 59 changed files with 14,957 additions and 5,792 deletions.
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ script:

# Run littlefs functional tests with different configurations
# Note: r/w size of 64 is default in mbed
- make -Clittlefs test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=64 -DLFS_PROG_SIZE=64"
- make -Clittlefs test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=1 -DLFS_PROG_SIZE=1"
- make -Clittlefs test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=512 -DLFS_PROG_SIZE=512"
- make -Clittlefs test QUIET=1 CFLAGS+="-DLFS_BLOCK_COUNT=1023"
- make -Clittlefs test QUIET=1 CFLAGS+="-DLFS_LOOKAHEAD=2048"
- make -Clittlefs test QUIET=1 CFLAGS+="-DLFS2_READ_SIZE=64 -DLFS2_CACHE_SIZE=64"
- make -Clittlefs test QUIET=1 CFLAGS+="-DLFS2_READ_SIZE=1 -DLFS2_CACHE_SIZE=1"
- make -Clittlefs test QUIET=1 CFLAGS+="-DLFS2_READ_SIZE=512 -DLFS2_CACHE_SIZE=512 -DLFS2_BLOCK_CYCLES=16"
- make -Clittlefs test QUIET=1 CFLAGS+="-DLFS2_READ_SIZE=8 -DLFS2_CACHE_SIZE=16 -DLFS2_BLOCK_CYCLES=2"
- make -Clittlefs test QUIET=1 CFLAGS+="-DLFS2_BLOCK_COUNT=1023 -DLFS2_LOOKAHEAD_SIZE=256"

install:
# Get arm-none-eabi-gcc
Expand All @@ -33,7 +33,8 @@ install:
- git clone https://github.com/armmbed/mbed-os.git
# Install python dependencies
- pip install -r mbed-os/requirements.txt
- sudo apt-get install python3 python3-pip
- sudo pip3 install toml
# Check versions
- arm-none-eabi-gcc --version
- python --version
- gcc --version
63 changes: 3 additions & 60 deletions LittleFileSystem2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ namespace mbed {

extern "C" uint32_t lfs2_crc(uint32_t crc, const void *buffer, size_t size)
{
uint32_t initial_xor = crc;
MbedCRC<POLY_32BIT_REV_ANSI, 32> ct(initial_xor, 0x0, true, false);
uint32_t initial_xor = lfs2_rbit(crc);
MbedCRC<POLY_32BIT_ANSI, 32, CrcMode::TABLE> ct(initial_xor, 0x0, true, true);

ct.compute((void *)buffer, size, &crc);
return crc;
}
Expand Down Expand Up @@ -166,12 +167,10 @@ LittleFileSystem2::~LittleFileSystem2()
int LittleFileSystem2::mount(BlockDevice *bd)
{
_mutex.lock();
LFS2_INFO("mount(%p)", bd);
_bd = bd;
int err = _bd->init();
if (err) {
_bd = NULL;
LFS2_INFO("mount -> %d", err);
_mutex.unlock();
return err;
}
Expand All @@ -192,20 +191,17 @@ int LittleFileSystem2::mount(BlockDevice *bd)
err = lfs2_mount(&_lfs, &_config);
if (err) {
_bd = NULL;
LFS2_INFO("mount -> %d", lfs2_toerror(err));
_mutex.unlock();
return lfs2_toerror(err);
}

_mutex.unlock();
LFS2_INFO("mount -> %d", 0);
return 0;
}

int LittleFileSystem2::unmount()
{
_mutex.lock();
LFS2_INFO("unmount(%s)", "");
int res = 0;
if (_bd) {
int err = lfs2_unmount(&_lfs);
Expand All @@ -221,7 +217,6 @@ int LittleFileSystem2::unmount()
_bd = NULL;
}

LFS2_INFO("unmount -> %d", res);
_mutex.unlock();
return res;
}
Expand All @@ -230,11 +225,8 @@ int LittleFileSystem2::format(BlockDevice *bd,
lfs2_size_t block_size, uint32_t block_cycles,
lfs2_size_t cache_size, lfs2_size_t lookahead_size)
{
LFS2_INFO("format(%p, %ld, %ld, %ld, %ld)",
bd, block_size, block_cycles, cache_size, lookahead_size);
int err = bd->init();
if (err) {
LFS2_INFO("format -> %d", err);
return err;
}

Expand All @@ -257,39 +249,33 @@ int LittleFileSystem2::format(BlockDevice *bd,

err = lfs2_format(&_lfs, &_config);
if (err) {
LFS2_INFO("format -> %d", lfs2_toerror(err));
return lfs2_toerror(err);
}

err = bd->deinit();
if (err) {
LFS2_INFO("format -> %d", err);
return err;
}

LFS2_INFO("format -> %d", 0);
return 0;
}

int LittleFileSystem2::reformat(BlockDevice *bd)
{
_mutex.lock();
LFS2_INFO("reformat(%p)", bd);
if (_bd) {
if (!bd) {
bd = _bd;
}

int err = unmount();
if (err) {
LFS2_INFO("reformat -> %d", err);
_mutex.unlock();
return err;
}
}

if (!bd) {
LFS2_INFO("reformat -> %d", -ENODEV);
_mutex.unlock();
return -ENODEV;
}
Expand All @@ -300,49 +286,40 @@ int LittleFileSystem2::reformat(BlockDevice *bd)
_config.cache_size,
_config.lookahead_size);
if (err) {
LFS2_INFO("reformat -> %d", err);
_mutex.unlock();
return err;
}

err = mount(bd);
if (err) {
LFS2_INFO("reformat -> %d", err);
_mutex.unlock();
return err;
}

LFS2_INFO("reformat -> %d", 0);
_mutex.unlock();
return 0;
}

int LittleFileSystem2::remove(const char *filename)
{
_mutex.lock();
LFS2_INFO("remove(\"%s\")", filename);
int err = lfs2_remove(&_lfs, filename);
LFS2_INFO("remove -> %d", lfs2_toerror(err));
_mutex.unlock();
return lfs2_toerror(err);
}

int LittleFileSystem2::rename(const char *oldname, const char *newname)
{
_mutex.lock();
LFS2_INFO("rename(\"%s\", \"%s\")", oldname, newname);
int err = lfs2_rename(&_lfs, oldname, newname);
LFS2_INFO("rename -> %d", lfs2_toerror(err));
_mutex.unlock();
return lfs2_toerror(err);
}

int LittleFileSystem2::mkdir(const char *name, mode_t mode)
{
_mutex.lock();
LFS2_INFO("mkdir(\"%s\", 0x%lx)", name, mode);
int err = lfs2_mkdir(&_lfs, name);
LFS2_INFO("mkdir -> %d", lfs2_toerror(err));
_mutex.unlock();
return lfs2_toerror(err);
}
Expand All @@ -351,9 +328,7 @@ int LittleFileSystem2::stat(const char *name, struct stat *st)
{
struct lfs2_info info;
_mutex.lock();
LFS2_INFO("stat(\"%s\", %p)", name, st);
int err = lfs2_stat(&_lfs, name, &info);
LFS2_INFO("stat -> %d", lfs2_toerror(err));
_mutex.unlock();
st->st_size = info.size;
st->st_mode = lfs2_tomode(info.type);
Expand All @@ -366,9 +341,7 @@ int LittleFileSystem2::statvfs(const char *name, struct statvfs *st)

lfs2_ssize_t in_use = 0;
_mutex.lock();
LFS2_INFO("statvfs(\"%s\", %p)", name, st);
in_use = lfs2_fs_size(&_lfs);
LFS2_INFO("statvfs -> %d", lfs2_toerror(in_use));
_mutex.unlock();
if (in_use < 0) {
return in_use;
Expand All @@ -388,9 +361,7 @@ int LittleFileSystem2::file_open(fs_file_t *file, const char *path, int flags)
{
lfs2_file_t *f = new lfs2_file_t;
_mutex.lock();
LFS2_INFO("file_open(%p, \"%s\", 0x%x)", *file, path, flags);
int err = lfs2_file_open(&_lfs, f, path, lfs2_fromflags(flags));
LFS2_INFO("file_open -> %d", lfs2_toerror(err));
_mutex.unlock();
if (!err) {
*file = f;
Expand All @@ -404,9 +375,7 @@ int LittleFileSystem2::file_close(fs_file_t file)
{
lfs2_file_t *f = (lfs2_file_t *)file;
_mutex.lock();
LFS2_INFO("file_close(%p)", file);
int err = lfs2_file_close(&_lfs, f);
LFS2_INFO("file_close -> %d", lfs2_toerror(err));
_mutex.unlock();
delete f;
return lfs2_toerror(err);
Expand All @@ -416,9 +385,7 @@ ssize_t LittleFileSystem2::file_read(fs_file_t file, void *buffer, size_t len)
{
lfs2_file_t *f = (lfs2_file_t *)file;
_mutex.lock();
LFS2_INFO("file_read(%p, %p, %d)", file, buffer, len);
lfs2_ssize_t res = lfs2_file_read(&_lfs, f, buffer, len);
LFS2_INFO("file_read -> %d", lfs2_toerror(res));
_mutex.unlock();
return lfs2_toerror(res);
}
Expand All @@ -427,9 +394,7 @@ ssize_t LittleFileSystem2::file_write(fs_file_t file, const void *buffer, size_t
{
lfs2_file_t *f = (lfs2_file_t *)file;
_mutex.lock();
LFS2_INFO("file_write(%p, %p, %d)", file, buffer, len);
lfs2_ssize_t res = lfs2_file_write(&_lfs, f, buffer, len);
LFS2_INFO("file_write -> %d", lfs2_toerror(res));
_mutex.unlock();
return lfs2_toerror(res);
}
Expand All @@ -438,9 +403,7 @@ int LittleFileSystem2::file_sync(fs_file_t file)
{
lfs2_file_t *f = (lfs2_file_t *)file;
_mutex.lock();
LFS2_INFO("file_sync(%p)", file);
int err = lfs2_file_sync(&_lfs, f);
LFS2_INFO("file_sync -> %d", lfs2_toerror(err));
_mutex.unlock();
return lfs2_toerror(err);
}
Expand All @@ -449,9 +412,7 @@ off_t LittleFileSystem2::file_seek(fs_file_t file, off_t offset, int whence)
{
lfs2_file_t *f = (lfs2_file_t *)file;
_mutex.lock();
LFS2_INFO("file_seek(%p, %ld, %d)", file, offset, whence);
off_t res = lfs2_file_seek(&_lfs, f, offset, lfs2_fromwhence(whence));
LFS2_INFO("file_seek -> %d", lfs2_toerror(res));
_mutex.unlock();
return lfs2_toerror(res);
}
Expand All @@ -460,9 +421,7 @@ off_t LittleFileSystem2::file_tell(fs_file_t file)
{
lfs2_file_t *f = (lfs2_file_t *)file;
_mutex.lock();
LFS2_INFO("file_tell(%p)", file);
off_t res = lfs2_file_tell(&_lfs, f);
LFS2_INFO("file_tell -> %d", lfs2_toerror(res));
_mutex.unlock();
return lfs2_toerror(res);
}
Expand All @@ -471,9 +430,7 @@ off_t LittleFileSystem2::file_size(fs_file_t file)
{
lfs2_file_t *f = (lfs2_file_t *)file;
_mutex.lock();
LFS2_INFO("file_size(%p)", file);
off_t res = lfs2_file_size(&_lfs, f);
LFS2_INFO("file_size -> %d", lfs2_toerror(res));
_mutex.unlock();
return lfs2_toerror(res);
}
Expand All @@ -482,9 +439,7 @@ int LittleFileSystem2::file_truncate(fs_file_t file, off_t length)
{
lfs2_file_t *f = (lfs2_file_t *)file;
_mutex.lock();
LFS2_INFO("file_truncate(%p)", file);
int err = lfs2_file_truncate(&_lfs, f, length);
LFS2_INFO("file_truncate -> %d", lfs2_toerror(err));
_mutex.unlock();
return lfs2_toerror(err);
}
Expand All @@ -495,9 +450,7 @@ int LittleFileSystem2::dir_open(fs_dir_t *dir, const char *path)
{
lfs2_dir_t *d = new lfs2_dir_t;
_mutex.lock();
LFS2_INFO("dir_open(%p, \"%s\")", *dir, path);
int err = lfs2_dir_open(&_lfs, d, path);
LFS2_INFO("dir_open -> %d", lfs2_toerror(err));
_mutex.unlock();
if (!err) {
*dir = d;
Expand All @@ -511,9 +464,7 @@ int LittleFileSystem2::dir_close(fs_dir_t dir)
{
lfs2_dir_t *d = (lfs2_dir_t *)dir;
_mutex.lock();
LFS2_INFO("dir_close(%p)", dir);
int err = lfs2_dir_close(&_lfs, d);
LFS2_INFO("dir_close -> %d", lfs2_toerror(err));
_mutex.unlock();
delete d;
return lfs2_toerror(err);
Expand All @@ -524,9 +475,7 @@ ssize_t LittleFileSystem2::dir_read(fs_dir_t dir, struct dirent *ent)
lfs2_dir_t *d = (lfs2_dir_t *)dir;
struct lfs2_info info;
_mutex.lock();
LFS2_INFO("dir_read(%p, %p)", dir, ent);
int res = lfs2_dir_read(&_lfs, d, &info);
LFS2_INFO("dir_read -> %d", lfs2_toerror(res));
_mutex.unlock();
if (res == 1) {
ent->d_type = lfs2_totype(info.type);
Expand All @@ -539,19 +488,15 @@ void LittleFileSystem2::dir_seek(fs_dir_t dir, off_t offset)
{
lfs2_dir_t *d = (lfs2_dir_t *)dir;
_mutex.lock();
LFS2_INFO("dir_seek(%p, %ld)", dir, offset);
lfs2_dir_seek(&_lfs, d, offset);
LFS2_INFO("dir_seek -> %s", "void");
_mutex.unlock();
}

off_t LittleFileSystem2::dir_tell(fs_dir_t dir)
{
lfs2_dir_t *d = (lfs2_dir_t *)dir;
_mutex.lock();
LFS2_INFO("dir_tell(%p)", dir);
lfs2_soff_t res = lfs2_dir_tell(&_lfs, d);
LFS2_INFO("dir_tell -> %d", lfs2_toerror(res));
_mutex.unlock();
return lfs2_toerror(res);
}
Expand All @@ -560,9 +505,7 @@ void LittleFileSystem2::dir_rewind(fs_dir_t dir)
{
lfs2_dir_t *d = (lfs2_dir_t *)dir;
_mutex.lock();
LFS2_INFO("dir_rewind(%p)", dir);
lfs2_dir_rewind(&_lfs, d);
LFS2_INFO("dir_rewind -> %s", "void");
_mutex.unlock();
}

Expand Down
3 changes: 3 additions & 0 deletions littlefs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
blocks/
lfs2
test.c
tests/*.toml.*
scripts/__pycache__
.gdb_history
Loading

0 comments on commit 70aa179

Please sign in to comment.