mbed-os/features/filesystem/littlefs
Christopher Haster 2cf4715cb6 littlefs: Increased test timeout to 4 minutes
Unfortunately there are several issues colluding to force the timeout
this high.

1. The tests push littlefs to the limits of how many errors it can
handle before failing. As a side effect this causes a massive amount
of debug/warn/error logging about the situation.

2. The logging can't be turned off for specific tests. Note: This might
change with the introduction of test-configs.

3. Logging is fixed to a baud rate of 9600. Previous testing was carried
out with a baud rate of 115200, which is the reason for the original
timeout.
2017-11-22 17:19:16 -06:00
..
TESTS littlefs: Increased test timeout to 4 minutes 2017-11-22 17:19:16 -06:00
TESTS_COMMON littlefs: Moved test block devices into general block devices 2017-11-22 16:02:54 -06:00
littlefs Add 'features/filesystem/littlefs/' from commit 'd02b3122f006aa201bca4efc699bae40971e5a00' 2017-11-22 16:02:21 -06:00
.mbedignore Add 'features/filesystem/littlefs/' from commit 'd02b3122f006aa201bca4efc699bae40971e5a00' 2017-11-22 16:02:21 -06:00
.travis.yml Add 'features/filesystem/littlefs/' from commit 'd02b3122f006aa201bca4efc699bae40971e5a00' 2017-11-22 16:02:21 -06:00
LICENSE.md Add 'features/filesystem/littlefs/' from commit 'd02b3122f006aa201bca4efc699bae40971e5a00' 2017-11-22 16:02:21 -06:00
LittleFileSystem.cpp Add 'features/filesystem/littlefs/' from commit 'd02b3122f006aa201bca4efc699bae40971e5a00' 2017-11-22 16:02:21 -06:00
LittleFileSystem.h littlefs: Removed mbed namespace leaks 2017-11-22 16:02:54 -06:00
README.md Add 'features/filesystem/littlefs/' from commit 'd02b3122f006aa201bca4efc699bae40971e5a00' 2017-11-22 16:02:21 -06:00
mbed_lib.json Add 'features/filesystem/littlefs/' from commit 'd02b3122f006aa201bca4efc699bae40971e5a00' 2017-11-22 16:02:21 -06:00

README.md

mbed wrapper for the little filesystem

This is the mbed wrapper for littlefs, a little fail-safe filesystem designed for embedded systems.

   | | |     .---._____
  .-----.   |          |
--|o    |---| littlefs |
--|     |---|          |
  '-----'   '----------'
   | | |

Bounded RAM/ROM - The littlefs is designed to work with a limited amount of memory. Recursion is avoided and dynamic memory is limited to configurable buffers that can be provided statically.

Power-loss resilient - The littlefs is designed for systems that may have random power failures. The littlefs has strong copy-on-write guaruntees and storage on disk is always kept in a valid state.

Wear leveling - Since the most common form of embedded storage is erodible flash memories, littlefs provides a form of dynamic wear leveling for systems that can not fit a full flash translation layer.

Usage

If you are already using a filesystem in mbed, adopting the littlefs should just require a name change to use the LittleFileSystem class.

Here is a simple example that updates a file named "boot_count" every time the application runs:

#include "LittleFileSystem.h"
#include "SPIFBlockDevice.h"

// Physical block device, can be any device that supports the BlockDevice API
SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5);

// Storage for the littlefs
LittleFileSystem fs("fs");

// Entry point
int main() {
    // Mount the filesystem
    int err = fs.mount(&bd);
    if (err) {
        // Reformat if we can't mount the filesystem,
        // this should only happen on the first boot
        LittleFileSystem::format(&bd);
        fs.mount(&bd);
    }

    // Read the boot count
    uint32_t boot_count = 0;
    FILE *f = fopen("/fs/boot_count", "r+");
    if (!f) {
        // Create the file if it doesn't exist
        f = fopen("/fs/boot_count", "w+");
    }
    fread(&boot_count, sizeof(boot_count), 1, f);

    // Update the boot count
    boot_count += 1;
    rewind(f);
    fwrite(&boot_count, sizeof(boot_count), 1, f);

    // Remember that storage may not be updated until the file
    // is closed successfully
    fclose(f);

    // Release any resources we were using
    fs.unmount();

    // Print the boot count
    printf("boot_count: %ld\n", boot_count);
}

Reference material

DESIGN.md - DESIGN.md contains a fully detailed dive into how littlefs actually works. I would encourage you to read it since the solutions and tradeoffs at work here are quite interesting.

SPEC.md - SPEC.md contains the on-disk specification of littlefs with all the nitty-gritty details. Can be useful for developing tooling.

littlefs - Where the core of littlefs currently lives.

littlefs-fuse - A FUSE wrapper for littlefs. The project allows you to mount littlefs directly in a Linux machine. Can be useful for debugging littlefs if you have an SD card handy.

littlefs-js - A javascript wrapper for littlefs. I'm not sure why you would want this, but it is handy for demos. You can see it in action here.