14#define WIN32_NO_STATUS
27#define DRIVE_LAYOUT_INFO_ENTRY_SIZE \
28 RTL_FIELD_SIZE(DRIVE_LAYOUT_INFORMATION, PartitionEntry[0])
30#define DRIVE_LAYOUT_INFO_SIZE(n) \
31 (FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION, PartitionEntry) + \
32 ((n) * DRIVE_LAYOUT_INFO_ENTRY_SIZE))
34#define DRIVE_LAYOUT_INFOEX_ENTRY_SIZE \
35 RTL_FIELD_SIZE(DRIVE_LAYOUT_INFORMATION_EX, PartitionEntry[0])
37#define DRIVE_LAYOUT_INFOEX_SIZE(n) \
38 (FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION_EX, PartitionEntry) + \
39 ((n) * DRIVE_LAYOUT_INFOEX_ENTRY_SIZE))
43#define ROUND_UP_NUM(num, up) ((((num) + (up) - 1) / (up)) * (up))
52#define PARTITION_STYLE_NAME(PartStyle) \
53 ( ((PartStyle) <= PARTITION_STYLE_RAW) \
54 ? PartitionStyleNames[(PartStyle)] \
55 : PartitionStyleNames[_countof(PartitionStyleNames)-1] )
58#define DETECT_TYPE_NAME(DetectType) \
59 ( ((DetectType) <= DetectExInt13) \
60 ? DetectTypeNames[(DetectType)] \
61 : DetectTypeNames[_countof(DetectTypeNames)-1] )
63#define GUID_FORMAT_STR "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"
64#define GUID_ELEMENTS(Guid) \
65 (Guid)->Data1, (Guid)->Data2, (Guid)->Data3, \
66 (Guid)->Data4[0], (Guid)->Data4[1], (Guid)->Data4[2], (Guid)->Data4[3], \
67 (Guid)->Data4[4], (Guid)->Data4[5], (Guid)->Data4[6], (Guid)->Data4[7]
83 printf(
"%08lx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx\n",
109 puts(
"Usage: partinfo <drive number>");
137 PDRIVE_LAYOUT_INFORMATION_EX InfoEx;
151 printf(
"Error: Malformed drive number\n");
164 printf(
"NtQuerySystemInformation() failed (Status 0x%lx)\n",
Status);
169 printf(
"No disk drive installed!\n");
175 printf(
"Invalid disk drive number! Valid drive numbers: [0-%lu]\n",
181 swprintf(DriveName,
L"\\\\.\\PHYSICALDRIVE%lu", ulDrive);
193 printf(
"Could not open drive!");
197 printf(
"Drive number: %lu\n\n", ulDrive);
212 sizeof(DiskGeometry.Info));
215 printf(
"NtDeviceIoControlFile(IOCTL_DISK_GET_DRIVE_GEOMETRY) failed! (Status 0x%lx)\n",
Status);
219 pDiskGeometry = &DiskGeometry.Info;
224 printf(
"IOCTL_DISK_GET_DRIVE_GEOMETRY\n"
225 "Cylinders: %I64u\nMediaType: 0x%x\nTracksPerCylinder: %lu\n"
226 "SectorsPerTrack: %lu\nBytesPerSector: %lu\n",
247 &DiskGeometry.InfoEx,
248 sizeof(DiskGeometry.InfoEx));
251 printf(
"NtDeviceIoControlFile(IOCTL_DISK_GET_DRIVE_GEOMETRY_EX) failed! (Status 0x%lx)\n",
Status);
257 pDiskGeometry = &DiskGeometry.InfoEx.Geometry;
262 printf(
"IOCTL_DISK_GET_DRIVE_GEOMETRY_EX\n"
263 "Cylinders: %I64u\nMediaType: 0x%x\nTracksPerCylinder: %lu\n"
264 "SectorsPerTrack: %lu\nBytesPerSector: %lu\n"
271 DiskGeometry.InfoEx.DiskSize.QuadPart);
273 printf(
"SizeOfDetectInfo: %lu DetectionType: %u (%s)\n",
274 DiskGeometry.InfoEx.Detection.SizeOfDetectInfo,
275 DiskGeometry.InfoEx.Detection.DetectionType,
277 switch (DiskGeometry.InfoEx.Detection.DetectionType)
281 PDISK_INT13_INFO pInt13 = &DiskGeometry.InfoEx.Detection.Int13;
282 printf(
" DriveSelect: %u MaxCylinders: %lu SectorsPerTrack: %u MaxHeads: %u NumberDrives: %u\n",
283 pInt13->DriveSelect, pInt13->MaxCylinders,
284 pInt13->SectorsPerTrack, pInt13->MaxHeads,
285 pInt13->NumberDrives);
291 PDISK_EX_INT13_INFO pExInt13 = &DiskGeometry.InfoEx.Detection.ExInt13;
292 printf(
" ExBufferSize: %u ExFlags: %u\n"
293 " ExCylinders: %lu ExHeads: %lu ExSectorsPerTrack: %lu\n"
294 " ExSectorsPerDrive: %I64u ExSectorSize: %u ExReserved: %u\n",
295 pExInt13->ExBufferSize, pExInt13->ExFlags,
296 pExInt13->ExCylinders, pExInt13->ExHeads,
297 pExInt13->ExSectorsPerTrack, pExInt13->ExSectorsPerDrive,
298 pExInt13->ExSectorSize, pExInt13->ExReserved);
307 printf(
"SizeOfPartitionInfo: %lu PartitionStyle: %u [%s]\n",
308 DiskGeometry.InfoEx.Partition.SizeOfPartitionInfo,
309 DiskGeometry.InfoEx.Partition.PartitionStyle,
314 printf(
" Signature: 0x%08lx Checksum 0x%08lx\n",
315 DiskGeometry.InfoEx.Partition.Mbr.Signature,
316 DiskGeometry.InfoEx.Partition.Mbr.CheckSum);
344 sizeof(PartInfo.Info));
347 printf(
"NtDeviceIoControlFile(IOCTL_DISK_GET_PARTITION_INFO) failed! (Status 0x%lx)\n",
Status);
351 pPartInfo = &PartInfo.Info;
356 printf(
"IOCTL_DISK_GET_PARTITION_INFO\n"
357 "nr: %ld boot: %1x type: 0x%x (%s) start: 0x%016I64x count: 0x%016I64x hidden: 0x%lx\n",
377 sizeof(PartInfo.InfoEx));
380 printf(
"NtDeviceIoControlFile(IOCTL_DISK_GET_PARTITION_INFO_EX) failed! (Status 0x%lx)\n",
Status);
384 pPartInfoEx = &PartInfo.InfoEx;
389 printf(
"IOCTL_DISK_GET_PARTITION_INFO_EX\n");
393 printf(
"nr: %ld [%s] boot: %1x type: 0x%x (%s) start: 0x%016I64x count: 0x%016I64x hidden: 0x%lx\n",
402#if (NTDDI_VERSION >= NTDDI_WINBLUE)
412 " attrs: 0x%016I64x\n"
414 " start: 0x%016I64x count: 0x%016I64x\n",
438 if (!LayoutBuffer.Info)
475 printf(
"Compactification failed; keeping original structure.\n");
479 LayoutBuffer.Info =
ptr;
487 printf(
"NtDeviceIoControlFile(IOCTL_DISK_GET_DRIVE_LAYOUT) failed! (Status 0x%lx)\n",
Status);
493 RtlFreeHeap(RtlGetProcessHeap(), 0, LayoutBuffer.Info);
511 RtlFreeHeap(RtlGetProcessHeap(), 0, LayoutBuffer.Info);
514 LayoutBuffer.Info =
ptr;
522 printf(
"IOCTL_DISK_GET_DRIVE_LAYOUT\n"
523 "Partitions: %lu Signature: 0x%08lx\n",
524 LayoutBuffer.Info->PartitionCount,
525 LayoutBuffer.Info->Signature);
527 for (
i = 0;
i < LayoutBuffer.Info->PartitionCount;
i++)
529 pPartInfo = &LayoutBuffer.Info->PartitionEntry[
i];
531 printf(
" %ld: nr: %ld boot: %1x type: 0x%x (%s) start: 0x%016I64x count: 0x%016I64x hidden: 0x%lx\n",
542 RtlFreeHeap(RtlGetProcessHeap(), 0, LayoutBuffer.Info);
555 if (!LayoutBuffer.InfoEx)
592 printf(
"Compactification failed; keeping original structure.\n");
596 LayoutBuffer.InfoEx =
ptr;
604 printf(
"NtDeviceIoControlFile(IOCTL_DISK_GET_DRIVE_LAYOUT_EX) failed! (Status 0x%lx)\n",
Status);
609 RtlFreeHeap(RtlGetProcessHeap(), 0, LayoutBuffer.InfoEx);
627 RtlFreeHeap(RtlGetProcessHeap(), 0, LayoutBuffer.InfoEx);
630 LayoutBuffer.InfoEx =
ptr;
638 printf(
"IOCTL_DISK_GET_DRIVE_LAYOUT_EX\n"
639 "PartitionStyle: %lu [%s]\n",
640 LayoutBuffer.InfoEx->PartitionStyle,
645 printf(
"Partitions: %lu Signature: 0x%08lx",
646 LayoutBuffer.InfoEx->PartitionCount,
647 LayoutBuffer.InfoEx->Mbr.Signature);
648#if (NTDDI_VERSION >= NTDDI_WIN10_RS1)
649 printf(
" Checksum 0x%08lx\n",
650 LayoutBuffer.InfoEx->Mbr.CheckSum);
655 for (
i = 0;
i < LayoutBuffer.InfoEx->PartitionCount;
i++)
657 pPartInfoEx = &LayoutBuffer.InfoEx->PartitionEntry[
i];
659 printf(
" %ld: nr: %ld [%s] boot: %1x type: 0x%x (%s) start: 0x%016I64x count: 0x%016I64x hidden: 0x%lx\n",
669#if (NTDDI_VERSION >= NTDDI_WINBLUE)
677 printf(
"Partitions: %lu MaxPartitionCount: %lu\n"
679 "StartingUsableOffset: 0x%016I64x UsableLength: 0x%016I64x\n",
680 LayoutBuffer.InfoEx->PartitionCount,
681 LayoutBuffer.InfoEx->Gpt.MaxPartitionCount,
683 LayoutBuffer.InfoEx->Gpt.StartingUsableOffset.QuadPart,
684 LayoutBuffer.InfoEx->Gpt.UsableLength.QuadPart);
686 for (
i = 0;
i < LayoutBuffer.InfoEx->PartitionCount;
i++)
688 pPartInfoEx = &LayoutBuffer.InfoEx->PartitionEntry[
i];
690 printf(
" %ld: nr: %ld [%s]\n"
693 " attrs: 0x%016I64x\n"
695 " start: 0x%016I64x count: 0x%016I64x\n",
709 RtlFreeHeap(RtlGetProcessHeap(), 0, LayoutBuffer.InfoEx);
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
void HexDump(PUCHAR buffer, ULONG size)
int puts(const char *string)
#define NT_SUCCESS(StatCode)
#define INVALID_HANDLE_VALUE
#define IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
#define IOCTL_DISK_GET_PARTITION_INFO_EX
#define IOCTL_DISK_GET_DRIVE_LAYOUT_EX
@ SystemDeviceInformation
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T)
static PCSTR PartitionStyleNames[]
#define DRIVE_LAYOUT_INFO_SIZE(n)
struct _DISK_GEOMETRY_EX_INTERNAL * PDISK_GEOMETRY_EX_INTERNAL
struct _DISK_GEOMETRY_EX_INTERNAL DISK_GEOMETRY_EX_INTERNAL
static PCSTR DetectTypeNames[]
#define DRIVE_LAYOUT_INFO_ENTRY_SIZE
#define DRIVE_LAYOUT_INFOEX_ENTRY_SIZE
#define ROUND_UP_NUM(num, up)
#define GUID_ELEMENTS(Guid)
#define DETECT_TYPE_NAME(DetectType)
#define DRIVE_LAYOUT_INFOEX_SIZE(n)
#define PARTITION_STYLE_NAME(PartStyle)
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define HEAP_REALLOC_IN_PLACE_ONLY
#define IOCTL_DISK_GET_DRIVE_LAYOUT
#define IOCTL_DISK_GET_PARTITION_INFO
#define STATUS_BUFFER_TOO_SMALL
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
DISK_PARTITION_INFO Partition
DISK_DETECTION_INFO Detection
#define STATUS_INVALID_DEVICE_REQUEST
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize