littlefs-project / littlefs

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

Tags with id == 0x3ff #930

Closed andriyndev closed 5 months ago

andriyndev commented 5 months ago

Id (10-bits) - File id associated with the tag. Each file in a metadata block gets a unique id which is used to associate tags with that file. The special value 0x3ff is used for any tags that are not associated with a file, such as directory and global metadata.

Do I understand correctly that all the directories have tag id = 0x3ff, or only some folders?

geky commented 5 months ago

Ah, I can see where this would be confusing. That last sentence could probably be made clearer.

The tricky bit is that directories have two relationships with the mdirs:

  1. Directories exist as files in their parent's mdir. These mdir entries have the type LFS_TYPE_DIR, but otherwise are mostly the same as regular files. These have normal ids 0x0-0x3fe based on their location in the mdir.

  2. The contents of a directory is stored as a linked-list of mdirs. This linked-list may contain its own metadata unrelated to any files in the mdirs. These entries use the special id 0x3ff to indicate they aren't normal files. Currently this is limited to the pointers that construct the linked-list, LFS_TYPE_TAIL, and global metadata, LFS_TYPE_GLOBALS.

andriyndev commented 5 months ago

Thank you!