Today I'll study LittleFS's `lfs_format()` routine, and tomorrow I hope to study the rest. Glossing over any code that's shared. This `lfs_format()` routine, among other things, is only compiled if a compiletime flag indicates you're happy with a read-only filesystem.
The top-level routine intended to be invoked by external code possibly transiently (depending on macros) invokes a method to grab a lock & performs the core logic with possible logging both before & after (depending on macros).
1
That core routine invokes a shared helper to init the LittleFS filesystem, validates that there's a non-zero blockcount, zeroes out the lookahead buffer, updates the lookahead checkpoint property via another helper, invokes a helper to (via yet more helpers) allocate 2 harddrive blocks & read/update those allocated blocks, inits a superblock including (via a helper) a hardcoded or configured version number fixing (via helpers) endianness, writes to harddrive twice, & reads it.
2/4?