#include <windows.h>
#include <winioctl.h>
#include <stdio.h>

BOOL GetDriveGeometry(DISK_GEOMETRY *pdg)
{

 HANDLE hDevice;
 BOOL bResult;
 DWORD junk; //line 10

 hDevice = CreateFile("\\\\.\\PhysicalDrive0", 
                      0,
                      FILE_SHARE_READ |
                      FILE_SHARE_WRITE
                      NULL,
                      OPEN_EXISTING,
                      0,
                      NULL);
//line 20
 if (hDevice == INVALID_HANDLE_VALUE)
 {
  return (FALSE);
 }

 bResult = DeviceIoControl(hDevice,
                           IOCTL_DISK_GET_DRIVE_GEOMETRY,
                           NULL,
                           0,
                           pdg, //line 30
                           sizeOf(*pdg),
                           &junk,
                           (LPOVERLAPPED) NULL);

closeHandle(hDevice);

return(bResult);
}

//line 40
int main(int argc, char *argv[])
{

 DISK_GEOMETRY pdg;
 BOOL bResult;
 ULONGLONG DiskSize;

 bResult = getDriveGeometry (&pdg);

 if (bResult)  //line 50
 {
  printf("Cylinders = %I64d\n", pdg.Cylinders);
  printf("Tracks = %ld\n", (ULONG) pdg.TracksPerCylinder);
  printf("Sectors/Track = %ld\n", pdg.SectorsPerTrack);
  printf("Bytes/Sector = %ld\n", pdg.BytesPerSector);
  
  DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
             (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;

  printf("Disk Size = %I64d (Bytes) = %I64d (GB)\n", DiskSize, DiskSize / (1024 * 1024 * 1024) );
 }
 else
 {
  printf("Get Drive Geometry Failed. Error %ld.\n", GetLastError ()x);
 }

 return ((int)bResult);
}
