2 * partinfo - partition info program
6 //#include <winioctl.h>
12 #define DUMP_SIZE_INFO
16 void HexDump(char *buffer
, ULONG size
)
21 while (offset
< (size
& ~15))
23 ptr
= (unsigned char*)((ULONG
)buffer
+ offset
);
24 printf("%08lx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx\n",
45 ptr
= (unsigned char*)((ULONG
)buffer
+ offset
);
46 printf("%08lx ", offset
);
49 printf(" %02hx", *ptr
);
61 puts("Usage: partinfo <drive number>");
65 int main (int argc
, char *argv
[])
71 DRIVE_LAYOUT_INFORMATION
*LayoutBuffer
;
72 DISK_GEOMETRY DiskGeometry
;
75 SYSTEM_DEVICE_INFORMATION DeviceInfo
;
84 ulDrive
= strtoul(argv
[1], NULL
, 10);
87 printf("Error: Malformed drive number\n");
91 /* Check drive number */
92 Status
= NtQuerySystemInformation(SystemDeviceInformation
,
94 sizeof(SYSTEM_DEVICE_INFORMATION
),
96 if (!NT_SUCCESS(Status
))
98 printf("NtQuerySystemInformation() failed (Status %lx)\n", Status
);
102 if (DeviceInfo
.NumberOfDisks
== 0)
104 printf("No disk drive installed!\n");
108 if (ulDrive
>= DeviceInfo
.NumberOfDisks
)
110 printf("Invalid disk drive number! Valid drive numbers [0-%lu]\n",
111 DeviceInfo
.NumberOfDisks
-1);
115 /* Build full drive name */
116 sprintf(DriveName
, "\\\\.\\PHYSICALDRIVE%lu", ulDrive
);
119 hDisk
= CreateFile(DriveName
,
121 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
126 if (hDisk
== INVALID_HANDLE_VALUE
)
128 printf("Invalid disk handle!");
132 /* Get drive geometry */
133 if (!DeviceIoControl(hDisk
,
134 IOCTL_DISK_GET_DRIVE_GEOMETRY
,
138 sizeof(DISK_GEOMETRY
),
143 printf("DeviceIoControl failed! Error: %lu\n",
149 HexDump((char*)&DiskGeometry
, dwRead
);
151 printf("Drive number: %lu\n", ulDrive
);
152 printf("Cylinders: %I64u\nMediaType: %x\nTracksPerCylinder: %lu\n"
153 "SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n",
154 DiskGeometry
.Cylinders
.QuadPart
,
155 DiskGeometry
.MediaType
,
156 DiskGeometry
.TracksPerCylinder
,
157 DiskGeometry
.SectorsPerTrack
,
158 DiskGeometry
.BytesPerSector
);
161 Buffer
= (char*)malloc(8192);
165 printf("Out of memory!");
168 memset(Buffer
, 0, 8192);
170 if (!DeviceIoControl(hDisk
,
171 IOCTL_DISK_GET_DRIVE_LAYOUT
,
180 printf("DeviceIoControl(IOCTL_DISK_GET_DRIVE_LAYOUT) failed! Error: %lu\n",
189 HexDump(Buffer
, dwRead
);
192 LayoutBuffer
= (DRIVE_LAYOUT_INFORMATION
*)Buffer
;
194 printf("Partitions %lu Signature %lx\n",
195 LayoutBuffer
->PartitionCount
,
196 LayoutBuffer
->Signature
);
198 for (i
= 0; i
< LayoutBuffer
->PartitionCount
; i
++)
200 printf(" %ld: nr: %ld boot: %1x type: %x start: 0x%I64x count: 0x%I64x\n",
202 LayoutBuffer
->PartitionEntry
[i
].PartitionNumber
,
203 LayoutBuffer
->PartitionEntry
[i
].BootIndicator
,
204 LayoutBuffer
->PartitionEntry
[i
].PartitionType
,
205 LayoutBuffer
->PartitionEntry
[i
].StartingOffset
.QuadPart
,
206 LayoutBuffer
->PartitionEntry
[i
].PartitionLength
.QuadPart
);