views:

84

answers:

1

We're using a small self-made windows-based tool to write OS, Images and a FAT partition containing data on SD cards that will then be used in embedded devices as boot medium and data storage.

I'm currently using IOCTL_DISK_GET_DRIVE_GEOMETRY to get the size of an SD card. However, due to the limitations of the CHS format it's not the real size of the SD card. This is not a big issue, since only a few sectors are wasted, however it would be nice to use all of the available space on the card.

Is there a better way to get the size of the drive? Remember, I'm not interested in the partition size. I need the total number of bytes (or sectors) that I can access on the SD card. Also, the drive might not be formated (correctly - my tool creates "too small" partitions) and formating it with windows first is not an option.

Fozi

A: 

You can try using IOCTL_DISK_GET_LENGTH_INFO. However, this IOCTL was added in Windows XP and later OSes.
http://msdn.microsoft.com/en-us/library/aa365178%28VS.85%29.aspx

swatkat
Thanks I'll try that. I can still fall back to the drive parameters if it fails.
Fozi
@swatkat: you can leave out the (VS.85) part of MSDN URLs.
MSalters