Skip to content

design: expose on-chip flash storage generically, not as make_littlefs_filesystem #4007

Closed

Description

@zackees

Summary

FsImplPtr make_littlefs_filesystem(bool) (proposed in #4006) names a technology in FastLED's public API. It should name the concept instead, with LittleFS demoted to a platform detail under src/platforms/.

This is a narrower and more actionable point than the general audit in #4003: the public filesystem API may grow for convenience, but it must not leak platform vocabulary.

Why the current shape is wrong

Every platform inherits the vocabulary. Once make_littlefs_filesystem() is public, the host stub, WASM, Teensy, and AVR all live in a world where "LittleFS" is a concept they must have an opinion about. platforms/stub/fs_stub.hpp maps filesystem calls to a real directory on the developer's disk — asking it to answer "do you support LittleFS?" is meaningless. The honest answer for the stub is "I have somewhere to put files," which is the concept, not the technology.

LittleFS is not even the only answer on the platforms that have it. ESP32 can back on-chip flash with LittleFS, SPIFFS (legacy), or FatFS. RP2040 uses LittleFS. Teensy 4.x uses LittleFS_Program with genuinely different semantics (program flash, wiped on re-upload). Pinning the public name to one of those choices means the API is wrong for its siblings and blocks changing the default later.

It breaks the symmetry the API already has. make_sdcard_filesystem(int cs_pin) names a medium (an SD card) and takes a property of the medium (the chip-select pin) — not make_sdfat_filesystem() or make_arduino_sd_filesystem(). The SD entry point is already technology-neutral; the flash one should match.

Proposed shape

Public API — one generic factory, no platform words:

// On-chip flash storage. The platform picks the implementation:
// LittleFS on ESP32/ESP8266/RP2040, LittleFS_Program on Teensy 4.x,
// a scratch directory on host/stub. Returns null where the platform has
// no such storage, so callers get a clean begin() failure.
FsImplPtr make_flash_filesystem(bool format_on_fail = false) FL_NO_EXCEPT;

Name is up for discussion — make_flash_filesystem, make_internal_filesystem, make_onboard_filesystem. The requirement is only that it describes where the bytes live, not which filesystem driver puts them there. "Flash" describes the medium, parallel to "sdcard".

Platform detail — LittleFS moves under src/platforms/:

src/platforms/esp/32/fs/fs_littlefs_esp32.{h,cpp.hpp}     LittleFS on ESP32
src/platforms/.../fs_littlefs_rp2040.{h,cpp.hpp}          later
src/platforms/stub/fs_stub.hpp                            already maps to a real dir

with a dispatcher TU selecting among them, exactly as fl/system/sd/file_system_sd.cpp.hpp already does for SD (FASTLED_TESTING → stub, FL_IS_WASM → browser VFS, FL_IS_TEENSY → SdFat, else Arduino SD). That file is the working exemplar for this pattern.

Constraint to preserve: the separate translation unit. fl.system.sd+.cpp exists so the linker drops the SD chain (~16 KB on ESP32-S3) when beginSd() is never called — #2773 item 1.2. The flash filesystem needs the same treatment; do not fold it into fl.system+.cpp.

Questions this issue should settle

  1. The name. flash / internal / onboard, and whether it reads right beside make_sdcard_filesystem.
  2. Is format_on_fail the right generic parameter? It is meaningful on ESP32, absent on ESP8266/RP2040 (no such hook), and arguably dangerous on Teensy where re-upload wipes storage anyway. It may belong in a small options struct rather than the signature, or not be exposed at all.
  3. Should the stub implement it? Mapping it to a scratch directory would let host tests exercise real read paths instead of only the null-fallback contract. That is a genuine testability win and the strongest argument for the generic name.
  4. Free factory or FileSystem::beginFlash()? audit: fl/system/file_system.h has drifted from the API Object Pattern #4003 argues against growing the class per backend; a generic concept is a better candidate for a member than a technology was. Worth deciding once rather than per-backend.
  5. Does Teensy's LittleFS_Program belong behind this name at all, given it is wiped on every upload? Possibly yes with a documented caveat, possibly a separate concept.

Related

Activity

  1. zackees commented on Sep 8, 2026

    @zackees
    MemberAuthor

    This looks satisfied on current master by the merged #4006. Checking each requirement in the proposal against the tree rather than assuming:

    1. Public API names the medium, not the driver. src/fl/fs/embedded/embedded_fs.h:49:

    FsImplPtr getEmbeddedFs(bool format_on_fail = false) FL_NO_EXCEPT;

    Structurally identical to the proposed make_flash_filesystem(bool format_on_fail = false) — same parameter, same default, medium-named. The issue said "Name is up for discussion ... The requirement is only that it describes where the bytes live", and getEmbeddedFs does.

    2. No driver name reaches the public API. littlefs appears in five headers under src/fl/, but every occurrence is a comment explaining the platform detail, not an identifier. src/fl/fs/backend.h:17 is explicit about it:

    /// `getLittleFs`, see #4007), and hand it to `FileSystem::begin()`.
    

    and embedded_fs.h:8-9:

    /// the platform's: LittleFS on ESP32 and ESP8266, and other backends as
    /// they are added. A sketch never says "LittleFS", the same way it never
    

    3. LittleFS demoted to src/platforms/. The backends live at platforms/esp/fs/embedded_fs_esp.hpp and platforms/wasm/fs/embedded_fs_wasm.hpp, dispatched from platforms/embedded_fs.h. Nothing named *littlefs* exists anywhere under src/platforms/.

    4. Symmetry with the SD entry point. src/fl/fs/fs.h:44 adds getSdFs(int cs_pin) alongside the original make_sdcard_filesystem, with a comment citing this issue: "Preferred spelling: it names the medium, matching getEmbeddedFs() for on-chip flash, so every backend reads the same way and no driver name reaches the public API (FastLED #4007)." That is the sdcard/flash parallel the issue asked for.

    5. Null where the platform has no such storage. The proposal said "Returns null where the platform has no such storage, so callers get a clean begin() failure." platforms/embedded_fs.h:35 sends everything outside ESP32/ESP8266/WASM to platforms/shared/embedded_fs_noop.hpp, whose makeEmbeddedFs() returns a default-constructed FsImplPtr().

    RP-specific note, since this issue is tagged for RP2040/RP2350. The proposal lists "RP2040 uses LittleFS" among the platforms, but there is no RP backend — RP takes the #else branch and gets the noop. So RP2350W/RP2040 currently return null from getEmbeddedFs() and callers get the clean begin() failure the design intends, rather than on-chip flash storage. That is correct behaviour under this design, but it means an RP LittleFS backend is still unimplemented work if on-chip storage is wanted there. Worth tracking separately rather than leaving implied by this issue's platform list.

    Suggest this can close as completed by #4006, with the RP backend split out if it is still wanted.

  2. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Question 3 answered with code, not by omission (#4270)

    Your triage above checks the design point by point and I agree with all of it. The one thing it does not cover is the issue's own third question, which #4006 settled by default rather than by decision:

    Should the stub implement it? Mapping it to a scratch directory would let host tests exercise real read paths instead of only the null-fallback contract. That is a genuine testability win and the strongest argument for the generic name.

    It is, so #4270 does it. Before it, the only host coverage of embedded storage was the no-op fragment — a real contract, and one tests/fl/fs/embedded/embedded_fs.cpp does test, but one that exercises none of the read path a sketch runs.

    Two constraints kept it from disturbing anything:

    • Opt-in, and null until asked. getEmbeddedFs() returns null on the host exactly as the no-op fragment does until a test calls setTestEmbeddedFileSystemRoot(). The four existing cases keep testing the null fallback and keep meaning what they meant. There is now a case pinning that as well, because if pointing the host at a directory ever became the default those cases would silently stop testing it.
    • A separate root from the SD stub. On a device these are two media, so a test that wrote to on-chip flash and read it back off a card must not pass. Sharing setTestFileSystemRoot's directory would make such a test green here and red on hardware, so the roots are independent and a case asserts a file under one is not visible through the other.

    The fragment takes the shape platforms/embedded_fs.h documents — a plain header composed into fl.fs.embedded+.cpp, dropped with the entry point when a sketch never asks — gated on FL_IS_STUB && FASTLED_TESTING, which cannot reach a device build.

    On closing

    I have not touched the RP gap you flagged: RP2040/RP2350 still take the no-op branch and return null. Correct under this design, and unimplemented work rather than a defect — worth the separate issue you suggested.

    Questions 1, 2, 4 and 5 in the body are settled by the shipped shape (getEmbeddedFs, format_on_fail retained, free factory, Teensy not backed). With question 3 now answered in code, this issue looks complete apart from the RP split-out.

  3. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Verified against current master, and closing

    Re-checked each of the issue's four requirements against the tree rather than carrying the earlier triage forward, plus the third open question that #4270 answered.

    requirement evidence on master
    public API names the medium, not the driver src/fl/fs/embedded/embedded_fs.h:49 — FsImplPtr getEmbeddedFs(bool format_on_fail = false)
    no driver name reaches the public API a grep for littlefs/LittleFS across src/fl/**/*.h,*.hpp outside comments returns nothing
    LittleFS demoted to src/platforms/ find src/platforms -iname "*littlefs*" returns nothing; the backends are platforms/esp/fs/embedded_fs_esp.hpp and platforms/wasm/fs/embedded_fs_wasm.hpp
    symmetry with the SD entry point src/fl/fs/fs.h:36 — make_sdcard_filesystem(int cs_pin), with the neighbouring comment citing this issue
    "should the stub implement it?" yes, and it does — fl::setTestEmbeddedFileSystemRoot in src/fl/fs/testing.h:35, backed by platforms/stub/fs/embedded_fs_stub.hpp, opt-in and null until asked

    Nothing here is outstanding. Closing.

  4. moved this from Triage to Done in FastLED Trackeron Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions