How can I get the exact size of the hard disk in bytes on the old Windows 2000?
IOCTL_DISK_GET_LENGTH_INFO works fine for volumes, but not on physical disk handles (stuff at //./PHYSICALDISKx) on Windows 2000. (Works fine for physical drives from XP or later)
We still have to support this ancient OS...
UPDATE:
The code is written in C, so I would use plain Windows API if possible.
It seems there is no IOCTL that give you the exact hard drive size on Windows 2000.
But there is a workaround, that worked:
I used IOCTL_DISK_GET_DRIVE_GEOMETRY to get cylinders, tracks/cyl, sectors/track, bytes/sector.
Multiplying them gave me a rough size of the HDD but not the exact size (little smaller). I can calculate the almost last sector id from this.
To get the exact size I used IOCTL_SCSI_PASS_THROUGH and sent SCSI read commands to attempt to read beyond the end of disk, so I had a sector number for a non-existing sector, then used binary search to get highest sector id where the read succeeds.
Multiplying it with the bytes/sector, I have the exact size of hard disk in bytes.