littlefs

v2.11.3
littlefs is a fail-safe filesystem specifically designed for microcontrollers with limited resources, featuring power-loss resilience and dynamic wear leveling. It employs a unique two-layer architecture combining metadata logs and copy-on-write structures to ensure data integrity and minimize flash wear while maintaining a strictly bounded memory footprint.

Features

  • 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 (194)

View All 194 Projects →
ESP32 CYD Aquarium

ESP32 CYD Aquarium

An autonomous virtual aquarium firmware designed for the ESP32-2432S028R 'Cheap Yellow Display'. It features a stylized dot-grid renderer, simulated aquatic life, and automatic backlight adjustment using onboard sensors.

freertos littlefstft-espi
HomeTiles

HomeTiles

HomeTiles is a tile-based firmware for ESP32-P4 touch displays designed to function as a highly configurable Home Assistant dashboard. It utilizes LVGL for its touch-first UI and FreeRTOS for task management, providing features like MQTT integration, web-based drag-and-drop configuration, and on-device OTA updates. The project targets high-performance hardware including the M5Stack Tab5 and various Waveshare MIPI-DSI displays.

freertos littlefslvgl
AI Desk Card

AI Desk Card

A secondary e-ink desk display designed for AI Agents like Claude Code and Codex, utilizing the M5Paper V1.1 hardware. The project features a Python-based daemon for server-side rendering and an ESP32 firmware that supports Wi-Fi, BLE, and USB communication.

freertos littlefslwipnimbleplatformio-platformio-core
Claude Pocket

Claude Pocket

Claude Pocket is a voice-activated AI assistant firmware for the M5Stack Cardputer ADV, powered by Anthropic's Claude and OpenAI's Whisper and TTS APIs. It features a custom C++ implementation that handles voice activity detection, streaming transcription, and real-time audio playback on hardware without external PSRAM.

freertos littlefsplatformio-platformio-core
Tossed The TV — Kept The Remote

Tossed The TV — Kept The Remote

An RP2040-based project that repurposes old infrared TV remotes into programmable USB HID devices like presentation clickers or custom keyboards. It utilizes the Arduino framework with TinyUSB for HID communication and LittleFS for storing button mappings in JSON format, configured via a Web Serial browser application.

littlefs
Plume — M5Cardputer ADV Edition

Plume — M5Cardputer ADV Edition

A passive RF scanner for the M5Cardputer ADV that detects Flock Safety ALPR cameras and Raven surveillance devices. It utilizes WiFi promiscuous mode and BLE scanning on the ESP32-S3, running entirely locally without cloud connectivity. Detections are logged to an SD card with GPS coordinates and signal strength visualizations.

freertos littlefsspiffsnimbleh2zero-esp-nimble-cpp
Astronomy Micro Station

Astronomy Micro Station

A standalone astronomy display for the LILYGO T-Display S3 Pro powered by an ESP32-S3. It tracks solar and lunar conditions using the ipgeolocation.io API, featuring a touch-enabled interface, LittleFS caching for offline use, and seamless Home Assistant integration via MQTT.

freertos littlefstft-espi
iMX RT1011 Nano Kit

iMX RT1011 Nano Kit

A high-performance development board featuring the NXP iMX RT1011 Crossover MCU with an ARM Cortex-M7 core running at 500MHz. It supports the Zephyr RTOS and Python environments, offering 128 KB RAM, 128 Mb QSPI Flash, and a compact USB-C form factor for rapid prototyping.

zephyr littlefslvglmicropython