2 * partinfo - partition info program
6 //#include <winioctl.h>
11 #define DUMP_SIZE_INFO
15 void HexDump(char *buffer
, ULONG size
)
20 while (offset
< (size
& ~15))
22 ptr
= (unsigned char*)((ULONG
)buffer
+ offset
);
23 printf("%08lx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx\n",
44 ptr
= (unsigned char*)((ULONG
)buffer
+ offset
);
45 printf("%08lx ", offset
);
48 printf(" %02hx", *ptr
);
60 puts("Usage: partinfo <drive number>");
64 int main (int argc
, char *argv
[])
70 DRIVE_LAYOUT_INFORMATION
*LayoutBuffer
;
71 DISK_GEOMETRY DiskGeometry
;
74 SYSTEM_DEVICE_INFORMATION DeviceInfo
;
83 ulDrive
= strtoul(argv
[1], NULL
, 10);
86 printf("Error: Malformed drive number\n", errno
);
90 /* Check drive number */
91 Status
= NtQuerySystemInformation(SystemDeviceInformation
,
93 sizeof(SYSTEM_DEVICE_INFORMATION
),
95 if (!NT_SUCCESS(Status
))
97 printf("NtQuerySystemInformation() failed (Status %lx)\n", Status
);
101 if (DeviceInfo
.NumberOfDisks
== 0)
103 printf("No disk drive installed!\n");
107 if (ulDrive
>= DeviceInfo
.NumberOfDisks
)
109 printf("Invalid disk drive number! Valid drive numbers [0-%lu]\n",
110 DeviceInfo
.NumberOfDisks
-1);
114 /* Build full drive name */
115 sprintf(DriveName
, "\\\\.\\PHYSICALDRIVE%lu", ulDrive
);
118 hDisk
= CreateFile(DriveName
,
120 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
125 if (hDisk
== INVALID_HANDLE_VALUE
)
127 printf("Invalid disk handle!");
131 /* Get drive geometry */
132 if (!DeviceIoControl(hDisk
,
133 IOCTL_DISK_GET_DRIVE_GEOMETRY
,
137 sizeof(DISK_GEOMETRY
),
142 printf("DeviceIoControl failed! Error: %u\n",
149 HexDump((char*)&DiskGeometry
, dwRead
);
151 printf("Drive number: %lu\n", ulDrive
);
152 printf("Cylinders: %I64u\nMediaType: %lx\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: %u\n",
189 HexDump(Buffer
, dwRead
);
192 LayoutBuffer
= (DRIVE_LAYOUT_INFORMATION
*)Buffer
;
194 printf("Partitions %u Signature %x\n",
195 LayoutBuffer
->PartitionCount
,
196 LayoutBuffer
->Signature
);
198 for (i
= 0; i
< LayoutBuffer
->PartitionCount
; i
++)
200 printf(" %d: nr: %d 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
);