Total space on FAT16

Hi all,

I'm using CF storage (FAT16) in an embedded system, and i'm unable to retrieve the remaining free space value given by XP.

Windows XP say :

Used space : 51200 bytes. Free space : 16 283 848 bytes. Total space: 16 334 848 bytes.

Ok, so let's see at the partition record :

Bytes per sector : 512 Sectors per cluster : 4 Reserved sectors : 1 FATs : 2 Root dir entries : 512 Sectors on drive : 32004 Sectors per FAT : 32 Hidden sectors : 63

Respecting the partition record, the first cluster (dataSector) is located =E0 sector 152 :

FATsector =3D bootSector+ reservedSectors rootSector =3D FATsector + nbOfFAT*sectorsPerFAT dataSector =3D rootSector + (maxRootDir*32)/(bytesPerSecto=ADr)

The total free space available is [Bytes per sector]*{[Sectors on drive]-152 +1}, no ? Computing :

512*(32004-152+1) =3D 16 308 736 !!!

XP is missing 49 sectors !

Am i wrong ? Any ideas on how XP compute total space on disk ?

Reply to
nono240 at gmail dot com
Loading thread data ...

Well, it's hard to say precisely without seeing some more of the storage device in question but...

First, your XP free space number is wrong (for starters, it's not a multiple of the cluster size of 2048). Second, the free space is based on the number of clusters on the volume, not the number of sectors. Since you've got 32004 sectors, then you've got, by my count, 159 sectors (63 reserved, 2*32 per FAT, 32 root dir), not 152, which leaves

31845 data sectors, which has room for 7961 2K clusters (with one sector wasted). 7961*2048 (16304128) is what I'd expect Windows to report for the device capacity (total size).

That actually leaves a discrepancy of 30720 bytes or 60 sectors of extra capacity reported by Windows. I suspect that your reserved sector count is wrong (it's almost never anything but one for FAT12 or FAT16). Adding those extra 62 sectors would give you an additional 15 clusters (and increase the "wasted" sectors to three), which would explain the discrepancy neatly.

To then compute the actual free space, you need to count the number of clusters in the FAT marked as free (using the cluster count determined beforehand), and multiply by the cluster size.

Reply to
robertwessel2

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.