nexos wrote:
If you dump the values of the BPB via your OS, what does it say for sectors per cluster?
The BPB has a value of 512 for the bytes per sector field.
crosssans wrote:
bloodline wrote:
Ok weird question... But what does the "sectors per cluster" field in the volume boot record actually tell me?
The "sectors per cluster" indicates the number of
logical sectors (and not physical, as some tools may actually specify something higher than the physical number of bytes per sector on the media, see below!) used by one cluster on the data portion of the FAT filesystem.
bloodline wrote:
Have now made a new HD 80Meg image for use with GRUB2, and MacOS Disk utility automatically formatted it FAT16... I decided to leave it as FAT16 to test my FAT FS driver. But this has a value of 4 in the Sectors per cluster field, now my cluster to LBA conversion function seems wrong as I am calculating 2048 bytes per cluster (512 * 4), but when I look at the HD image file in a Hex viewer, it's clear there are 8192 bytes per cluster (16 sectors per cluster!)... I'm hugely confused by this.
And that's where the "Bytes per logical sector" field comes into play: I guess that your disk utility probably set this to 2048 bytes instead of 512 - and that's where your cluster to LBA conversion fails, because you're assuming that a disk will always have logical sectors that are 512 bytes
There is a really good article on Wikipedia that has a section where all fields of the FAT's BPB are described:
https://en.wikipedia.org/wiki/Design_of ... eter_BlockAt the bottom of these tables, there are two formulas that will help you fix your conversion function
Yes, haven't hard coded any values, the 512 comes directly from the BPB... thanks for the link though, I was trying to find that at lunch today! I'll have a play before bed.
Am I correct that with FAT16 the Root occupies the second cluster of the data area? or does the data area start after the root directory?