littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
5.25k stars 803 forks source link

Parsing order in a folder #1024

Open tototrix23 opened 2 months ago

tototrix23 commented 2 months ago

Hi everyone,

It's not an issue but a question. When you create hundred of files in a folder and you want to parse it: what is the parsing order ? The oldest created file to the newest ? Is it true all the time ?

Best regards.

geky commented 2 months ago

Hi @tototrix23, thanks for creating an issue.

The order lfs_dir_read returns files is a bit weird. It's almost alphabetical, but with larger file names being returned first.

Originally the ordering was intended to be strictly alphabetical, but a bug in the comparison logic went unnoticed. Backwards compatible with existing disks makes this difficult to change without a minor/major on-disk version bump. More info here: https://github.com/littlefs-project/littlefs/issues/923.

Still, this ordering can be useful if you want to intentionally order files with same-sized filenames.