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 (186)

View All 186 Projects →
DeskPet

DeskPet

DeskPet is a pixel-art companion for the M5Stack Cardputer that synchronizes with Claude Code sessions via Bluetooth Low Energy. Built on the ESP32-S3 using the Arduino framework and NimBLE, it provides real-time visual feedback on AI agent states, including task progress, token usage, and permission approvals directly from the device's keyboard.

freertos littlefsnimbleplatformio-platformio-core
Japi Base

Japi Base

Japi Base is a hackable retro computer platform for the Raspberry Pi Pico 2 (RP2350) that provides integrated VGA, PS/2 keyboard, SD storage, and audio capabilities. It utilizes a dual-core architecture where I/O management is isolated to one core and a single PIO block, leaving the second core and remaining peripherals entirely available for user applications. The system features a unified file API using littlefs for internal flash and FatFs for external SD cards.

littlefs

Ameba RTOS SDK

A comprehensive IoT development framework for Realtek Ameba series SoCs, providing a robust environment for building connected applications. It primarily leverages the FreeRTOS kernel and integrates essential networking stacks like lwIP, Wi-Fi, and Bluetooth. The SDK supports a wide range of Realtek chips, including the RTL8730E and RTL8721Dx, with tools for both CLI and VS Code-based development.

freertos lwiplittlefs
Tasmota SML Images

Tasmota SML Images

This project provides pre-compiled Tasmota firmware binaries specifically optimized for smart meter reading via SML and advanced scripting on ESP32 and ESP8266 platforms. It features a dual-track approach offering both the classic Tasmota Scripter and the high-performance TinyC VM, utilizing FreeRTOS for background processing and LittleFS for filesystem management. The firmware supports energy monitoring, Google Charts visualization, and emulation of smart battery interfaces like Shelly Pro 3EM.

freertos littlefslwiplvglplatformio-platformio-core
PaperSat

PaperSat

PaperSat is a standalone satellite tracking application for the M5Paper S3 e-ink tablet, providing real-time orbital predictions and polar sky plots. It utilizes SGP4 propagation for high-accuracy tracking and features an offline-first design with LittleFS for TLE data caching. The project is designed for amateur radio operators and observers, offering on-device configuration for location and time.

freertos littlefs
Z906 Remote

Z906 Remote

An ESP8266-based IoT solution for remote management of the Logitech Z906 5.1 surround sound system. It provides a web interface and MQTT integration for volume control, input switching, and status monitoring via the system's DE-15 console port.

littlefslwip
Pixel Pets

Pixel Pets

Pixel Pets is an open-source virtual pet ecosystem built for the M5Stack hardware family, featuring interactive digital companions with adaptive behaviors. It utilizes FreeRTOS for task management and the M5Unified library for hardware abstraction, supporting advanced features like ESP-NOW inter-device communication, offline LLM-based voice control, and real-time environment syncing. The project targets various ESP32 platforms including the CoreS3, Core2, and M5StickC PLUS2.

freertos littlefslwip
ESP32 Bit Pirate

ESP32 Bit Pirate

ESP32 Bit Pirate is an open-source firmware that transforms ESP32-S3 development boards into multi-protocol hardware hacking tools. It provides extensive support for digital protocols like I2C, SPI, and UART, as well as radio communications including Wi-Fi, Bluetooth, and Sub-GHz, utilizing FreeRTOS and LittleFS for robust device interaction.

freertos littlefslwipnimble