| 516 | } |
| 517 | |
| 518 | PDRIVE_LAYOUT_INFORMATION_EXT |
| 519 | Ext2QueryDriveLayout( |
| 520 | HANDLE Handle, |
| 521 | PUCHAR NumOfParts |
| 522 | ) |
| 523 | { |
| 524 | NT::IO_STATUS_BLOCK ioSb; |
| 525 | NT::NTSTATUS status; |
| 526 | |
| 527 | PDRIVE_LAYOUT_INFORMATION_EXT driveLayout = NULL; |
| 528 | ULONG dataSize = 512; |
| 529 | ULONG retSize = 0; |
| 530 | |
| 531 | QueryDrive: |
| 532 | |
| 533 | status = STATUS_SUCCESS; |
| 534 | driveLayout = (PDRIVE_LAYOUT_INFORMATION_EXT) malloc(dataSize); |
| 535 | if(!driveLayout) { |
| 536 | goto errorout; |
| 537 | } |
| 538 | memset(driveLayout, 0, dataSize); |
| 539 | |
| 540 | if (IsWindows2000()) { |
| 541 | |
| 542 | PDRIVE_LAYOUT_INFORMATION oldLayout = |
| 543 | (PDRIVE_LAYOUT_INFORMATION ) malloc(dataSize); |
| 544 | if (!oldLayout) { |
| 545 | goto errorout; |
| 546 | } |
| 547 | |
| 548 | status = NT::ZwDeviceIoControlFile( |
| 549 | Handle, NULL, NULL, NULL, &ioSb, |
| 550 | IOCTL_DISK_GET_DRIVE_LAYOUT, |
| 551 | NULL, 0, (PVOID)oldLayout, dataSize |
| 552 | ); |
| 553 | |
| 554 | if (NT_SUCCESS(status)) { |
| 555 | |
| 556 | ULONG newLayoutSize = FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION_EX, PartitionEntry); |
| 557 | newLayoutSize += sizeof(PARTITION_INFORMATION_EX) * oldLayout->PartitionCount; |
| 558 | |
| 559 | if (dataSize >= newLayoutSize) { |
| 560 | |
| 561 | driveLayout->PartitionStyle = PARTITION_STYLE_MBR; |
| 562 | driveLayout->PartitionCount = oldLayout->PartitionCount; |
| 563 | driveLayout->Mbr.Signature = oldLayout->Signature; |
| 564 | |
| 565 | for (DWORD i=0; i < oldLayout->PartitionCount; i++) { |
| 566 | driveLayout->PartitionEntry[i].PartitionStyle = PARTITION_STYLE_MBR; |
| 567 | |
| 568 | driveLayout->PartitionEntry[i].StartingOffset = |
| 569 | oldLayout->PartitionEntry[i].StartingOffset; |
| 570 | driveLayout->PartitionEntry[i].PartitionLength = |
| 571 | oldLayout->PartitionEntry[i].PartitionLength; |
| 572 | driveLayout->PartitionEntry[i].PartitionNumber = |
| 573 | oldLayout->PartitionEntry[i].PartitionNumber; |
| 574 | driveLayout->PartitionEntry[i].RewritePartition = |
| 575 | oldLayout->PartitionEntry[i].RewritePartition; |
no test coverage detected