Getting Accurate Disk Sizes in Windows 2000

Hello,

To get the disk size, I am using geometry of the disk and calculating the
size
in terms of blocks as -

DiskSize = diskGeometry.Cylinders.QuadPart *
diskGeometry.TracksPerCylinder *
diskGeometry.SectorsPerTrack *
diskGeometry.BytesPerSector

I am not using “diskGeometry.BytesPerSector” in my calculations, as I want
to
express diskSize in terms of blocks.

BUt however this disk size mismatches with the size given by Dmdiag - Disk
Manager Diagnostics tool.
(http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/dmdiag-
o.asp)

Following are the exact figures that I am getting.

[partial output by executing dmdiag.exe - Only relevent portion from the
output
is kept here]


PhysicalDrive1 \Device\Harddisk1\DR1 (Signature 73728248) Dynamic Disk (LDM)

\Device\Harddisk1\DR1 (Device)
\Device\Harddisk1\Partition0 (SymbolicLink) -> \Device\Harddisk1\DR1

---------- ldmsize 1 ----------
469 Cylinders
255 Tracks/Cylinder
63 Sectors/Track
512 Bytes/Sector
12 MediaType
7,534,485 Sectors (total)
3,857,656,320 Bytes (total)
3,767,243 KB
3,679 MB
3.6 GB

0 StartingOffset
3,860,398,080 PartitionLength
0 HiddenSectors
0 PartitionNumber
0 PartitionType
0 BootIndicator
0 RecognizedPartition
0 RewritePartition

4 PartitionCount
73728248 Signature

[snip]

3,857,656,320 Bytes ( 7534485 sectors) Geometric size
3,860,398,080 Bytes ( 7539840 sectors) True size (measured)
3,860,398,080 Bytes ( 7539840 sectors) Reported size (Partition0)
0 Bytes ( 0 sectors) missing/wasted



Now I am able to get the disk size as 7534485 sectors, but not 7539840
sectors.
Which APIs might have been used to get this size. My wild guess is that the
difference in the size (~1.60 MB) has to do something with the LBA
(linear/logical blocks addressing organization of the disk).

I have tried so far-

  1. GetDiskFreeSpaceEx - this function cannot be used for any harddisk, it is
    intended to be used for volumes/partitions/directories etc.
  2. Using IOCTL_DISK_GET_PARTITION_INFO, oe can get all the partitions for a
    required disk, say PhysicalDrive0, but one thing to be noticed is that
    the
    documentation says that, PartitionNumber i.e. Number of the partition are
    (1-based). And here we want information about Partition0
  3. Using IOCTL_DISK_GET_DRIVE_GEOMETRY_EX on Windows 2000, which directly
    gives
    the DiskSize, but it is giving me some incorrect function.

Could anybody help me out in clearing my confusion about why there is
differece
between the disk Sizes, and what exactly is TRUE size, and reported Size,
how MS
guys get it in dmdiag tool?

thanks in advance,
Pankaj