2 * partinfo - partition info program
6 //#include <winioctl.h>
14 #define DUMP_SIZE_INFO
18 void HexDump(char *buffer
, ULONG size
)
23 while (offset
< (size
& ~15))
25 ptr
= (unsigned char*)((ULONG
)buffer
+ offset
);
26 printf("%08lx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx\n",
47 ptr
= (unsigned char*)((ULONG
)buffer
+ offset
);
48 printf("%08lx ", offset
);
51 printf(" %02hx", *ptr
);
63 puts("Usage: partinfo <drive number>");
67 int main (int argc
, char *argv
[])
73 DRIVE_LAYOUT_INFORMATION
*LayoutBuffer
;
74 DISK_GEOMETRY DiskGeometry
;
77 SYSTEM_DEVICE_INFORMATION DeviceInfo
;
86 ulDrive
= strtoul(argv
[1], NULL
, 10);
89 printf("Error: Malformed drive number\n");
93 /* Check drive number */
94 Status
= NtQuerySystemInformation(SystemDeviceInformation
,
96 sizeof(SYSTEM_DEVICE_INFORMATION
),
98 if (!NT_SUCCESS(Status
))
100 printf("NtQuerySystemInformation() failed (Status %lx)\n", Status
);
104 if (DeviceInfo
.NumberOfDisks
== 0)
106 printf("No disk drive installed!\n");
110 if (ulDrive
>= DeviceInfo
.NumberOfDisks
)
112 printf("Invalid disk drive number! Valid drive numbers [0-%lu]\n",
113 DeviceInfo
.NumberOfDisks
-1);
117 /* Build full drive name */
118 sprintf(DriveName
, "\\\\.\\PHYSICALDRIVE%lu", ulDrive
);
121 hDisk
= CreateFile(DriveName
,
123 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
128 if (hDisk
== INVALID_HANDLE_VALUE
)
130 printf("Invalid disk handle!");
134 /* Get drive geometry */
135 if (!DeviceIoControl(hDisk
,
136 IOCTL_DISK_GET_DRIVE_GEOMETRY
,
140 sizeof(DISK_GEOMETRY
),
145 printf("DeviceIoControl failed! Error: %lu\n",
151 HexDump((char*)&DiskGeometry
, dwRead
);
153 printf("Drive number: %lu\n", ulDrive
);
154 printf("Cylinders: %I64u\nMediaType: %x\nTracksPerCylinder: %lu\n"
155 "SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n",
156 DiskGeometry
.Cylinders
.QuadPart
,
157 DiskGeometry
.MediaType
,
158 DiskGeometry
.TracksPerCylinder
,
159 DiskGeometry
.SectorsPerTrack
,
160 DiskGeometry
.BytesPerSector
);
163 Buffer
= (char*)malloc(8192);
167 printf("Out of memory!");
170 memset(Buffer
, 0, 8192);
172 if (!DeviceIoControl(hDisk
,
173 IOCTL_DISK_GET_DRIVE_LAYOUT
,
182 printf("DeviceIoControl(IOCTL_DISK_GET_DRIVE_LAYOUT) failed! Error: %lu\n",
191 HexDump(Buffer
, dwRead
);
194 LayoutBuffer
= (DRIVE_LAYOUT_INFORMATION
*)Buffer
;
196 printf("Partitions %lu Signature %lx\n",
197 LayoutBuffer
->PartitionCount
,
198 LayoutBuffer
->Signature
);
200 for (i
= 0; i
< LayoutBuffer
->PartitionCount
; i
++)
202 printf(" %ld: nr: %ld boot: %1x type: %x start: 0x%I64x count: 0x%I64x\n",
204 LayoutBuffer
->PartitionEntry
[i
].PartitionNumber
,
205 LayoutBuffer
->PartitionEntry
[i
].BootIndicator
,
206 LayoutBuffer
->PartitionEntry
[i
].PartitionType
,
207 LayoutBuffer
->PartitionEntry
[i
].StartingOffset
.QuadPart
,
208 LayoutBuffer
->PartitionEntry
[i
].PartitionLength
.QuadPart
);