Hello everybody,
I want to calculate the free space of a SD-Card. The SD-Card is either formatted to FAT16 or
to FAT32.
The calculation is performed by a M16C uC which is connected via SPI to the card.
I have a little clue how to calculate but I don't know if my idea is high in performance.
My idea:
Reading following from parameters "Boot sector"
- Total sector (0x13/0x20)
- Sector per cluster (0x0d)
- Bytes per sector (0x0b)
Then calculating
Total sector / Sectors per cluster=> Total clusters
Then I look up the FAT and calculate how much clusters of total cluster are free
For example
free_cluster=0;
for(int i=0;i<total mode="hold" />{
if(FAT[i]==0)
free_cluster++;
}
Finally, I would calculate the size like this:
Size_of_cluster=Bytes per sector*Sector per cluster;
free_space=free_cluster * Size_of_cluster;
What do you think about my solution?
Is there any other way how to solve the problem?
How does Windows calculate this if I insert a SD-Card?
How would you solve it?
Thank you for helping