}
#endif
+
+void Usage(void)
+{
+ puts("Usage: partinfo <drive number>");
+}
+
+
int main (int argc, char *argv[])
{
HANDLE hDisk;
char *Buffer;
DRIVE_LAYOUT_INFORMATION *LayoutBuffer;
DISK_GEOMETRY DiskGeometry;
+ ULONG ulDrive;
+ CHAR DriveName[40];
+ SYSTEM_DEVICE_INFORMATION DeviceInfo;
+ NTSTATUS Status;
- hDisk = CreateFile("\\\\.\\PHYSICALDRIVE0",
+ if (argc != 2)
+ {
+ Usage();
+ return(0);
+ }
+
+ ulDrive = strtoul(argv[1], NULL, 10);
+ if (errno != 0)
+ {
+ printf("Error: Malformed drive number\n", errno);
+ return(0);
+ }
+
+ /* Check drive number */
+ Status = NtQuerySystemInformation(SystemDeviceInformation,
+ &DeviceInfo,
+ sizeof(SYSTEM_DEVICE_INFORMATION),
+ &i);
+ if (!NT_SUCCESS(Status))
+ {
+ printf("NtQuerySystemInformation() failed (Status %lx)\n", Status);
+ return(0);
+ }
+
+ if (DeviceInfo.NumberOfDisks == 0)
+ {
+ printf("No disk drive installed!\n");
+ return(0);
+ }
+
+ if (ulDrive >= DeviceInfo.NumberOfDisks)
+ {
+ printf("Invalid disk drive number! Valid drive numbers [0-%lu]\n",
+ DeviceInfo.NumberOfDisks-1);
+ return(0);
+ }
+
+ /* Build full drive name */
+ sprintf(DriveName, "\\\\.\\PHYSICALDRIVE%lu", ulDrive);
+
+ /* Open drive */
+ hDisk = CreateFile(DriveName,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
return 0;
}
-
- /* get drive geometry */
+ /* Get drive geometry */
if (!DeviceIoControl(hDisk,
IOCTL_DISK_GET_DRIVE_GEOMETRY,
NULL,
#ifdef DUMP_DATA
HexDump((char*)&DiskGeometry, dwRead);
#endif
+ printf("Drive number: %lu\n", ulDrive);
printf("Cylinders: %I64u\nMediaType: %lx\nTracksPerCylinder: %lu\n"
"SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n",
DiskGeometry.Cylinders.QuadPart,
NULL))
{
CloseHandle(hDisk);
- printf("DeviceIoControl failed! Error: %u\n",
+ printf("DeviceIoControl(IOCTL_DISK_GET_DRIVE_LAYOUT) failed! Error: %u\n",
GetLastError());
free(Buffer);
return 0;
LayoutBuffer->PartitionEntry[i].PartitionLength.QuadPart);
}
-#ifdef DUMP_SIZE_INFO
- printf("\nsizeof(PARTITION_INFORMATION): %lu\n", sizeof(PARTITION_INFORMATION));
-#endif
-
free(Buffer);
return 0;