I'm working on a low-level application which uses a FAT16 file system structure on a resource-constrained microcontroller which necessitates that I write my own custom access code. I've already looked into using libraries like Petit FAT and FatFS but unfortunately I don't think either of these will suite my needs. They have served as useful references for how FAT works, though.
The one area that I'm still having troubles with is sub-directory entries.
According to this, a directory entry is able to point to 1 start cluster. For a data file, this is simply the first data cluster. For a directory, this is the starting cluster of the sub-directory (presumably another directory entry).
This works fine if there's only 1 directory path from a root directory down to the base file, but I don't understand how this allows you to branch out to multiple files/directories underneath any given directory.
ex. directory structure:
- root dir 1
- sub dir 1
- file 1
- sub dir 2
- file 2
- root dir 2
- sub dir 3
Based on my understanding of the FAT16 structure,
Immediately following the FATs will be the cluster for the first root directory entry, containing information for root dir 1
. The first cluster field would then contain the cluster address for sub dir 1
, who's first cluster field would contain the cluster address for file 1
, who's first cluster points to a data cluster.
The second root directory entry would then start at the second cluster after then end of the FATs containing information for root dir 2
. Its first cluster would point to the cluster for sub dir 3
, who's first cluster would point to an empty cluster (as marked in the FATs).
What am I missing here? I can't figure out a way to navigate from a root directory entry down to sub dir 2
.