2 * partinfo - partition info program
8 #define WIN32_NO_STATUS
13 #define DUMP_SIZE_INFO
23 while (offset
< (size
& ~15))
25 ptr
= (PUCHAR
)((ULONG_PTR
)buffer
+ offset
);
26 printf("%08lx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx\n",
28 ptr
[0], ptr
[1], ptr
[2] , ptr
[3] , ptr
[4] , ptr
[5] , ptr
[6] , ptr
[7],
29 ptr
[8], ptr
[9], ptr
[10], ptr
[11], ptr
[12], ptr
[13], ptr
[14], ptr
[15]);
33 ptr
= (PUCHAR
)((ULONG_PTR
)buffer
+ offset
);
34 printf("%08lx ", offset
);
37 printf(" %02hx", *ptr
);
48 puts("Usage: partinfo <drive number>");
51 int main(int argc
, char *argv
[])
58 SYSTEM_DEVICE_INFORMATION DeviceInfo
;
59 DISK_GEOMETRY DiskGeometry
;
60 PDRIVE_LAYOUT_INFORMATION LayoutBuffer
;
69 ulDrive
= strtoul(argv
[1], NULL
, 10);
72 printf("Error: Malformed drive number\n");
77 * Retrieve the number of disks on the system.
79 Status
= NtQuerySystemInformation(SystemDeviceInformation
,
83 if (!NT_SUCCESS(Status
))
85 printf("NtQuerySystemInformation() failed (Status %lx)\n", Status
);
88 if (DeviceInfo
.NumberOfDisks
== 0)
90 printf("No disk drive installed!\n");
94 if (ulDrive
>= DeviceInfo
.NumberOfDisks
)
96 printf("Invalid disk drive number! Valid drive numbers [0-%lu]\n",
97 DeviceInfo
.NumberOfDisks
-1);
101 /* Build the full drive name */
102 sprintf(DriveName
, "\\\\.\\PHYSICALDRIVE%lu", ulDrive
);
105 hDisk
= CreateFileA(DriveName
,
107 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
112 if (hDisk
== INVALID_HANDLE_VALUE
)
114 printf("Invalid disk handle!");
119 * Get the drive geometry.
121 if (!DeviceIoControl(hDisk
,
122 IOCTL_DISK_GET_DRIVE_GEOMETRY
,
126 sizeof(DiskGeometry
),
130 printf("DeviceIoControl(IOCTL_DISK_GET_DRIVE_GEOMETRY) failed! Error: %lu\n",
137 HexDump(&DiskGeometry
, dwRead
);
139 printf("Drive number: %lu\n", ulDrive
);
140 printf("Cylinders: %I64u\nMediaType: %x\nTracksPerCylinder: %lu\n"
141 "SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n",
142 DiskGeometry
.Cylinders
.QuadPart
,
143 DiskGeometry
.MediaType
,
144 DiskGeometry
.TracksPerCylinder
,
145 DiskGeometry
.SectorsPerTrack
,
146 DiskGeometry
.BytesPerSector
);
149 /* Get extended drive geometry */
150 // IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
154 * Retrieve the legacy partition layout
156 LayoutBuffer
= (PDRIVE_LAYOUT_INFORMATION
)malloc(8192);
157 if (LayoutBuffer
== NULL
)
159 printf("Out of memory!");
163 memset(LayoutBuffer
, 0, 8192);
165 if (!DeviceIoControl(hDisk
,
166 IOCTL_DISK_GET_DRIVE_LAYOUT
,
174 printf("DeviceIoControl(IOCTL_DISK_GET_DRIVE_LAYOUT) failed! Error: %lu\n",
184 HexDump(LayoutBuffer
, dwRead
);
187 printf("Partitions %lu Signature %lx\n",
188 LayoutBuffer
->PartitionCount
,
189 LayoutBuffer
->Signature
);
191 for (i
= 0; i
< LayoutBuffer
->PartitionCount
; i
++)
193 printf(" %ld: nr: %ld boot: %1x type: %x start: 0x%I64x count: 0x%I64x\n",
195 LayoutBuffer
->PartitionEntry
[i
].PartitionNumber
,
196 LayoutBuffer
->PartitionEntry
[i
].BootIndicator
,
197 LayoutBuffer
->PartitionEntry
[i
].PartitionType
,
198 LayoutBuffer
->PartitionEntry
[i
].StartingOffset
.QuadPart
,
199 LayoutBuffer
->PartitionEntry
[i
].PartitionLength
.QuadPart
);
204 // TODO: Retrieve the extended partition layout