Current implementation of dosfs in libstand reads full File Allocation Table to the RAM in the initialization code. In the extreme case of FAT32 filesystem, this structure will take up to 256-1024 Mb of loader memory, depending on the cluster size.
Proposed patch reduces libstands/dosfs memory requirements to 128 Kb for all variants of dosfs filesystem. For FAT12 and FAT16 filesystems, File Allocation Table is cached in full, as before. For FAT32, File Allocation Table is broken into the equal blocks of 128 Kilobytes (32768 entries), and only current block is cached.
In my measurements, I could not find any performance degradation caused by this patch. FAT32 cache misses occur with ~ 1/10000 probability, so this patch doesn't hurt performance much, but allows to save significant amount of memory in the loader environment. Additionally, loader time is saved by avoiding loading of non-relevant 128K-blocks from the File Allocation Table on disk.
Because per-filesystem context is now small, global FAT cache (for all instances of dosfs filesystem) is replaced by local per-instance cache.