Why so much dead space in FAT32 ? - Page 1
Forum section: electronics / projects

author: Dan Moos
author_rank: Frequent Contributor
timestamp: April 03, 2022, 11:42:07 pm
content: I'm adding FAT 32 SD card support to my home brew computer, and I'm struck by the apparently wasted space on a FAT32 formatted SD card.Their are 8192 512 byte sectors until the first partition boot sector on the card I'm currently working with. after that there are 2420 "reserved sectors until the FAT itself.I realize that on an SD card with tens of gigs of space, this isn't that much, but it still seems wasteful.Why is it like this?

author: Berni
author_rank: Super Contributor
timestamp: April 04, 2022, 05:48:19 am
content: There are many ways to format a SD card. If you have a partition table with unused space in it, that might be the fault of the utility used to create the partition. Some filesystems also want to be in neat multiples of size so sometimes you also get some unused space on the end of the disk too.There are also some legacy reasons for keeping certain offsets to make sure it is compatible with old PCs. We unfortunately picked up a lot of legacy baggage with it so FAT32 is a pretty crappy filesystem these days. The exFAT is a modern version of it that fixes most of its flaws, but Microsoft is being bitchy about patents on that one too.

author: magic
author_rank: Super Contributor
timestamp: April 04, 2022, 06:00:29 am
content: Appendix C of the SD Filesystem Specification answers all your questions and then some you don't even know you have.Download it because it's a leaked pirate PDFhttps://dokumen.pub/sd-specifications-part-2-file-system-specification-version-300.htmlBTW, there are cameras that actually enforce this layout. If you plug a differently formatted card, they will complain and say it cannot be used for recording. I follow those guidelines when formatting SD cards for best performance and compatibility with equipment.

author: ejeffrey
author_rank: Super Contributor
timestamp: April 04, 2022, 06:09:58 am
content: The space before the partition boot record is nothing to do with the filesystem and everything to do with the tool that produced the MBR. There have been a number of weird factors that go into that. Extremely old tools would insist that every partition start on a cylinder boundary. Since MBR is the first sector of the first cylinder the rest of that cylinder would be empty. Obviously CHS addressing is long obsolete but LBA partitioning tools often set their own alignments. Modern systems also often want to align filesystems on larger allocation boundaries such as flash erase groups, or SMR groups. This can create weird gaps.I'm not sure whether the gap between the PBR and the first sector of the filesystem is a requirement of the filesystem or just chosen by the tool that created it, but I'd guess similar reasons apply

author: Gyro
author_rank: Super Contributor
timestamp: April 04, 2022, 09:27:41 am
content: This is probably a naive suggestion, but hopefully you're aware of the SD Association card formatter. Presumably this formats cards optimally...https://www.sdcard.org/downloads/formatter/

author: fchk
author_rank: Frequent Contributor
timestamp: April 04, 2022, 11:28:35 am
content: Quote from: Dan Moos on April 03, 2022, 11:42:07 pmThe default logical block size is 512 byte. The underlying physical block sizes for writing and erasing of the underlying flash memory however are much larger, 4k up to 128k. In order to get the best performance and the least amound of wear partitions should start on a physical block boundary. The reserved space ensures this even for quite big ease blocks.In the early days the first partition would start at C0 H1 S1, which translates to LBA 63. This is an odd address and caused a huge performance loss when hard disks with internal 4k sectors came out, and it is even worse for SSDs.fchk