Looking at some of LittleFS's support underlying the routines for writing directories to a microcontroller's harddrive...
There's several for extracting certain bits from an attributes "tag", or handling endianness.
There's a couple more helpers for (recursively or not) gathering all entries in a directory, which invokes a further surprisingly simple helper for detect cycles via Brent's Algorithm. In turn invoking an equality helper. The recursive variant uses an explicit stack.
1/?
Furthermore the recursive variant invokes a callback for each entry, & invokes the cached-wrapper around the harddrive-read method itself. In this case its callback lightly wraps `lfs_dir_commitattr()` (also called directly from the relocating-commit routine) which reformats a tag & defers on to `lfs_dir_commitprog()` at least twice, or follows up the first call with repeated reads of data to commit. Then adds a CRC.
This carefully & repeatedly writes data into the Program-cache flushing it.
2