Repository navigation
Description
Summary
Filesystem code is spread across four unrelated parts of the tree with no directory that names the subsystem. Proposal: consolidate under src/fl/fs/**.
This surfaced while adding a second storage backend (#3984 / #4007). Nothing about that work was hard; deciding where each file goes was, repeatedly — which is the symptom worth acting on.
Where filesystem code lives today
| Concern | Location |
|---|---|
Public API + FsImpl interface |
fl/system/file_system.{h,cpp.hpp} |
| SD backend | fl/system/sd/ |
| Embedded-flash backend | fl/system/embedded_fs/ (new) |
filebuf — the file handle every backend implements |
fl/stl/detail/file_handle.h |
ifstream / filebuf_ptr |
fl/stl/fstream.h |
Asset resolution (.lnk, FL_ASSET) |
fl/asset/ |
| Platform backends | platforms/stub/fs_stub.hpp, platforms/wasm/fs_wasm.*, platforms/arm/teensy/sdfat/**, platforms/esp/fs/ |
| Unity TUs | fl/build/fl.system+.cpp, fl.system.sd+.cpp, fl.system.embedded_fs+.cpp, fl.asset+.cpp |
fl/stl/ is the odd one. filebuf is the abstraction every backend subclasses — it is the filesystem's core type, sitting in the standard-library-shims directory because it is spelled like std::filebuf. Anyone tracing how a backend works has to leave the filesystem code entirely to find its base class.
fl/system/ is a grab bag by construction: delay.h, pin.h, heap.h, serial.h, yield.h, timeout.h, engine_events.h and the filesystem all share it. A subsystem with three subdirectories, four translation units, and platform fragments in five places has outgrown a shared folder.
Proposed
src/fl/fs/
fs.h public API (FileSystem, FsImpl, factories)
fs.cpp.hpp
file_handle.h filebuf — moved from fl/stl/detail/
fstream.h ifstream — moved from fl/stl/
sd/ SD backend
embedded/ on-chip flash backend
asset/ .lnk resolution, FL_ASSET (or left in fl/asset/)
with src/fl/build/fl.fs*.cpp for the translation units and platform fragments staying under src/platforms/**, reached through a dispatch header exactly as they are now.
Why now
Two related issues are already open against the current shape, and both get easier with a home for the subsystem:
- audit: fl/system/file_system.h has drifted from the API Object Pattern #4003 —
file_system.hhas drifted from the API Object Pattern: it carries an inlineloadJpegFromSD()body, re-exportsvideo.handjpeg.hto every consumer, and has no matching implementation directory. Rule 1 of that pattern is "one header, one directory, same name" —fs.h+fs/satisfies it directly, wherefile_system.h+fl/system/never can. - design: expose on-chip flash storage generically, not as make_littlefs_filesystem #4007 — keeping platform vocabulary out of the public API. A dedicated directory makes the boundary obvious: everything in
fl/fs/is generic, everything platform-specific is behind a dispatch header.
Doing this before more backends land is cheaper than after. RP2040 LittleFS and any FatFS work would otherwise each repeat the "where does this go?" decision.
Constraints any restructure must preserve
- Per-backend translation units.
fl.system.sd+.cppexists so the linker drops the SD chain (~16 KB on ESP32-S3) whenbeginSd()is never called — Meta: ESP32-S3 binary-size reduction — Batch 1 (~26 KB) + Batch 2 (~26–50 KB) (supersedes #2771) #2773 item 1.2.fl.system.embedded_fs+.cppdoes the same for flash. Renaming is fine; merging them is not. - The entry point must share a TU with its backend. Splitting them puts the backend in
platforms+.cpp, which every sketch links, and the tree-shaking silently stops working. #include "fl/system/file_system.h"must keep working, or this becomes a breaking change for every sketch that opens a file. A forwarding header is the obvious answer; the deprecation timeline is a separate decision.
Open questions
fl/fs/vsfl/filesystem/—fs.his terse and matchesfl/stl/,fl/fx/,fl/ui/;filesystem.his unambiguous. Note the existing comment at the top offile_system.h: "fs.h breaks ESPAsyncWebServer so we use file_system.h instead" — worth checking whether afl/fs/fs.hpath collides the same way before committing to the name.- Does
fl/asset/move in, or stay adjacent? It is a consumer of the filesystem, not part of it. - Should
filebuf/ifstreammove, given they are deliberatelystd-shaped and live with the other shims? - Big-bang move plus forwarding headers, or incremental with both paths live?
Related
- audit: fl/system/file_system.h has drifted from the API Object Pattern #4003 —
file_system.hAPI Object Pattern audit - design: expose on-chip flash storage generically, not as make_littlefs_filesystem #4007 — generic vs platform-specific naming in the public API
- feat: add a LittleFS FsImpl backend — on-chip flash storage is unreachable today #3984 — embedded-flash backend
- meta: remote assets — hosting, build-time resolution, and on-device filesystem deployment #3986 — meta
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Aug 23, 2026
Open question 1 resolved —
fl/fs/fs.his safeThe concern was the comment atop
file_system.h: "fs.h breaks ESPAsyncWebServer so we use file_system.h instead." That collision cannot recur atfl/fs/fs.h, and the tooling that guarantees it is already in place — nothing needs adding.IncludePathsChecker(ci/lint_cpp_rs/src/checkers/basic.rs) enforces src-root-relative includes on two fronts:Relative paths are rejected outright (
lint_core/path_helpers.rs:77):Every other include must resolve from
src/(basic.rs:460-465):The second is what closes this. A bare
#include "fs.h"is not a relative path, so rule 1 misses it — but rule 2 catches it, because it would have to resolve tosrc/fs.h, which will not exist. The only spelling that compiles is#include "fl/fs/fs.h".The external-library case is closed by construction: ESPAsyncWebServer's
#include <fs.h>looks for a barefs.h, which FastLED would not have at a shadowing location. The original breakage came from a header reachable asfs.h; one atfl/fs/fs.his not.Verified state of the tree: the only relative includes under
src/are seven lines in the vendoredplatforms/arm/teensy/sdfat/**tree, each carrying an explicit// ok include path; // ok relative include - imported SdFat layoutsuppression. There are no unsuppressed violations, so the convention is enforced in practice rather than merely documented.No build-system change is required. I checked whether the build files needed to restrict include paths and they do not — the lint layer covers it more precisely than an include-path change could, because it also rejects the bare-filename form that a compiler would otherwise resolve happily from the including file's own directory.
Naming decision:
fl/fs/fs.h.zackees commentedon Aug 23, 2026
Proposed
fl/fs/fs.h— concrete draftResolving open questions 2 and 3 by showing the shape rather than describing it. Not implemented; posting for review before anyone moves files.
Directory
Answers to the open questions
Q1 naming — settled as
fl/fs/fs.h. See the comment above; the include checker makes the bare-fs.hcollision impossible.Q2 does
fl/asset/move in? No. It is a consumer of the filesystem — it resolves.lnkfiles andFL_ASSETpaths by reading throughFileSystem. Same relationship as the codecs, and they are staying out too.Q3 do
filebuf/ifstreammove? Yes.filebufis the base class every backend subclasses — it is the filesystem's core type, sitting infl/stl/detail/only because it is spelled likestd::filebuf. Tracing a backend today means leaving the filesystem code to find its own base class.Q4 big-bang or incremental? Incremental.
fl/system/file_system.hbecomes a forwarding header that includesfl/fs/fs.handfl/fs/read.h, so existing sketches keep compiling unchanged. The format helpers stay as deprecatedFileSystemmembers forwarding to the free functions until a major version drops them.Cost
The include-graph win is the measurable part:
file_system.hcurrently re-exportsfl/fx/video.handfl/codec/jpeg.h, so every sketch that opens a file compiles both. Worth measuring on a small target before and after — that number should decide how hard to push on this.refactor(fs): move read.h bodies out of line
refactor(fs): finish the API Object Pattern items from #4003
refactor(fs): consolidate the filesystem subsystem under fl/fs/ (#4010)