The FAT contains two unusable entries at the beginning that do not represent
data, so those shouldn’t be counted when determining the number of data sectors.
Keeping track of the offset depends on the order in which entries are written,
i.e. breaks as soon as you have multiple nested directories.
Calculating the offset is shorter and more robust.
related to https://github.com/gokrazy/internal/issues/6
When writing directory entries, we now allocate the FAT entries
before writing, so that we can synthesize the . and .. entries
which need FirstCluster and parent.FirstCluster to be set.
This code currently assumes each directory consumes only 1 cluster
(space for 64 directory entries, I think).
Before this commit, the special first two entries (media descriptor copy, file
system state) were only written out in writeFAT.
For the edge case where the two entries are what pushes the FAT from one sector
to the next, this resulted in incorrect fatSectors calculation.
This is in preparation for adding Raspberry Pi 3 B+ support, for which we’ll
need to let the firmware locate the DTB file under file names such as
bcm2710-rpi-3-b-plus.dtb.
Note that short names are not upper-cased currently (the standard says they
should, but neither the firmware nor the linux kernel care) so that upgrades
from older gokrazy installations work. In a year or so, we can change this.