How to get the size of a physical disk?
-
I would like to know the way to get the size of physical disks (hard disks).
When I use IOCTL_DISK_GET_DRIVE_GEOMETRY, it tells me the size of \\.\physicaldisk0 is 33814126080 bytes = 32247 MB
But actually it is a Maxtor 57GB hard disk, also WIndows Disk Management Tool tells me the size is 55.91 GB.
Could anyone teach me a correct way to get the size of physical disks?
Thanks. BuggyMax -
I would like to know the way to get the size of physical disks (hard disks).
When I use IOCTL_DISK_GET_DRIVE_GEOMETRY, it tells me the size of \\.\physicaldisk0 is 33814126080 bytes = 32247 MB
But actually it is a Maxtor 57GB hard disk, also WIndows Disk Management Tool tells me the size is 55.91 GB.
Could anyone teach me a correct way to get the size of physical disks?
Thanks. BuggyMaxDoes this help??? :confused::confused: LPCTSTR lpDirectoryName; // directory name ULARGE_INTEGER lpFreeBytesAvailable; // bytes available to caller ULARGE_INTEGER lpTotalNumberOfBytes; // bytes on disk ULARGE_INTEGER lpTotalNumberOfFreeBytes; // free bytes on disk lpDirectoryName = "c:"; lpFreeBytesAvailable.QuadPart = 0; lpTotalNumberOfBytes.QuadPart = 0; lpTotalNumberOfFreeBytes.QuadPart = 0; FARPROC pGetDiskFreeSpaceEx; pGetDiskFreeSpaceEx = GetProcAddress( GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA"); if (pGetDiskFreeSpaceEx) { GetDiskFreeSpaceEx (lpDirectoryName, (PULARGE_INTEGER)&lpFreeBytesAvailable, (PULARGE_INTEGER)&lpTotalNumberOfBytes, (PULARGE_INTEGER)&lpTotalNumberOfFreeBytes); } else { AfxMessageBox(_T("Error")); }
-
I would like to know the way to get the size of physical disks (hard disks).
When I use IOCTL_DISK_GET_DRIVE_GEOMETRY, it tells me the size of \\.\physicaldisk0 is 33814126080 bytes = 32247 MB
But actually it is a Maxtor 57GB hard disk, also WIndows Disk Management Tool tells me the size is 55.91 GB.
Could anyone teach me a correct way to get the size of physical disks?
Thanks. BuggyMaxBuggyMax wrote: physicaldisk0 is 33814126080 byte How do you get that ? You should multiply : bytes per sector * sectors per track * track per cylinder * cylinders to get your size. If this does not work, maybe use IOCTL_DISK_GET_DRIVE_LAYOUT to get the partitions and IOCTL_DISK_GET_PARTITION_INFO to retrieve the sizes. ~RaGE();
-
I would like to know the way to get the size of physical disks (hard disks).
When I use IOCTL_DISK_GET_DRIVE_GEOMETRY, it tells me the size of \\.\physicaldisk0 is 33814126080 bytes = 32247 MB
But actually it is a Maxtor 57GB hard disk, also WIndows Disk Management Tool tells me the size is 55.91 GB.
Could anyone teach me a correct way to get the size of physical disks?
Thanks. BuggyMaxThis correctly reports that I have a (roughly) 13GB disk:
HANDLE disk;
DWORD dwNeeded;
DISK_GEOMETRY *geometry;disk=CreateFile("\\\\.\\PHYSICALDRIVE0",
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (INVALID_HANDLE_VALUE != disk)
{
geometry = new DISK_GEOMETRY;DeviceIoControl(disk, IOCTL\_DISK\_GET\_DRIVE\_GEOMETRY, NULL, 0, geometry, sizeof(DISK\_GEOMETRY), &dwNeeded, NULL); TRACE(" Cylinders: %I64u\\n", geometry->Cylinders); TRACE(" Media Type: %d\\n", geometry->MediaType); TRACE("Tracks/Cylinder: %lu\\n", geometry->TracksPerCylinder); TRACE(" Sectors/Track: %lu\\n", geometry->SectorsPerTrack); TRACE(" Bytes/Sector: %lu\\n", geometry->BytesPerSector); delete \[\] geometry; CloseHandle(disk);
}
-
Does this help??? :confused::confused: LPCTSTR lpDirectoryName; // directory name ULARGE_INTEGER lpFreeBytesAvailable; // bytes available to caller ULARGE_INTEGER lpTotalNumberOfBytes; // bytes on disk ULARGE_INTEGER lpTotalNumberOfFreeBytes; // free bytes on disk lpDirectoryName = "c:"; lpFreeBytesAvailable.QuadPart = 0; lpTotalNumberOfBytes.QuadPart = 0; lpTotalNumberOfFreeBytes.QuadPart = 0; FARPROC pGetDiskFreeSpaceEx; pGetDiskFreeSpaceEx = GetProcAddress( GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA"); if (pGetDiskFreeSpaceEx) { GetDiskFreeSpaceEx (lpDirectoryName, (PULARGE_INTEGER)&lpFreeBytesAvailable, (PULARGE_INTEGER)&lpTotalNumberOfBytes, (PULARGE_INTEGER)&lpTotalNumberOfFreeBytes); } else { AfxMessageBox(_T("Error")); }
Xander80 wrote: lpDirectoryName = "c:"; Thanks but "C:" is logical drive. What I need is size of physical disks. Thanks. BuggyMax
-
BuggyMax wrote: physicaldisk0 is 33814126080 byte How do you get that ? You should multiply : bytes per sector * sectors per track * track per cylinder * cylinders to get your size. If this does not work, maybe use IOCTL_DISK_GET_DRIVE_LAYOUT to get the partitions and IOCTL_DISK_GET_PARTITION_INFO to retrieve the sizes. ~RaGE();
Rage wrote: You should multiply : bytes per sector * sectors per track * track per cylinder * cylinders to get your size. Yes that huge number (33814126080) is the result of multiplying the four values. Rage wrote: If this does not work, maybe use IOCTL_DISK_GET_DRIVE_LAYOUT to get the partitions and IOCTL_DISK_GET_PARTITION_INFO to retrieve the sizes. What if the disk contains NO partitions? ;) BuggyMax
-
This correctly reports that I have a (roughly) 13GB disk:
HANDLE disk;
DWORD dwNeeded;
DISK_GEOMETRY *geometry;disk=CreateFile("\\\\.\\PHYSICALDRIVE0",
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (INVALID_HANDLE_VALUE != disk)
{
geometry = new DISK_GEOMETRY;DeviceIoControl(disk, IOCTL\_DISK\_GET\_DRIVE\_GEOMETRY, NULL, 0, geometry, sizeof(DISK\_GEOMETRY), &dwNeeded, NULL); TRACE(" Cylinders: %I64u\\n", geometry->Cylinders); TRACE(" Media Type: %d\\n", geometry->MediaType); TRACE("Tracks/Cylinder: %lu\\n", geometry->TracksPerCylinder); TRACE(" Sectors/Track: %lu\\n", geometry->SectorsPerTrack); TRACE(" Bytes/Sector: %lu\\n", geometry->BytesPerSector); delete \[\] geometry; CloseHandle(disk);
}
That source code was also what I used. But the values I got were: Cylinders: 4111 ( I use __int64 already.) TracksPerCylinder: 255 SectorsPerTrack: 63 BytesPerSector: 512 The result, as you see, is 33GB. But actually it is a 55.9GB one. It means amount of cylinders should be 6964. BuggyMax