littlefs
v2.11.2Features
-
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 (55)
LittleDB: SQL-like Database for ESP32
A lightweight SQL-like database library designed for ESP32 microcontrollers. It utilizes the LittleFS file system to manage data storage on embedded flash memory, providing a familiar query interface for creating databases, tables, and performing CRUD operations.
littlefs Disk Image Viewer
A web-based utility for browsing littlefs disk images using WebAssembly. It provides a memory-efficient way to inspect filesystem contents by emulating a block device directly in the browser, specifically targeting the littlefs filesystem used in embedded systems.
littlefs2: Idiomatic Rust API for littlefs
A high-level, idiomatic Rust wrapper for the littlefs microcontroller filesystem. It provides a no_std compatible interface for embedded systems, supporting features like inline files, custom attributes, and dynamic wear-leveling while following the patterns of Rust's standard filesystem API.
FS_Nano33BLE
A filesystem wrapper library for Arduino MBED nRF52840-based boards, providing a simplified interface for LittleFS and FATFS on internal flash memory. It supports power-fail safety and high-performance data storage for devices like the Nano 33 BLE and Seeeduino XIAO nRF52840.
Golioth Firmware SDK
A comprehensive software development kit for connecting embedded devices to the Golioth IoT cloud. It provides robust middleware for OTA updates, data streaming, remote logging, and device management across platforms like Zephyr, ESP-IDF, and ModusToolbox.
IMXRT1060-EVK Sample Project
A comprehensive sample project for the NXP i.MX RT1060 Evaluation Kit (EVK) featuring a dual-stage architecture with a dedicated bootloader and a feature-rich application. It integrates Amazon FreeRTOS with a full middleware stack including lwIP networking, LVGL graphics, and FatFs storage for ARM Cortex-M7 development.
James Rocket Controller
Firmware for a Raspberry Pi Pico-based rocket controller designed for the Czech Rocket Challenge. It features automated parachute deployment via free-fall detection using an ADXL345 accelerometer, data logging to flash memory using Littlefs, and audible/visual status feedback.
ESP_DoubleResetDetector Library
A specialized Arduino library for ESP32 and ESP8266 microcontrollers designed to detect double-reset events. It enables developers to trigger specific actions, like opening a configuration portal or clearing settings, by detecting two consecutive resets within a defined time window using various storage backends.
esp-fs-webserver
A comprehensive Arduino library for ESP32 and ESP8266 that simplifies the implementation of web servers with integrated file management, WiFi configuration, and OTA updates. It enables hosting web assets directly from flash memory and includes a built-in code editor for runtime UI adjustments.
ESP8266_ENC_Manager
A connection and credentials manager for ESP8266 boards using ENC28J60 Ethernet modules. It provides a fallback web configuration portal for runtime setup of static or DHCP IP addresses, DNS servers, and NTP settings, utilizing the LwIP stack and Arduino framework.
ESP8266 LittleFS File Handler
A lightweight C++ library for ESP8266 microcontrollers designed to simplify JSON configuration management and file system operations using LittleFS. It provides a POSIX-like interface for file handling and integrates with ArduinoJSON for robust data persistence.
ESP8266_W5500_Manager
A connection and credentials manager for ESP8266 boards using the W5500 Ethernet controller. It provides a web-based configuration portal for setting static or DHCP IP addresses, DNS servers, and custom parameters at runtime, with support for LittleFS and SPIFFS.
ESPChat
A captive portal chat application for the ESP32 microcontroller that stores messages on the device's internal flash. It functions as a standalone WiFi access point, serving a web interface to connected clients for local communication without requiring an internet connection.
LittleFS for ESP-IDF
A high-performance, fail-safe filesystem port for ESP32 microcontrollers using the ESP-IDF framework. It serves as a robust alternative to SPIFFS and FAT, offering better reliability, faster formatting, and efficient wear leveling for embedded flash storage.
Arduino-Pico
A high-performance Arduino core for Raspberry Pi RP2040 and RP2350 microcontrollers, supporting both ARM and RISC-V architectures. It integrates the Raspberry Pi Pico SDK with FreeRTOS SMP support and provides advanced features like multicore processing, PIO-based peripherals, and integrated SSL/TLS.
AsyncESP32_SC_Ethernet_Manager
An asynchronous Ethernet connection manager for ESP32-S2/S3/C3 microcontrollers. It utilizes the LwIP stack with W5500 or ENC28J60 controllers to provide a web-based configuration portal for managing network credentials and static IP settings at runtime.
AsyncESP8266_ENC_Manager
A high-performance asynchronous connection and credentials manager for ESP8266 boards using the ENC28J60 Ethernet controller. It provides a fallback web configuration portal for runtime setup of DHCP/Static IP settings, hostnames, and custom application parameters stored in LittleFS or SPIFFS.
AsyncESP8266_W5100_Manager
An asynchronous Ethernet credentials and connection manager for ESP8266 boards using Wiznet W5100 or W5100S controllers. It provides a fallback web configuration portal for setting static or DHCP IP addresses, hostnames, and custom parameters at runtime using ESPAsyncWebServer.
AsyncESP8266_W5500_Manager
A comprehensive connection and credentials manager for ESP8266 boards equipped with W5500 Ethernet shields. It features an asynchronous web configuration portal for runtime network setup, supporting DHCP, static IP, and custom parameters stored via LittleFS or SPIFFS.
AsyncHTTPSRequest_Generic
A high-performance asynchronous HTTPS request library for ESP32 and ESP8266, enabling non-blocking REST communication. It supports a wide range of network interfaces including built-in WiFi and various Ethernet controllers like W5500, W6100, and ENC28J60.
Awesome Zephyr RTOS
A curated collection of high-quality resources, libraries, tools, and learning materials for the Zephyr RTOS ecosystem. It serves as a comprehensive directory for developers looking for official documentation, community-supported libraries, and hardware platforms compatible with Zephyr.
Bare Metal Programming Guide
A comprehensive educational resource for learning microcontroller programming from scratch using GCC and datasheets without high-level frameworks. It covers fundamental concepts like memory mapping, register manipulation, startup code, and peripheral drivers for various ARM Cortex-M and RISC-V architectures.
Blynk_Async_ESP32_BT_WF
An advanced ESP32 library that enables simultaneous or runtime-selectable Blynk connections via WiFi, Bluetooth, and BLE. It leverages asynchronous web servers for a non-blocking configuration portal and supports multi-credential management with storage in SPIFFS, LittleFS, or EEPROM.
Blynk_Async_GSM_Manager
A comprehensive library for ESP32 and ESP8266 that enables simultaneous WiFi and GSM/GPRS connections for Blynk applications. It features an asynchronous web-based configuration portal to manage credentials at runtime, eliminating the need for hardcoded network settings.
Blynk_Async_WM
An asynchronous WiFi and Blynk configuration manager for ESP8266 and ESP32 platforms. It leverages ESPAsyncWebServer to provide a non-blocking configuration portal with support for multi-WiFi/multi-Blynk credentials, SSL, and persistent storage via LittleFS, SPIFFS, or EEPROM.
Blynk_WiFiManager
A powerful WiFi and Blynk configuration library for ESP8266 and ESP32 that eliminates hardcoded credentials. It provides a web-based portal for runtime configuration of multiple WiFi APs and Blynk tokens, supporting SSL and various storage backends like LittleFS and SPIFFS.
Blynk_WiFiNINA_WM
A comprehensive WiFi configuration manager and Blynk connection library for a wide range of Arduino-compatible boards using WiFiNINA modules. It enables runtime credential configuration via a web portal, supports multiple WiFi networks, and integrates with storage solutions like LittleFS and EEPROM to eliminate hardcoded credentials.
Chronothermostat: An AWS-Powered IoT Climate Control System
A comprehensive IoT chronothermostat system utilizing ESP32 nodes and a Raspberry Pi 3 gateway integrated with Amazon Web Services. It features multi-room temperature and humidity monitoring, remote control via MQTT, and a web-based GUI for scheduling and statistics.
DoubleResetDetector_Generic
A comprehensive Arduino library for detecting double reset events across a vast array of hardware architectures including AVR, SAMD, STM32, nRF52, and RP2040. It enables developers to trigger alternative startup modes, such as configuration portals or factory resets, by simply pressing the reset button twice within a configurable timeout.
ESP32_BitlashTBP
A multi-interpreter environment for the ESP32-C3 that integrates Bitlash and TinyBasicPlus with Quick ESP-NOW wireless connectivity. It provides a programmable command shell and BASIC scripting capabilities with a LittleFS-based file system for persistent script storage.
esp32-cam-micropython
A specialized MicroPython port for the ESP32-CAM module that integrates camera support directly into the firmware. It features a custom C-based camera module, support for LittleFS to optimize RAM usage, and includes various asynchronous web server examples for streaming video and capturing images.
ESP32-targz
A comprehensive Arduino library for ESP32, ESP8266, and RP2040 that enables handling of .tar, .gz, and .tar.gz files. It supports compression, decompression, and streaming across various filesystems and network protocols, including specialized features for OTA firmware updates from compressed archives.
ESP32_W5500_Manager
A comprehensive connection and credential manager for ESP32 boards using the W5500 Ethernet controller and LwIP. It provides a fallback web configuration portal for runtime setup of static or DHCP IP addresses, custom parameters, and NTP settings, supporting storage via LittleFS or SPIFFS.
LittleFS_Mbed_RP2040 Library
A LittleFS wrapper designed for RP2040-based microcontrollers running the Arduino-mbed core. It provides a reliable, power-fail-safe filesystem for onboard flash storage, supporting POSIX and Mbed FileSystem APIs on boards like the Raspberry Pi Pico and Arduino Nano RP2040 Connect.