littlefs
v2.11.3Features
-
Power-loss resilience with strong copy-on-write guarantees for all file operations.
-
Dynamic wear leveling across flash blocks to extend storage lifespan.
-
Bad block detection and automatic workaround capabilities for NAND/NOR flash.
-
Strictly bounded RAM and ROM usage that remains constant regardless of filesystem size.
-
Elimination of unbounded recursion to prevent stack overflow in constrained environments.
-
Configurable, potentially static buffers to avoid dynamic memory allocation.
-
Full POSIX-like API for file and directory management.
-
Atomic POSIX operations including file removal and renaming.
-
Metadata stored in small logs called metadata pairs for efficient, low-latency updates.
-
File data stored in copy-on-write structures to prevent wear amplification.
-
C99 compliant source code for maximum portability across embedded compilers.
-
Support for multiple simultaneous filesystem instances via user-allocated state structures.
-
Data integrity verification through read-back checks during write operations.
-
Customizable block device interface for read, program, erase, and sync operations.
-
Support for custom error codes returned from underlying block device drivers.
-
Integrated test suite for PC/Linux environments using emulated block devices.
Architecture
littlefs is architected as a block-based filesystem utilizing a “two-layered cake” design to balance performance and reliability. The first layer consists of metadata pairs, which are small logs used to store directory information and file metadata. These logs allow for fast, frequent updates to metadata anywhere on the storage medium without requiring large-scale erases. The second layer uses larger copy-on-write (COW) structures to store actual file data, ensuring that data is stored compactly and that updates do not cause unnecessary wear amplification.
At the core of the system is a common block allocator that services both metadata and data structures. This allocator implements dynamic wear leveling by tracking and limiting the number of erases allowed on a block per allocation cycle. The system is designed to be entirely reentrant and supports multiple instances by requiring the user to provide the state storage (lfs_t) and configuration (lfs_config). This design ensures that RAM usage is strictly bounded and predictable, as the filesystem does not use recursion or unbounded dynamic memory allocation.
Use Cases
This library is ideal for:
- IoT Edge Devices: Systems requiring high reliability during unpredictable power cycles or battery failures.
- Data Logging: Applications that need to write data frequently to flash while maximizing the lifespan of the hardware through wear leveling.
- Embedded Firmware Storage: Storing system configurations and firmware images where corruption could lead to device bricking.
- Resource-Constrained MCUs: Microcontrollers with very limited RAM (e.g., <10KB) where a traditional filesystem would be too heavy.
- NAND/NOR Flash Management: Devices using raw flash chips that require manual bad block management and wear leveling.
Getting Started
To integrate littlefs, developers must first define a lfs_config structure that specifies the block device dimensions (read size, program size, block size, and count) and provides function pointers for the hardware-specific read, prog, erase, and sync operations. Once the configuration is defined, the filesystem can be initialized using lfs_mount. If the mount fails (common on first boot), lfs_format can be called to create a fresh filesystem.
Detailed API documentation is located within the lfs.h header file. For developers looking to port the library, the DESIGN.md and SPEC.md files in the repository provide deep dives into the on-disk format and architectural tradeoffs. Testing can be performed on a development PC using the provided emulated block device and the Python-based test runner found in the scripts directory.
Related Projects (152)
View All 152 Projects →PC-6001mkII Emulator for Raspberry Pi Pico
A comprehensive hardware emulator for the NEC PC-6001mkII and PC-6601 series running on the Raspberry Pi Pico. It utilizes custom PIO state machines for VGA and audio generation, supports LittleFS for storage, and offers high-fidelity sound emulation via the fmgen library.
midi2piousbhub
A versatile MIDI hub firmware for the Raspberry Pi Pico that interconnects USB MIDI hosts, serial MIDI devices, and USB MIDI controllers. It leverages the RP2040's PIO to implement a software USB host port and supports Bluetooth MIDI on the Pico W.
Seeed Studio XIAO ESP32 Project Collection
A comprehensive development resource for the Seeed Studio XIAO ESP32 family, including the C3, S3, and C6 modules. It provides over thirty modular projects demonstrating hardware-specific features like LiPo battery monitoring, deep sleep optimization, and advanced wireless implementations such as BLE HID keyboards and WebSocket camera servers.
InfiniEmu
InfiniEmu is a high-fidelity emulator for the PineTime smartwatch, simulating the nRF52832 SoC and its complete peripheral suite including I2C sensors and SPI displays. It enables developers to run production firmware like InfiniTime in both native desktop environments and web browsers using WebAssembly, featuring integrated support for FreeRTOS debugging and LittleFS storage.
pico-vfs: A Virtual File System for Raspberry Pi Pico
pico-vfs is a modular virtual file system designed for the Raspberry Pi Pico that provides a unified POSIX-compliant API for various storage media. It allows developers to mount multiple file systems, such as littlefs and FatFs, across physical storage like onboard flash and SD cards. The project streamlines embedded development by abstracting hardware differences and supporting standard C file operations.
SQLite for Raspberry Pi Pico
A port of the SQLite3 database engine for the Raspberry Pi Pico, enabling structured data storage on microcontrollers. It leverages littlefs for flash persistence and pico-vfs for flexible filesystem support, providing both a C/C++ library and an interactive shell.
Raspberry Pi Pico LittleFS USB Flash Memory Interface
This project implements a USB Mass Storage Class device for the Raspberry Pi Pico that exposes a LittleFS filesystem as a standard FAT12 volume. It allows users to read, write, and manage files stored on a microcontroller's flash memory from any PC without needing specialized software or drivers.
SQLite3 for ESP-IDF
A port of the SQLite3 relational database engine for ESP32 microcontrollers using the ESP-IDF framework. It supports ESP-IDF V5.x, offers specialized PSRAM memory management, and integrates with various filesystems including SPIFFS, LittleFS, and FATFS.