2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/fstub/disksup.c
5 * PURPOSE: I/O HAL Routines for Disk Access
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Eric Kohl (ekohl@rz-online.de)
8 * Casper S. Hornstrup (chorns@users.sourceforge.net)
11 /* INCLUDES ******************************************************************/
16 #include <internal/hal.h>
18 /* DEPRECATED FUNCTIONS ******************************************************/
21 const WCHAR DiskMountString
[] = L
"\\DosDevices\\%C:";
23 #define AUTO_DRIVE ((ULONG)-1)
25 #define PARTITION_MAGIC 0xaa55
29 typedef struct _REG_DISK_MOUNT_INFO
32 LARGE_INTEGER StartingOffset
;
33 } REG_DISK_MOUNT_INFO
, *PREG_DISK_MOUNT_INFO
;
37 typedef enum _DISK_MANAGER
45 HalpAssignDrive(IN PUNICODE_STRING PartitionName
,
49 IN LARGE_INTEGER StartingOffset
,
51 IN PUNICODE_STRING BootDevice
,
52 OUT PUCHAR NtSystemPath
)
54 WCHAR DriveNameBuffer
[16];
55 UNICODE_STRING DriveName
;
58 REG_DISK_MOUNT_INFO DiskMountInfo
;
60 DPRINT("HalpAssignDrive()\n");
62 if ((DriveNumber
!= AUTO_DRIVE
) && (DriveNumber
< 26))
64 /* Force assignment */
65 if ((ObSystemDeviceMap
->DriveMap
& (1 << DriveNumber
)) != 0)
67 DbgPrint("Drive letter already used!\n");
73 /* Automatic assignment */
74 DriveNumber
= AUTO_DRIVE
;
76 for (i
= 2; i
< 26; i
++)
78 if ((ObSystemDeviceMap
->DriveMap
& (1 << i
)) == 0)
85 if (DriveNumber
== AUTO_DRIVE
)
87 DbgPrint("No drive letter available!\n");
92 DPRINT("DriveNumber %d\n", DriveNumber
);
94 /* Update the System Device Map */
95 ObSystemDeviceMap
->DriveMap
|= (1 << DriveNumber
);
96 ObSystemDeviceMap
->DriveType
[DriveNumber
] = DriveType
;
98 /* Build drive name */
99 swprintf(DriveNameBuffer
,
102 RtlInitUnicodeString(&DriveName
,
105 DPRINT(" %wZ ==> %wZ\n",
109 /* Create symbolic link */
110 Status
= IoCreateSymbolicLink(&DriveName
,
114 DriveType
== DOSDEVICE_DRIVE_FIXED
&&
117 DiskMountInfo
.Signature
= Signature
;
118 DiskMountInfo
.StartingOffset
= StartingOffset
;
119 swprintf(DriveNameBuffer
, DiskMountString
, L
'A' + DriveNumber
);
120 RtlInitUnicodeString(&DriveName
, DriveNameBuffer
);
122 Status
= ZwSetValueKey(hKey
,
127 sizeof(DiskMountInfo
));
128 if (!NT_SUCCESS(Status
))
130 DPRINT1("ZwCreateValueKey failed for %wZ, status=%x\n", &DriveName
, Status
);
134 /* Check if this is a boot partition */
135 if (RtlCompareUnicodeString(PartitionName
, BootDevice
, FALSE
) == 0)
137 /* Set NtSystemPath to that partition's disk letter */
138 *NtSystemPath
= 'A' + DriveNumber
;
145 xHalpGetRDiskCount(VOID
)
148 UNICODE_STRING ArcName
;
149 PWCHAR ArcNameBuffer
;
150 OBJECT_ATTRIBUTES ObjectAttributes
;
151 HANDLE DirectoryHandle
;
152 POBJECT_DIRECTORY_INFORMATION DirectoryInfo
;
157 BOOLEAN First
= TRUE
;
160 DirectoryInfo
= ExAllocatePool(PagedPool
, 2 * PAGE_SIZE
);
161 if (DirectoryInfo
== NULL
)
166 RtlInitUnicodeString(&ArcName
, L
"\\ArcName");
167 InitializeObjectAttributes(&ObjectAttributes
,
173 Status
= ZwOpenDirectoryObject (&DirectoryHandle
,
174 SYMBOLIC_LINK_ALL_ACCESS
,
176 if (!NT_SUCCESS(Status
))
178 DPRINT1("ZwOpenDirectoryObject for %wZ failed, status=%lx\n", &ArcName
, Status
);
179 ExFreePool(DirectoryInfo
);
185 while (NT_SUCCESS(Status
))
187 Status
= NtQueryDirectoryObject (DirectoryHandle
,
195 if (NT_SUCCESS(Status
))
198 while (DirectoryInfo
[Count
].Name
.Buffer
)
200 DPRINT("Count %x\n", Count
);
201 DirectoryInfo
[Count
].Name
.Buffer
[DirectoryInfo
[Count
].Name
.Length
/ sizeof(WCHAR
)] = 0;
202 ArcNameBuffer
= DirectoryInfo
[Count
].Name
.Buffer
;
203 if (DirectoryInfo
[Count
].Name
.Length
>= sizeof(L
"multi(0)disk(0)rdisk(0)") - sizeof(WCHAR
) &&
204 !_wcsnicmp(ArcNameBuffer
, L
"multi(0)disk(0)rdisk(", (sizeof(L
"multi(0)disk(0)rdisk(") - sizeof(WCHAR
)) / sizeof(WCHAR
)))
206 DPRINT("%S\n", ArcNameBuffer
);
207 ArcNameBuffer
+= (sizeof(L
"multi(0)disk(0)rdisk(") - sizeof(WCHAR
)) / sizeof(WCHAR
);
209 while (iswdigit(*ArcNameBuffer
))
211 CurrentRDisk
= CurrentRDisk
* 10 + *ArcNameBuffer
- L
'0';
214 if (!_wcsicmp(ArcNameBuffer
, L
")") &&
215 CurrentRDisk
>= RDiskCount
)
217 RDiskCount
= CurrentRDisk
+ 1;
224 ExFreePool(DirectoryInfo
);
229 xHalpGetDiskNumberFromRDisk(ULONG RDisk
, PULONG DiskNumber
)
231 WCHAR NameBuffer
[80];
232 UNICODE_STRING ArcName
;
233 UNICODE_STRING LinkName
;
234 OBJECT_ATTRIBUTES ObjectAttributes
;
239 L
"\\ArcName\\multi(0)disk(0)rdisk(%lu)",
242 RtlInitUnicodeString(&ArcName
, NameBuffer
);
243 InitializeObjectAttributes(&ObjectAttributes
,
248 Status
= ZwOpenSymbolicLinkObject(&LinkHandle
,
249 SYMBOLIC_LINK_ALL_ACCESS
,
251 if (!NT_SUCCESS(Status
))
253 DPRINT1("ZwOpenSymbolicLinkObject failed for %wZ, status=%lx\n", &ArcName
, Status
);
257 LinkName
.Buffer
= NameBuffer
;
259 LinkName
.MaximumLength
= sizeof(NameBuffer
);
260 Status
= ZwQuerySymbolicLinkObject(LinkHandle
,
264 if (!NT_SUCCESS(Status
))
266 DPRINT1("ZwQuerySymbolicLinkObject failed, status=%lx\n", Status
);
269 if (LinkName
.Length
< sizeof(L
"\\Device\\Harddisk0\\Partition0") - sizeof(WCHAR
) ||
270 LinkName
.Length
>= sizeof(NameBuffer
))
272 return STATUS_UNSUCCESSFUL
;
275 NameBuffer
[LinkName
.Length
/ sizeof(WCHAR
)] = 0;
276 if (_wcsnicmp(NameBuffer
, L
"\\Device\\Harddisk", (sizeof(L
"\\Device\\Harddisk") - sizeof(WCHAR
)) / sizeof(WCHAR
)))
278 return STATUS_UNSUCCESSFUL
;
280 LinkName
.Buffer
+= (sizeof(L
"\\Device\\Harddisk") - sizeof(WCHAR
)) / sizeof(WCHAR
);
282 if (!iswdigit(*LinkName
.Buffer
))
284 return STATUS_UNSUCCESSFUL
;
287 while (iswdigit(*LinkName
.Buffer
))
289 *DiskNumber
= *DiskNumber
* 10 + *LinkName
.Buffer
- L
'0';
292 if (_wcsicmp(LinkName
.Buffer
, L
"\\Partition0"))
294 return STATUS_UNSUCCESSFUL
;
296 return STATUS_SUCCESS
;
301 xHalQueryDriveLayout(IN PUNICODE_STRING DeviceName
,
302 OUT PDRIVE_LAYOUT_INFORMATION
*LayoutInfo
)
304 IO_STATUS_BLOCK StatusBlock
;
305 DISK_GEOMETRY DiskGeometry
;
306 PDEVICE_OBJECT DeviceObject
= NULL
;
307 PFILE_OBJECT FileObject
;
312 DPRINT("xHalpQueryDriveLayout %wZ %p\n",
316 /* Get the drives sector size */
317 Status
= IoGetDeviceObjectPointer(DeviceName
,
318 FILE_READ_ATTRIBUTES
,
321 if (!NT_SUCCESS(Status
))
323 DPRINT("Status %x\n", Status
);
327 KeInitializeEvent(&Event
,
331 Irp
= IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_DRIVE_GEOMETRY
,
336 sizeof(DISK_GEOMETRY
),
342 ObDereferenceObject(FileObject
);
343 return(STATUS_INSUFFICIENT_RESOURCES
);
346 Status
= IoCallDriver(DeviceObject
,
348 if (Status
== STATUS_PENDING
)
350 KeWaitForSingleObject(&Event
,
355 Status
= StatusBlock
.Status
;
357 if (!NT_SUCCESS(Status
))
359 if (DeviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
)
361 DiskGeometry
.BytesPerSector
= 512;
365 ObDereferenceObject(FileObject
);
370 DPRINT("DiskGeometry.BytesPerSector: %d\n",
371 DiskGeometry
.BytesPerSector
);
373 if (DeviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
)
375 PDRIVE_LAYOUT_INFORMATION Buffer
;
377 /* Allocate a partition list for a single entry. */
378 Buffer
= ExAllocatePool(NonPagedPool
,
379 sizeof(DRIVE_LAYOUT_INFORMATION
));
382 RtlZeroMemory(Buffer
,
383 sizeof(DRIVE_LAYOUT_INFORMATION
));
384 Buffer
->PartitionCount
= 1;
385 *LayoutInfo
= Buffer
;
387 Status
= STATUS_SUCCESS
;
391 Status
= STATUS_UNSUCCESSFUL
;
396 /* Read the partition table */
397 Status
= IoReadPartitionTable(DeviceObject
,
398 DiskGeometry
.BytesPerSector
,
403 ObDereferenceObject(FileObject
);
410 xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock
,
411 IN PSTRING NtDeviceName
,
412 OUT PUCHAR NtSystemPath
,
413 OUT PSTRING NtSystemPathString
)
415 PDRIVE_LAYOUT_INFORMATION
*LayoutArray
;
416 PCONFIGURATION_INFORMATION ConfigInfo
;
417 OBJECT_ATTRIBUTES ObjectAttributes
;
418 IO_STATUS_BLOCK StatusBlock
;
419 UNICODE_STRING UnicodeString1
;
420 UNICODE_STRING UnicodeString2
;
430 PKEY_VALUE_PARTIAL_INFORMATION PartialInformation
;
431 PREG_DISK_MOUNT_INFO DiskMountInfo
;
433 UNICODE_STRING BootDevice
;
435 Status
= RtlAnsiStringToUnicodeString(&BootDevice
,
439 DPRINT("xHalIoAssignDriveLetters()\n");
441 ConfigInfo
= IoGetConfigurationInformation();
443 RDiskCount
= xHalpGetRDiskCount();
445 DPRINT("RDiskCount %d\n", RDiskCount
);
447 Buffer1
= (PWSTR
)ExAllocatePool(PagedPool
,
449 Buffer2
= (PWSTR
)ExAllocatePool(PagedPool
,
452 PartialInformation
= (PKEY_VALUE_PARTIAL_INFORMATION
)ExAllocatePool(PagedPool
,
453 sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + sizeof(REG_DISK_MOUNT_INFO
));
455 DiskMountInfo
= (PREG_DISK_MOUNT_INFO
) PartialInformation
->Data
;
457 /* Open or Create the 'MountedDevices' key */
458 RtlInitUnicodeString(&UnicodeString1
, L
"\\Registry\\Machine\\SYSTEM\\MountedDevices");
459 InitializeObjectAttributes(&ObjectAttributes
,
461 OBJ_CASE_INSENSITIVE
,
464 Status
= ZwOpenKey(&hKey
,
467 if (!NT_SUCCESS(Status
))
469 Status
= ZwCreateKey(&hKey
,
474 REG_OPTION_NON_VOLATILE
,
477 if (!NT_SUCCESS(Status
))
480 DPRINT("ZwCreateKey failed for %wZ, status=%x\n", &UnicodeString1
, Status
);
483 /* Create PhysicalDrive links */
484 DPRINT("Physical disk drives: %d\n", ConfigInfo
->DiskCount
);
485 for (i
= 0; i
< ConfigInfo
->DiskCount
; i
++)
488 L
"\\Device\\Harddisk%d\\Partition0",
490 RtlInitUnicodeString(&UnicodeString1
,
493 InitializeObjectAttributes(&ObjectAttributes
,
499 Status
= ZwOpenFile(&FileHandle
,
500 FILE_READ_DATA
| SYNCHRONIZE
,
504 FILE_SYNCHRONOUS_IO_NONALERT
);
505 if (NT_SUCCESS(Status
))
510 L
"\\??\\PhysicalDrive%d",
512 RtlInitUnicodeString(&UnicodeString2
,
515 DPRINT("Creating link: %S ==> %S\n",
519 IoCreateSymbolicLink(&UnicodeString2
,
524 /* Initialize layout array */
525 LayoutArray
= ExAllocatePool(NonPagedPool
,
526 ConfigInfo
->DiskCount
* sizeof(PDRIVE_LAYOUT_INFORMATION
));
527 RtlZeroMemory(LayoutArray
,
528 ConfigInfo
->DiskCount
* sizeof(PDRIVE_LAYOUT_INFORMATION
));
529 for (i
= 0; i
< ConfigInfo
->DiskCount
; i
++)
532 L
"\\Device\\Harddisk%d\\Partition0",
534 RtlInitUnicodeString(&UnicodeString1
,
537 Status
= xHalQueryDriveLayout(&UnicodeString1
,
539 if (!NT_SUCCESS(Status
))
541 DbgPrint("xHalQueryDriveLayout() failed (Status = 0x%lx)\n",
543 LayoutArray
[i
] = NULL
;
546 /* We don't use the RewritePartition value while mounting the disks.
547 * We use this value for marking pre-assigned (registry) partitions.
549 for (j
= 0; j
< LayoutArray
[i
]->PartitionCount
; j
++)
551 LayoutArray
[i
]->PartitionEntry
[j
].RewritePartition
= FALSE
;
556 /* Dump layout array */
557 for (i
= 0; i
< ConfigInfo
->DiskCount
; i
++)
559 DPRINT("Harddisk %d:\n",
562 if (LayoutArray
[i
] == NULL
)
565 DPRINT("Logical partitions: %d\n",
566 LayoutArray
[i
]->PartitionCount
);
568 for (j
= 0; j
< LayoutArray
[i
]->PartitionCount
; j
++)
570 DPRINT(" %d: nr:%x boot:%x type:%x startblock:%I64u count:%I64u\n",
572 LayoutArray
[i
]->PartitionEntry
[j
].PartitionNumber
,
573 LayoutArray
[i
]->PartitionEntry
[j
].BootIndicator
,
574 LayoutArray
[i
]->PartitionEntry
[j
].PartitionType
,
575 LayoutArray
[i
]->PartitionEntry
[j
].StartingOffset
.QuadPart
,
576 LayoutArray
[i
]->PartitionEntry
[j
].PartitionLength
.QuadPart
);
581 /* Assign pre-assigned (registry) partitions */
584 for (k
= 2; k
< 26; k
++)
586 swprintf(Buffer1
, DiskMountString
, L
'A' + k
);
587 RtlInitUnicodeString(&UnicodeString1
, Buffer1
);
588 Status
= ZwQueryValueKey(hKey
,
590 KeyValuePartialInformation
,
592 sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + sizeof(REG_DISK_MOUNT_INFO
),
594 if (NT_SUCCESS(Status
) &&
595 PartialInformation
->Type
== REG_BINARY
&&
596 PartialInformation
->DataLength
== sizeof(REG_DISK_MOUNT_INFO
))
598 DPRINT("%wZ => %08x:%08x%08x\n", &UnicodeString1
, DiskMountInfo
->Signature
,
599 DiskMountInfo
->StartingOffset
.u
.HighPart
, DiskMountInfo
->StartingOffset
.u
.LowPart
);
601 BOOLEAN Found
= FALSE
;
602 for (i
= 0; i
< ConfigInfo
->DiskCount
; i
++)
604 DPRINT("%x\n", LayoutArray
[i
]->Signature
);
605 if (LayoutArray
[i
] &&
606 LayoutArray
[i
]->Signature
&&
607 LayoutArray
[i
]->Signature
== DiskMountInfo
->Signature
)
609 for (j
= 0; j
< LayoutArray
[i
]->PartitionCount
; j
++)
611 if (LayoutArray
[i
]->PartitionEntry
[j
].StartingOffset
.QuadPart
== DiskMountInfo
->StartingOffset
.QuadPart
)
613 if (IsRecognizedPartition(LayoutArray
[i
]->PartitionEntry
[j
].PartitionType
) &&
614 LayoutArray
[i
]->PartitionEntry
[j
].RewritePartition
== FALSE
)
617 L
"\\Device\\Harddisk%d\\Partition%d",
619 LayoutArray
[i
]->PartitionEntry
[j
].PartitionNumber
);
620 RtlInitUnicodeString(&UnicodeString2
,
624 DPRINT(" %wZ\n", &UnicodeString2
);
625 Found
= HalpAssignDrive(&UnicodeString2
,
627 DOSDEVICE_DRIVE_FIXED
,
628 DiskMountInfo
->Signature
,
629 DiskMountInfo
->StartingOffset
,
633 /* Mark the partition as assigned */
634 LayoutArray
[i
]->PartitionEntry
[j
].RewritePartition
= TRUE
;
643 /* We didn't find a partition for this entry, remove them. */
644 Status
= ZwDeleteValueKey(hKey
, &UnicodeString1
);
651 /* Assign bootable partition on first harddisk */
652 DPRINT("Assigning bootable primary partition on first harddisk:\n");
655 Status
= xHalpGetDiskNumberFromRDisk(0, &DiskNumber
);
656 if (NT_SUCCESS(Status
) &&
657 DiskNumber
< ConfigInfo
->DiskCount
&&
658 LayoutArray
[DiskNumber
])
660 /* Search for bootable partition */
661 for (j
= 0; j
< NUM_PARTITION_TABLE_ENTRIES
&& j
< LayoutArray
[DiskNumber
]->PartitionCount
; j
++)
663 if ((LayoutArray
[DiskNumber
]->PartitionEntry
[j
].BootIndicator
== TRUE
) &&
664 IsRecognizedPartition(LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionType
))
666 if (LayoutArray
[DiskNumber
]->PartitionEntry
[j
].RewritePartition
== FALSE
)
669 L
"\\Device\\Harddisk%lu\\Partition%d",
671 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionNumber
);
672 RtlInitUnicodeString(&UnicodeString2
,
676 DPRINT(" %wZ\n", &UnicodeString2
);
677 HalpAssignDrive(&UnicodeString2
,
679 DOSDEVICE_DRIVE_FIXED
,
680 LayoutArray
[DiskNumber
]->Signature
,
681 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].StartingOffset
,
685 /* Mark the partition as assigned */
686 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].RewritePartition
= TRUE
;
694 /* Assign remaining primary partitions */
695 DPRINT("Assigning remaining primary partitions:\n");
696 for (RDisk
= 0; RDisk
< RDiskCount
; RDisk
++)
698 Status
= xHalpGetDiskNumberFromRDisk(RDisk
, &DiskNumber
);
699 if (NT_SUCCESS(Status
) &&
700 DiskNumber
< ConfigInfo
->DiskCount
&&
701 LayoutArray
[DiskNumber
])
703 /* Search for primary partitions */
704 for (j
= 0; (j
< NUM_PARTITION_TABLE_ENTRIES
) && (j
< LayoutArray
[DiskNumber
]->PartitionCount
); j
++)
706 if (LayoutArray
[DiskNumber
]->PartitionEntry
[j
].RewritePartition
== FALSE
&&
707 IsRecognizedPartition(LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionType
))
710 L
"\\Device\\Harddisk%d\\Partition%d",
712 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionNumber
);
713 RtlInitUnicodeString(&UnicodeString2
,
719 HalpAssignDrive(&UnicodeString2
,
721 DOSDEVICE_DRIVE_FIXED
,
722 LayoutArray
[DiskNumber
]->Signature
,
723 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].StartingOffset
,
727 /* Mark the partition as assigned */
728 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].RewritePartition
= TRUE
;
734 /* Assign extended (logical) partitions */
735 DPRINT("Assigning extended (logical) partitions:\n");
736 for (RDisk
= 0; RDisk
< RDiskCount
; RDisk
++)
738 Status
= xHalpGetDiskNumberFromRDisk(RDisk
, &DiskNumber
);
739 if (NT_SUCCESS(Status
) &&
740 DiskNumber
< ConfigInfo
->DiskCount
&&
741 LayoutArray
[DiskNumber
])
743 /* Search for extended partitions */
744 for (j
= NUM_PARTITION_TABLE_ENTRIES
; j
< LayoutArray
[DiskNumber
]->PartitionCount
; j
++)
746 if (IsRecognizedPartition(LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionType
) &&
747 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].RewritePartition
== FALSE
&&
748 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionNumber
!= 0)
751 L
"\\Device\\Harddisk%d\\Partition%d",
753 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionNumber
);
754 RtlInitUnicodeString(&UnicodeString2
,
760 HalpAssignDrive(&UnicodeString2
,
762 DOSDEVICE_DRIVE_FIXED
,
763 LayoutArray
[DiskNumber
]->Signature
,
764 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].StartingOffset
,
768 /* Mark the partition as assigned */
769 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].RewritePartition
= TRUE
;
775 /* Assign remaining primary partitions without an arc-name */
776 DPRINT("Assigning remaining primary partitions:\n");
777 for (DiskNumber
= 0; DiskNumber
< ConfigInfo
->DiskCount
; DiskNumber
++)
779 if (LayoutArray
[DiskNumber
])
781 /* Search for primary partitions */
782 for (j
= 0; (j
< NUM_PARTITION_TABLE_ENTRIES
) && (j
< LayoutArray
[DiskNumber
]->PartitionCount
); j
++)
784 if (LayoutArray
[DiskNumber
]->PartitionEntry
[j
].RewritePartition
== FALSE
&&
785 IsRecognizedPartition(LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionType
))
788 L
"\\Device\\Harddisk%d\\Partition%d",
790 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionNumber
);
791 RtlInitUnicodeString(&UnicodeString2
,
797 HalpAssignDrive(&UnicodeString2
,
799 DOSDEVICE_DRIVE_FIXED
,
800 LayoutArray
[DiskNumber
]->Signature
,
801 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].StartingOffset
,
805 /* Mark the partition as assigned */
806 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].RewritePartition
= TRUE
;
812 /* Assign extended (logical) partitions without an arc-name */
813 DPRINT("Assigning extended (logical) partitions:\n");
814 for (DiskNumber
= 0; DiskNumber
< ConfigInfo
->DiskCount
; DiskNumber
++)
816 if (LayoutArray
[DiskNumber
])
818 /* Search for extended partitions */
819 for (j
= NUM_PARTITION_TABLE_ENTRIES
; j
< LayoutArray
[DiskNumber
]->PartitionCount
; j
++)
821 if (IsRecognizedPartition(LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionType
) &&
822 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].RewritePartition
== FALSE
&&
823 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionNumber
!= 0)
826 L
"\\Device\\Harddisk%d\\Partition%d",
828 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].PartitionNumber
);
829 RtlInitUnicodeString(&UnicodeString2
,
835 HalpAssignDrive(&UnicodeString2
,
837 DOSDEVICE_DRIVE_FIXED
,
838 LayoutArray
[DiskNumber
]->Signature
,
839 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].StartingOffset
,
843 /* Mark the partition as assigned */
844 LayoutArray
[DiskNumber
]->PartitionEntry
[j
].RewritePartition
= TRUE
;
850 /* Assign removable disk drives */
851 DPRINT("Assigning removable disk drives:\n");
852 for (i
= 0; i
< ConfigInfo
->DiskCount
; i
++)
856 /* Search for virtual partitions */
857 if (LayoutArray
[i
]->PartitionCount
== 1 &&
858 LayoutArray
[i
]->PartitionEntry
[0].PartitionType
== 0)
861 L
"\\Device\\Harddisk%d\\Partition1",
863 RtlInitUnicodeString(&UnicodeString2
,
869 HalpAssignDrive(&UnicodeString2
,
871 DOSDEVICE_DRIVE_REMOVABLE
,
873 RtlConvertLongToLargeInteger(0),
881 /* Free layout array */
882 for (i
= 0; i
< ConfigInfo
->DiskCount
; i
++)
884 if (LayoutArray
[i
] != NULL
)
885 ExFreePool(LayoutArray
[i
]);
887 ExFreePool(LayoutArray
);
889 /* Assign floppy drives */
890 DPRINT("Floppy drives: %d\n", ConfigInfo
->FloppyCount
);
891 for (i
= 0; i
< ConfigInfo
->FloppyCount
; i
++)
894 L
"\\Device\\Floppy%d",
896 RtlInitUnicodeString(&UnicodeString1
,
899 /* Assign drive letters A: or B: or first free drive letter */
902 HalpAssignDrive(&UnicodeString1
,
903 (i
< 2) ? i
: AUTO_DRIVE
,
904 DOSDEVICE_DRIVE_REMOVABLE
,
906 RtlConvertLongToLargeInteger(0),
912 /* Assign cdrom drives */
913 DPRINT("CD-Rom drives: %d\n", ConfigInfo
->CdRomCount
);
914 for (i
= 0; i
< ConfigInfo
->CdRomCount
; i
++)
917 L
"\\Device\\CdRom%d",
919 RtlInitUnicodeString(&UnicodeString1
,
922 /* Assign first free drive letter */
923 DPRINT(" %wZ\n", &UnicodeString1
);
924 HalpAssignDrive(&UnicodeString1
,
926 DOSDEVICE_DRIVE_CDROM
,
928 RtlConvertLongToLargeInteger(0),
934 /* Anything else to do? */
936 ExFreePool(PartialInformation
);
947 /* PRIVATE FUNCTIONS *********************************************************/
951 HalpGetFullGeometry(IN PDEVICE_OBJECT DeviceObject
,
952 IN PDISK_GEOMETRY Geometry
,
953 OUT PULONGLONG RealSectorCount
)
956 IO_STATUS_BLOCK IoStatusBlock
;
959 PARTITION_INFORMATION PartitionInfo
;
962 /* Allocate a non-paged event */
963 Event
= ExAllocatePoolWithTag(NonPagedPool
,
966 if (!Event
) return STATUS_INSUFFICIENT_RESOURCES
;
969 KeInitializeEvent(Event
, NotificationEvent
, FALSE
);
972 Irp
= IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_DRIVE_GEOMETRY
,
977 sizeof(DISK_GEOMETRY
),
983 /* Fail, free the event */
984 ExFreePoolWithTag(Event
, TAG_FILE_SYSTEM
);
985 return STATUS_INSUFFICIENT_RESOURCES
;
988 /* Call the driver and check if it's pending */
989 Status
= IoCallDriver(DeviceObject
, Irp
);
990 if (Status
== STATUS_PENDING
)
992 /* Wait on the driver */
993 KeWaitForSingleObject(Event
, Executive
, KernelMode
, FALSE
, NULL
);
994 Status
= IoStatusBlock
.Status
;
997 /* Check if the driver returned success */
998 if(NT_SUCCESS(Status
))
1000 /* Build another IRP */
1001 Irp
= IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_PARTITION_INFO
,
1006 sizeof(PARTITION_INFORMATION
),
1012 /* Fail, free the event */
1013 ExFreePoolWithTag(Event
, TAG_FILE_SYSTEM
);
1014 return STATUS_INSUFFICIENT_RESOURCES
;
1017 /* Call the driver and check if it's pending */
1018 Status
= IoCallDriver(DeviceObject
, Irp
);
1019 if (Status
== STATUS_PENDING
)
1021 /* Wait on the driver */
1022 KeWaitForSingleObject(Event
, Executive
, KernelMode
, FALSE
, NULL
);
1023 Status
= IoStatusBlock
.Status
;
1026 /* Check if the driver returned success */
1027 if(NT_SUCCESS(Status
))
1029 /* Get the number of sectors */
1030 *RealSectorCount
= (PartitionInfo
.PartitionLength
.QuadPart
/
1031 Geometry
->BytesPerSector
);
1035 /* Free the event and return the Status */
1036 ExFreePoolWithTag(Event
, TAG_FILE_SYSTEM
);
1042 HalpIsValidPartitionEntry(IN PPARTITION_DESCRIPTOR Entry
,
1043 IN ULONGLONG MaxOffset
,
1044 IN ULONGLONG MaxSector
)
1046 ULONGLONG EndingSector
;
1049 /* Unused partitions are considered valid */
1050 if (Entry
->PartitionType
== PARTITION_ENTRY_UNUSED
) return TRUE
;
1052 /* Get the last sector of the partition */
1053 EndingSector
= GET_STARTING_SECTOR(Entry
) + GET_PARTITION_LENGTH(Entry
);
1055 /* Check if it's more then the maximum sector */
1056 if (EndingSector
> MaxSector
)
1058 /* Invalid partition */
1059 DPRINT1("FSTUB: entry is invalid\n");
1060 DPRINT1("FSTUB: offset %#08lx\n", GET_STARTING_SECTOR(Entry
));
1061 DPRINT1("FSTUB: length %#08lx\n", GET_PARTITION_LENGTH(Entry
));
1062 DPRINT1("FSTUB: end %#I64x\n", EndingSector
);
1063 DPRINT1("FSTUB: max %#I64x\n", MaxSector
);
1066 else if(GET_STARTING_SECTOR(Entry
) > MaxOffset
)
1068 /* Invalid partition */
1069 DPRINT1("FSTUB: entry is invalid\n");
1070 DPRINT1("FSTUB: offset %#08lx\n", GET_STARTING_SECTOR(Entry
));
1071 DPRINT1("FSTUB: length %#08lx\n", GET_PARTITION_LENGTH(Entry
));
1072 DPRINT1("FSTUB: end %#I64x\n", EndingSector
);
1073 DPRINT1("FSTUB: maxOffset %#I64x\n", MaxOffset
);
1077 /* It's fine, return success */
1083 HalpCalculateChsValues(IN PLARGE_INTEGER PartitionOffset
,
1084 IN PLARGE_INTEGER PartitionLength
,
1085 IN CCHAR ShiftCount
,
1086 IN ULONG SectorsPerTrack
,
1087 IN ULONG NumberOfTracks
,
1088 IN ULONG ConventionalCylinders
,
1089 OUT PPARTITION_DESCRIPTOR PartitionDescriptor
)
1091 LARGE_INTEGER FirstSector
, SectorCount
;
1092 ULONG LastSector
, Remainder
, SectorsPerCylinder
;
1093 ULONG StartingCylinder
, EndingCylinder
;
1094 ULONG StartingTrack
, EndingTrack
;
1095 ULONG StartingSector
, EndingSector
;
1098 /* Calculate the number of sectors for each cylinder */
1099 SectorsPerCylinder
= SectorsPerTrack
* NumberOfTracks
;
1101 /* Calculate the first sector, and the sector count */
1102 FirstSector
.QuadPart
= PartitionOffset
->QuadPart
>> ShiftCount
;
1103 SectorCount
.QuadPart
= PartitionLength
->QuadPart
>> ShiftCount
;
1105 /* Now calculate the last sector */
1106 LastSector
= FirstSector
.LowPart
+ SectorCount
.LowPart
- 1;
1108 /* Calculate the first and last cylinders */
1109 StartingCylinder
= FirstSector
.LowPart
/ SectorsPerCylinder
;
1110 EndingCylinder
= LastSector
/ SectorsPerCylinder
;
1112 /* Set the default number of cylinders */
1113 if (!ConventionalCylinders
) ConventionalCylinders
= 1024;
1115 /* Normalize the values */
1116 if (StartingCylinder
>= ConventionalCylinders
)
1118 /* Set the maximum to 1023 */
1119 StartingCylinder
= ConventionalCylinders
- 1;
1121 if (EndingCylinder
>= ConventionalCylinders
)
1123 /* Set the maximum to 1023 */
1124 EndingCylinder
= ConventionalCylinders
- 1;
1127 /* Calculate the starting head and sector that still remain */
1128 Remainder
= FirstSector
.LowPart
% SectorsPerCylinder
;
1129 StartingTrack
= Remainder
/ SectorsPerTrack
;
1130 StartingSector
= Remainder
% SectorsPerTrack
;
1132 /* Calculate the ending head and sector that still remain */
1133 Remainder
= LastSector
% SectorsPerCylinder
;
1134 EndingTrack
= Remainder
/ SectorsPerTrack
;
1135 EndingSector
= Remainder
% SectorsPerTrack
;
1137 /* Set cylinder data for the MSB */
1138 PartitionDescriptor
->StartingCylinderMsb
= (UCHAR
)StartingCylinder
;
1139 PartitionDescriptor
->EndingCylinderMsb
= (UCHAR
)EndingCylinder
;
1141 /* Set the track data */
1142 PartitionDescriptor
->StartingTrack
= (UCHAR
)StartingTrack
;
1143 PartitionDescriptor
->EndingTrack
= (UCHAR
)EndingTrack
;
1145 /* Update cylinder data for the LSB */
1146 StartingCylinder
= ((StartingSector
+ 1) & 0x3F) |
1147 ((StartingCylinder
>> 2) & 0xC0);
1148 EndingCylinder
= ((EndingSector
+ 1) & 0x3F) |
1149 ((EndingCylinder
>> 2) & 0xC0);
1151 /* Set the cylinder data for the LSB */
1152 PartitionDescriptor
->StartingCylinderLsb
= (UCHAR
)StartingCylinder
;
1153 PartitionDescriptor
->EndingCylinderLsb
= (UCHAR
)EndingCylinder
;
1158 xHalGetPartialGeometry(IN PDEVICE_OBJECT DeviceObject
,
1159 IN PULONG ConventionalCylinders
,
1160 IN PLONGLONG DiskSize
)
1162 PDISK_GEOMETRY DiskGeometry
= NULL
;
1163 PIO_STATUS_BLOCK IoStatusBlock
= NULL
;
1164 PKEVENT Event
= NULL
;
1169 *ConventionalCylinders
= 0;
1172 /* Allocate the structure in nonpaged pool */
1173 DiskGeometry
= ExAllocatePoolWithTag(NonPagedPool
,
1174 sizeof(DISK_GEOMETRY
),
1176 if (!DiskGeometry
) goto Cleanup
;
1178 /* Allocate the status block in nonpaged pool */
1179 IoStatusBlock
= ExAllocatePoolWithTag(NonPagedPool
,
1180 sizeof(IO_STATUS_BLOCK
),
1182 if (!IoStatusBlock
) goto Cleanup
;
1184 /* Allocate the event in nonpaged pool too */
1185 Event
= ExAllocatePoolWithTag(NonPagedPool
,
1188 if (!Event
) goto Cleanup
;
1190 /* Initialize the event */
1191 KeInitializeEvent(Event
, NotificationEvent
, FALSE
);
1194 Irp
= IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_DRIVE_GEOMETRY
,
1199 sizeof(DISK_GEOMETRY
),
1203 if (!Irp
) goto Cleanup
;
1205 /* Now call the driver */
1206 Status
= IoCallDriver(DeviceObject
, Irp
);
1207 if (Status
== STATUS_PENDING
)
1209 /* Wait for it to complete */
1210 KeWaitForSingleObject(Event
, Executive
, KernelMode
, FALSE
, NULL
);
1211 Status
= IoStatusBlock
->Status
;
1214 /* Check driver status */
1215 if (NT_SUCCESS(Status
))
1217 /* Return the cylinder count */
1218 *ConventionalCylinders
= DiskGeometry
->Cylinders
.LowPart
;
1220 /* Make sure it's not larger then 1024 */
1221 if (DiskGeometry
->Cylinders
.LowPart
>= 1024)
1223 /* Otherwise, normalize the value */
1224 *ConventionalCylinders
= 1024;
1227 /* Calculate the disk size */
1228 *DiskSize
= DiskGeometry
->Cylinders
.QuadPart
*
1229 DiskGeometry
->TracksPerCylinder
*
1230 DiskGeometry
->SectorsPerTrack
*
1231 DiskGeometry
->BytesPerSector
;
1235 /* Free all the pointers */
1236 if (Event
) ExFreePoolWithTag(Event
, TAG_FILE_SYSTEM
);
1237 if (IoStatusBlock
) ExFreePool(IoStatusBlock
);
1238 if (DiskGeometry
) ExFreePool(DiskGeometry
);
1244 xHalExamineMBR(IN PDEVICE_OBJECT DeviceObject
,
1245 IN ULONG SectorSize
,
1246 IN ULONG MbrTypeIdentifier
,
1247 OUT PVOID
*MbrBuffer
)
1249 LARGE_INTEGER Offset
;
1253 IO_STATUS_BLOCK IoStatusBlock
;
1255 PPARTITION_DESCRIPTOR PartitionDescriptor
;
1257 PIO_STACK_LOCATION IoStackLocation
;
1258 Offset
.QuadPart
= 0;
1260 /* Assume failure */
1263 /* Normalize the buffer size */
1264 BufferSize
= max(SectorSize
, 512);
1266 /* Allocate the buffer */
1267 Buffer
= ExAllocatePoolWithTag(NonPagedPool
,
1268 PAGE_SIZE
> BufferSize
?
1269 PAGE_SIZE
: BufferSize
,
1271 if (!Buffer
) return;
1273 /* Initialize the Event */
1274 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
1277 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
1287 ExFreePoolWithTag(Buffer
, TAG_FILE_SYSTEM
);
1291 /* Make sure to override volume verification */
1292 IoStackLocation
= IoGetNextIrpStackLocation(Irp
);
1293 IoStackLocation
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
1295 /* Call the driver */
1296 Status
= IoCallDriver(DeviceObject
, Irp
);
1297 if (Status
== STATUS_PENDING
)
1299 /* Wait for completion */
1300 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
1301 Status
= IoStatusBlock
.Status
;
1304 /* Check driver Status */
1305 if (NT_SUCCESS(Status
))
1307 /* Validate the MBR Signature */
1308 if (((PUSHORT
)Buffer
)[BOOT_SIGNATURE_OFFSET
] != BOOT_RECORD_SIGNATURE
)
1311 ExFreePoolWithTag(Buffer
, TAG_FILE_SYSTEM
);
1315 /* Get the partition entry */
1316 PartitionDescriptor
= (PPARTITION_DESCRIPTOR
)
1317 &(((PUSHORT
)Buffer
)[PARTITION_TABLE_OFFSET
]);
1319 /* Make sure it's what the caller wanted */
1320 if (PartitionDescriptor
->PartitionType
!= MbrTypeIdentifier
)
1322 /* It's not, free our buffer */
1323 ExFreePoolWithTag(Buffer
, TAG_FILE_SYSTEM
);
1327 /* Check if this is a secondary entry */
1328 if (PartitionDescriptor
->PartitionType
== 0x54)
1330 /* Return our buffer, but at sector 63 */
1331 *(PULONG
)Buffer
= 63;
1332 *MbrBuffer
= Buffer
;
1334 else if (PartitionDescriptor
->PartitionType
== 0x55)
1336 /* EZ Drive, return the buffer directly */
1337 *MbrBuffer
= Buffer
;
1341 /* Otherwise crash on debug builds */
1342 ASSERT(PartitionDescriptor
->PartitionType
== 0x55);
1350 xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject
,
1351 IN ULONG SectorSize
,
1352 IN BOOLEAN ReturnRecognizedPartitions
,
1353 IN OUT PDRIVE_LAYOUT_INFORMATION
*PartitionBuffer
)
1356 IO_STATUS_BLOCK IoStatusBlock
;
1358 PPARTITION_DESCRIPTOR PartitionDescriptor
;
1361 PPARTITION_INFORMATION PartitionInfo
;
1362 PUCHAR Buffer
= NULL
;
1363 ULONG BufferSize
= 2048, InputSize
;
1364 PDRIVE_LAYOUT_INFORMATION DriveLayoutInfo
= NULL
;
1365 LONG j
= -1, i
= -1, k
;
1366 DISK_GEOMETRY DiskGeometry
;
1367 LONGLONG EndSector
, MaxSector
, StartOffset
;
1368 ULONGLONG MaxOffset
;
1369 LARGE_INTEGER Offset
, VolumeOffset
;
1370 BOOLEAN IsPrimary
= TRUE
, IsEzDrive
= FALSE
, MbrFound
= FALSE
;
1371 BOOLEAN IsValid
, IsEmpty
= TRUE
;
1373 PIO_STACK_LOCATION IoStackLocation
;
1374 PBOOT_SECTOR_INFO BootSectorInfo
= (PBOOT_SECTOR_INFO
)Buffer
;
1375 UCHAR PartitionType
;
1376 LARGE_INTEGER HiddenSectors64
;
1377 VolumeOffset
.QuadPart
= Offset
.QuadPart
= 0;
1380 /* Allocate the buffer */
1381 *PartitionBuffer
= ExAllocatePoolWithTag(NonPagedPool
,
1384 if (!(*PartitionBuffer
)) return STATUS_INSUFFICIENT_RESOURCES
;
1386 /* Normalize the buffer size */
1387 InputSize
= max(512, SectorSize
);
1389 /* Check for EZ Drive */
1390 HalExamineMBR(DeviceObject
, InputSize
, 0x55, &MbrBuffer
);
1393 /* EZ Drive found, bias the offset */
1395 ExFreePool(MbrBuffer
);
1396 Offset
.QuadPart
= 512;
1399 /* Get drive geometry */
1400 Status
= HalpGetFullGeometry(DeviceObject
, &DiskGeometry
, &MaxOffset
);
1401 if (!NT_SUCCESS(Status
))
1403 ExFreePoolWithTag(*PartitionBuffer
, TAG_FILE_SYSTEM
);
1404 *PartitionBuffer
= NULL
;
1408 /* Get the end and maximum sector */
1409 EndSector
= MaxOffset
;
1410 MaxSector
= MaxOffset
<< 1;
1411 DPRINT("FSTUB: MaxOffset = %#I64x, MaxSector = %#I64x\n",
1412 MaxOffset
, MaxSector
);
1414 /* Allocate our buffer */
1415 Buffer
= ExAllocatePoolWithTag(NonPagedPool
, PAGE_SIZE
, TAG_FILE_SYSTEM
);
1418 /* Fail, free the input buffer */
1419 ExFreePoolWithTag(*PartitionBuffer
, TAG_FILE_SYSTEM
);
1420 *PartitionBuffer
= NULL
;
1421 return STATUS_INSUFFICIENT_RESOURCES
;
1424 /* Start partition loop */
1427 /* Assume the partition is valid */
1430 /* Initialize the event */
1431 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
1433 /* Clear the buffer and build the IRP */
1434 RtlZeroMemory(Buffer
, InputSize
);
1435 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
1445 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1449 /* Make sure to disable volume verification */
1450 IoStackLocation
= IoGetNextIrpStackLocation(Irp
);
1451 IoStackLocation
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
1453 /* Call the driver */
1454 Status
= IoCallDriver(DeviceObject
, Irp
);
1455 if (Status
== STATUS_PENDING
)
1457 /* Wait for completion */
1458 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
1459 Status
= IoStatusBlock
.Status
;
1462 /* Normalize status code and check for failure */
1463 if (Status
== STATUS_NO_DATA_DETECTED
) Status
= STATUS_SUCCESS
;
1464 if (!NT_SUCCESS(Status
)) break;
1466 /* If we biased for EZ-Drive, unbias now */
1467 if (IsEzDrive
&& (Offset
.QuadPart
== 512)) Offset
.QuadPart
= 0;
1469 /* Make sure this is a valid MBR */
1470 if (((PUSHORT
)Buffer
)[BOOT_SIGNATURE_OFFSET
] != BOOT_RECORD_SIGNATURE
)
1472 /* It's not, fail */
1473 DPRINT1("FSTUB: (IoReadPartitionTable) No 0xaa55 found in "
1474 "partition table %d\n", j
+ 1);
1478 /* At this point we have a valid MBR */
1481 /* Check if we weren't given an offset */
1482 if (!Offset
.QuadPart
)
1484 /* Then read the signature off the disk */
1485 (*PartitionBuffer
)->Signature
= ((PULONG
)Buffer
)
1486 [PARTITION_TABLE_OFFSET
/ 2 - 1];
1489 /* Get the partition descriptor array */
1490 PartitionDescriptor
= (PPARTITION_DESCRIPTOR
)
1491 &(((PUSHORT
)Buffer
)[PARTITION_TABLE_OFFSET
]);
1493 /* Get the partition type */
1494 PartitionType
= PartitionDescriptor
->PartitionType
;
1496 /* Start looping partitions */
1498 DPRINT("FSTUB: Partition Table %d:\n", j
);
1499 for (Entry
= 1, k
= 0; Entry
<= 4; Entry
++, PartitionDescriptor
++)
1501 /* Get the partition type */
1502 PartitionType
= PartitionDescriptor
->PartitionType
;
1504 /* Print debug messages */
1505 DPRINT("Partition Entry %d,%d: type %#x %s\n",
1509 (PartitionDescriptor
->ActiveFlag
) ? "Active" : "");
1510 DPRINT("\tOffset %#08lx for %#08lx Sectors\n",
1511 GET_STARTING_SECTOR(PartitionDescriptor
),
1512 GET_PARTITION_LENGTH(PartitionDescriptor
));
1514 /* Make sure that the partition is valid, unless it's the first */
1515 if (!(HalpIsValidPartitionEntry(PartitionDescriptor
,
1517 MaxSector
)) && !(j
))
1519 /* It's invalid, so fail */
1524 /* Check if it's a container */
1525 if (IsContainerPartition(PartitionType
))
1527 /* Increase the count of containers */
1530 /* More then one table is invalid */
1531 DPRINT1("FSTUB: Multiple container partitions found in "
1532 "partition table %d\n - table is invalid\n",
1539 /* Check if the partition is supposedly empty */
1542 /* But check if it actually has a start and/or length */
1543 if ((GET_STARTING_SECTOR(PartitionDescriptor
)) ||
1544 (GET_PARTITION_LENGTH(PartitionDescriptor
)))
1546 /* So then it's not really empty */
1551 /* Check if the caller wanted only recognized partitions */
1552 if (ReturnRecognizedPartitions
)
1554 /* Then check if this one is unused, or a container */
1555 if ((PartitionType
== PARTITION_ENTRY_UNUSED
) ||
1556 IsContainerPartition(PartitionType
))
1558 /* Skip it, since the caller doesn't want it */
1563 /* Increase the structure count and check if they can fit */
1564 if ((sizeof(DRIVE_LAYOUT_INFORMATION
) +
1565 (++i
* sizeof(PARTITION_INFORMATION
))) >
1568 /* Allocate a new buffer that's twice as big */
1569 DriveLayoutInfo
= ExAllocatePoolWithTag(NonPagedPool
,
1572 if (!DriveLayoutInfo
)
1574 /* Out of memory, unto this extra structure */
1576 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1580 /* Copy the contents of the old buffer */
1581 RtlMoveMemory(DriveLayoutInfo
,
1585 /* Free the old buffer and set this one as the new one */
1586 ExFreePoolWithTag(*PartitionBuffer
, TAG_FILE_SYSTEM
);
1587 *PartitionBuffer
= DriveLayoutInfo
;
1589 /* Double the size */
1593 /* Now get the current structure being filled and initialize it */
1594 PartitionInfo
= &(*PartitionBuffer
)->PartitionEntry
[i
];
1595 PartitionInfo
->PartitionType
= PartitionType
;
1596 PartitionInfo
->RewritePartition
= FALSE
;
1598 /* Check if we're dealing with a partition that's in use */
1599 if (PartitionType
!= PARTITION_ENTRY_UNUSED
)
1601 /* Check if it's bootable */
1602 PartitionInfo
->BootIndicator
= PartitionDescriptor
->
1606 /* Check if its' a container */
1607 if (IsContainerPartition(PartitionType
))
1609 /* Then don't recognize it and use the volume offset */
1610 PartitionInfo
->RecognizedPartition
= FALSE
;
1611 StartOffset
= VolumeOffset
.QuadPart
;
1615 /* Then recognize it and use the partition offset */
1616 PartitionInfo
->RecognizedPartition
= TRUE
;
1617 StartOffset
= Offset
.QuadPart
;
1620 /* Get the starting offset */
1621 PartitionInfo
->StartingOffset
.QuadPart
=
1623 UInt32x32To64(GET_STARTING_SECTOR(PartitionDescriptor
),
1626 /* Calculate the number of hidden sectors */
1627 HiddenSectors64
.QuadPart
= (PartitionInfo
->
1628 StartingOffset
.QuadPart
-
1631 PartitionInfo
->HiddenSectors
= HiddenSectors64
.LowPart
;
1633 /* Get the partition length */
1634 PartitionInfo
->PartitionLength
.QuadPart
=
1635 UInt32x32To64(GET_PARTITION_LENGTH(PartitionDescriptor
),
1638 /* FIXME: REACTOS HACK */
1639 PartitionInfo
->PartitionNumber
= i
+ 1;
1643 /* Otherwise, clear all the relevant fields */
1644 PartitionInfo
->BootIndicator
= FALSE
;
1645 PartitionInfo
->RecognizedPartition
= FALSE
;
1646 PartitionInfo
->StartingOffset
.QuadPart
= 0;
1647 PartitionInfo
->PartitionLength
.QuadPart
= 0;
1648 PartitionInfo
->HiddenSectors
= 0;
1650 /* FIXME: REACTOS HACK */
1651 PartitionInfo
->PartitionNumber
= 0;
1655 /* Finish debug log, and check for failure */
1657 if (!NT_SUCCESS(Status
)) break;
1659 /* Also check if we hit an invalid entry here */
1662 /* We did, so break out of the loop minus one entry */
1667 /* Reset the offset */
1668 Offset
.QuadPart
= 0;
1670 /* Go back to the descriptor array and loop it */
1671 PartitionDescriptor
= (PPARTITION_DESCRIPTOR
)
1672 &(((PUSHORT
)Buffer
)[PARTITION_TABLE_OFFSET
]);
1673 for (Entry
= 1; Entry
<= 4; Entry
++, PartitionDescriptor
++)
1675 /* Check if this is a container partition, since we skipped them */
1676 if (IsContainerPartition(PartitionType
))
1678 /* Get its offset */
1679 Offset
.QuadPart
= VolumeOffset
.QuadPart
+
1681 GET_STARTING_SECTOR(PartitionDescriptor
),
1684 /* If this is a primary partition, this is the volume offset */
1685 if (IsPrimary
) VolumeOffset
= Offset
;
1687 /* Also update the maximum sector */
1688 MaxSector
= GET_PARTITION_LENGTH(PartitionDescriptor
);
1689 DPRINT1("FSTUB: MaxSector now = %#08lx\n", MaxSector
);
1694 /* Loop the next partitions, which are not primary anymore */
1696 } while (Offset
.HighPart
| Offset
.LowPart
);
1698 /* Check if this is a removable device that's probably a super-floppy */
1699 if ((DiskGeometry
.MediaType
== RemovableMedia
) &&
1704 /* Read the jump bytes to detect super-floppy */
1705 if ((BootSectorInfo
->JumpByte
[0] == 0xeb) ||
1706 (BootSectorInfo
->JumpByte
[0] == 0xe9))
1708 /* Super floppes don't have typical MBRs, so skip them */
1709 DPRINT1("FSTUB: Jump byte %#x found along with empty partition "
1710 "table - disk is a super floppy and has no valid MBR\n",
1711 BootSectorInfo
->JumpByte
);
1716 /* Check if we're still at partition -1 */
1719 /* The likely cause is the super floppy detection above */
1720 if ((MbrFound
) || (DiskGeometry
.MediaType
== RemovableMedia
))
1722 /* Print out debugging information */
1723 DPRINT1("FSTUB: Drive %#p has no valid MBR. Make it into a "
1726 DPRINT1("FSTUB: Drive has %#08lx sectors and is %#016I64x "
1728 EndSector
, EndSector
* DiskGeometry
.BytesPerSector
);
1730 /* We should at least have some sectors */
1733 /* Get the entry we'll use */
1734 PartitionInfo
= &(*PartitionBuffer
)->PartitionEntry
[0];
1736 /* Fill it out with data for a super-floppy */
1737 PartitionInfo
->RewritePartition
= FALSE
;
1738 PartitionInfo
->RecognizedPartition
= TRUE
;
1739 PartitionInfo
->PartitionType
= PARTITION_FAT_16
;
1740 PartitionInfo
->BootIndicator
= FALSE
;
1741 PartitionInfo
->HiddenSectors
= 0;
1742 PartitionInfo
->StartingOffset
.QuadPart
= 0;
1743 PartitionInfo
->PartitionLength
.QuadPart
= (EndSector
*
1747 /* FIXME: REACTOS HACK */
1748 PartitionInfo
->PartitionNumber
= 0;
1750 /* Set the signature and set the count back to 0 */
1751 (*PartitionBuffer
)->Signature
= 1;
1757 /* Otherwise, this isn't a super floppy, so set an invalid count */
1762 /* Set the partition count */
1763 (*PartitionBuffer
)->PartitionCount
= ++i
;
1765 /* If we have no count, delete the signature */
1766 if (!i
) (*PartitionBuffer
)->Signature
= 0;
1768 /* Free the buffer and check for success */
1769 if (Buffer
) ExFreePoolWithTag(Buffer
, TAG_FILE_SYSTEM
);
1770 if (!NT_SUCCESS(Status
)) ExFreePoolWithTag(*PartitionBuffer
, TAG_FILE_SYSTEM
);
1778 xHalIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject
,
1779 IN ULONG SectorSize
,
1780 IN ULONG PartitionNumber
,
1781 IN ULONG PartitionType
)
1785 IO_STATUS_BLOCK IoStatusBlock
;
1787 LARGE_INTEGER Offset
, VolumeOffset
;
1788 PUCHAR Buffer
= NULL
;
1792 PPARTITION_DESCRIPTOR PartitionDescriptor
;
1793 BOOLEAN IsPrimary
= TRUE
, IsEzDrive
= FALSE
;
1795 PIO_STACK_LOCATION IoStackLocation
;
1796 VolumeOffset
.QuadPart
= Offset
.QuadPart
= 0;
1799 /* Normalize the buffer size */
1800 BufferSize
= max(512, SectorSize
);
1802 /* Check for EZ Drive */
1803 HalExamineMBR(DeviceObject
, BufferSize
, 0x55, &MbrBuffer
);
1806 /* EZ Drive found, bias the offset */
1808 ExFreePool(MbrBuffer
);
1809 Offset
.QuadPart
= 512;
1812 /* Allocate our partition buffer */
1813 Buffer
= ExAllocatePoolWithTag(NonPagedPool
, PAGE_SIZE
, TAG_FILE_SYSTEM
);
1814 if (!Buffer
) return STATUS_INSUFFICIENT_RESOURCES
;
1816 /* Initialize the event we'll use and loop partitions */
1817 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
1820 /* Reset the event since we reuse it */
1821 KeResetEvent(&Event
);
1823 /* Build the read IRP */
1824 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
1834 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1838 /* Make sure to disable volume verification */
1839 IoStackLocation
= IoGetNextIrpStackLocation(Irp
);
1840 IoStackLocation
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
1842 /* Call the driver */
1843 Status
= IoCallDriver(DeviceObject
, Irp
);
1844 if (Status
== STATUS_PENDING
)
1846 /* Wait for completion */
1847 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
1848 Status
= IoStatusBlock
.Status
;
1851 /* Check for failure */
1852 if (!NT_SUCCESS(Status
)) break;
1854 /* If we biased for EZ-Drive, unbias now */
1855 if (IsEzDrive
&& (Offset
.QuadPart
== 512)) Offset
.QuadPart
= 0;
1857 /* Make sure this is a valid MBR */
1858 if (((PUSHORT
)Buffer
)[BOOT_SIGNATURE_OFFSET
] != BOOT_RECORD_SIGNATURE
)
1860 /* It's not, fail */
1861 Status
= STATUS_BAD_MASTER_BOOT_RECORD
;
1865 /* Get the partition descriptors and loop them */
1866 PartitionDescriptor
= (PPARTITION_DESCRIPTOR
)
1867 &(((PUSHORT
)Buffer
)[PARTITION_TABLE_OFFSET
]);
1868 for (Entry
= 1; Entry
<= 4; Entry
++, PartitionDescriptor
++)
1870 /* Check if it's unused or a container partition */
1871 if ((PartitionDescriptor
->PartitionType
==
1872 PARTITION_ENTRY_UNUSED
) ||
1873 (IsContainerPartition(PartitionDescriptor
->PartitionType
)))
1875 /* Go to the next one */
1879 /* It's a valid partition, so increase the partition count */
1880 if (++i
== PartitionNumber
)
1882 /* We found a match, set the type */
1883 PartitionDescriptor
->PartitionType
= (UCHAR
)PartitionType
;
1885 /* Reset the reusable event */
1886 KeResetEvent(&Event
);
1888 /* Build the write IRP */
1889 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_WRITE
,
1899 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1903 /* Disable volume verification */
1904 IoStackLocation
= IoGetNextIrpStackLocation(Irp
);
1905 IoStackLocation
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
1907 /* Call the driver */
1908 Status
= IoCallDriver(DeviceObject
, Irp
);
1909 if (Status
== STATUS_PENDING
)
1911 /* Wait for completion */
1912 KeWaitForSingleObject(&Event
,
1917 Status
= IoStatusBlock
.Status
;
1920 /* We're done, break out of the loop */
1925 /* If we looped all the partitions, break out */
1926 if (Entry
<= NUM_PARTITION_TABLE_ENTRIES
) break;
1928 /* Nothing found yet, get the partition array again */
1929 PartitionDescriptor
= (PPARTITION_DESCRIPTOR
)
1930 &(((PUSHORT
)Buffer
)[PARTITION_TABLE_OFFSET
]);
1931 for (Entry
= 1; Entry
<= 4; Entry
++, PartitionDescriptor
++)
1933 /* Check if this was a container partition (we skipped these) */
1934 if (IsContainerPartition(PartitionDescriptor
->PartitionType
))
1936 /* Update the partition offset */
1937 Offset
.QuadPart
= VolumeOffset
.QuadPart
+
1938 GET_STARTING_SECTOR(PartitionDescriptor
) *
1941 /* If this was the primary partition, update the volume too */
1942 if (IsPrimary
) VolumeOffset
= Offset
;
1947 /* Check if we already searched all the partitions */
1948 if (Entry
> NUM_PARTITION_TABLE_ENTRIES
)
1950 /* Then we failed to find a good MBR */
1951 Status
= STATUS_BAD_MASTER_BOOT_RECORD
;
1955 /* Loop the next partitions, which are not primary anymore */
1957 } while (i
< PartitionNumber
);
1959 /* Everything done, cleanup */
1960 if (Buffer
) ExFreePool(Buffer
);
1966 xHalIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject
,
1967 IN ULONG SectorSize
,
1968 IN ULONG SectorsPerTrack
,
1969 IN ULONG NumberOfHeads
,
1970 IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer
)
1973 IO_STATUS_BLOCK IoStatusBlock
;
1975 NTSTATUS Status
= STATUS_SUCCESS
;
1979 PPARTITION_TABLE PartitionTable
;
1980 LARGE_INTEGER Offset
, NextOffset
, ExtendedOffset
, SectorOffset
;
1981 LARGE_INTEGER StartOffset
, PartitionLength
;
1984 BOOLEAN IsEzDrive
= FALSE
, IsSuperFloppy
= FALSE
, DoRewrite
= FALSE
, IsMbr
;
1985 ULONG ConventionalCylinders
;
1987 PDISK_LAYOUT DiskLayout
= (PDISK_LAYOUT
)PartitionBuffer
;
1989 UCHAR PartitionType
;
1990 PIO_STACK_LOCATION IoStackLocation
;
1991 PPARTITION_INFORMATION PartitionInfo
= PartitionBuffer
->PartitionEntry
;
1992 PPARTITION_INFORMATION TableEntry
;
1993 ExtendedOffset
.QuadPart
= NextOffset
.QuadPart
= Offset
.QuadPart
= 0;
1996 /* Normalize the buffer size */
1997 BufferSize
= max(512, SectorSize
);
1999 /* Get the partial drive geometry */
2000 xHalGetPartialGeometry(DeviceObject
, &ConventionalCylinders
, &DiskSize
);
2002 /* Check for EZ Drive */
2003 HalExamineMBR(DeviceObject
, BufferSize
, 0x55, &MbrBuffer
);
2006 /* EZ Drive found, bias the offset */
2008 ExFreePool(MbrBuffer
);
2009 Offset
.QuadPart
= 512;
2012 /* Get the number of bits to shift to multiply by the sector size */
2013 for (k
= 0; k
< 32; k
++) if ((SectorSize
>> k
) == 1) break;
2015 /* Check if there's only one partition */
2016 if (PartitionBuffer
->PartitionCount
== 1)
2018 /* Check if it has no starting offset or hidden sectors */
2019 if (!(PartitionInfo
->StartingOffset
.QuadPart
) &&
2020 !(PartitionInfo
->HiddenSectors
))
2022 /* Then it's a super floppy */
2023 IsSuperFloppy
= TRUE
;
2025 /* Which also means it must be non-bootable FAT-16 */
2026 if ((PartitionInfo
->PartitionNumber
) ||
2027 (PartitionInfo
->PartitionType
!= PARTITION_FAT_16
) ||
2028 (PartitionInfo
->BootIndicator
))
2030 /* It's not, so we fail */
2031 return STATUS_INVALID_PARAMETER
;
2034 /* Check if it needs a rewrite, and disable EZ drive for sure */
2035 if (PartitionInfo
->RewritePartition
) DoRewrite
= TRUE
;
2040 /* Count the number of partition tables */
2041 DiskLayout
->TableCount
= (PartitionBuffer
->PartitionCount
+ 4 - 1) / 4;
2043 /* Allocate our partition buffer */
2044 Buffer
= ExAllocatePoolWithTag(NonPagedPool
, PAGE_SIZE
, TAG_FILE_SYSTEM
);
2045 if (!Buffer
) return STATUS_INSUFFICIENT_RESOURCES
;
2047 /* Loop the entries */
2048 Entry
= (PPTE
)&Buffer
[PARTITION_TABLE_OFFSET
];
2049 for (i
= 0; i
< DiskLayout
->TableCount
; i
++)
2051 /* Set if this is the MBR partition */
2054 /* Initialize th event */
2055 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
2057 /* Build the read IRP */
2058 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
2068 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2072 /* Make sure to disable volume verification */
2073 IoStackLocation
= IoGetNextIrpStackLocation(Irp
);
2074 IoStackLocation
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
2076 /* Call the driver */
2077 Status
= IoCallDriver(DeviceObject
, Irp
);
2078 if (Status
== STATUS_PENDING
)
2080 /* Wait for completion */
2081 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
2082 Status
= IoStatusBlock
.Status
;
2085 /* Check for failure */
2086 if (!NT_SUCCESS(Status
)) break;
2088 /* If we biased for EZ-Drive, unbias now */
2089 if (IsEzDrive
&& (Offset
.QuadPart
== 512)) Offset
.QuadPart
= 0;
2091 /* Check if this is a normal disk */
2094 /* Set the boot record signature */
2095 Buffer
[BOOT_SIGNATURE_OFFSET
] = BOOT_RECORD_SIGNATURE
;
2097 /* By default, don't require a rewrite */
2100 /* Check if we don't have an offset */
2101 if (!Offset
.QuadPart
)
2103 /* Check if the signature doesn't match */
2104 if (((PULONG
)Buffer
)[PARTITION_TABLE_OFFSET
/ 2 - 1] !=
2105 PartitionBuffer
->Signature
)
2107 /* Then write the signature and now w need a rewrite */
2108 ((PULONG
)Buffer
)[PARTITION_TABLE_OFFSET
/ 2 - 1] =
2109 PartitionBuffer
->Signature
;
2114 /* Loop the partition table entries */
2115 PartitionTable
= &DiskLayout
->PartitionTable
[i
];
2116 for (j
= 0; j
< 4; j
++)
2118 /* Get the current entry and type */
2119 TableEntry
= &PartitionTable
->PartitionEntry
[j
];
2120 PartitionType
= TableEntry
->PartitionType
;
2122 /* Check if the entry needs a rewrite */
2123 if (TableEntry
->RewritePartition
)
2125 /* Then we need one too */
2128 /* Save the type and if it's a bootable partition */
2129 Entry
[j
].PartitionType
= TableEntry
->PartitionType
;
2130 Entry
[j
].ActiveFlag
= TableEntry
->BootIndicator
? 0x80 : 0;
2132 /* Make sure it's used */
2133 if (PartitionType
!= PARTITION_ENTRY_UNUSED
)
2135 /* Make sure it's not a container (unless primary) */
2136 if ((IsMbr
) || !(IsContainerPartition(PartitionType
)))
2138 /* Use the partition offset */
2139 StartOffset
.QuadPart
= Offset
.QuadPart
;
2143 /* Use the extended logical partition offset */
2144 StartOffset
.QuadPart
= ExtendedOffset
.QuadPart
;
2147 /* Set the sector offset */
2148 SectorOffset
.QuadPart
= TableEntry
->
2149 StartingOffset
.QuadPart
-
2150 StartOffset
.QuadPart
;
2152 /* Now calculate the starting sector */
2153 StartOffset
.QuadPart
= SectorOffset
.QuadPart
>> k
;
2154 Entry
[j
].StartingSector
= StartOffset
.LowPart
;
2156 /* As well as the length */
2157 PartitionLength
.QuadPart
= TableEntry
->PartitionLength
.
2159 Entry
[j
].PartitionLength
= PartitionLength
.LowPart
;
2161 /* Calculate the CHS values */
2162 HalpCalculateChsValues(&TableEntry
->StartingOffset
,
2163 &TableEntry
->PartitionLength
,
2167 ConventionalCylinders
,
2168 (PPARTITION_DESCRIPTOR
)
2173 /* Otherwise set up an empty entry */
2174 Entry
[j
].StartingSector
= 0;
2175 Entry
[j
].PartitionLength
= 0;
2176 Entry
[j
].StartingTrack
= 0;
2177 Entry
[j
].EndingTrack
= 0;
2178 Entry
[j
].StartingCylinder
= 0;
2179 Entry
[j
].EndingCylinder
= 0;
2183 /* Check if this is a container partition */
2184 if (IsContainerPartition(PartitionType
))
2186 /* Then update the offset to use */
2187 NextOffset
= TableEntry
->StartingOffset
;
2192 /* Check if we need to write back the buffer */
2195 /* We don't need to do this again */
2198 /* Initialize the event */
2199 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
2201 /* If we unbiased for EZ-Drive, rebias now */
2202 if ((IsEzDrive
) && !(Offset
.QuadPart
)) Offset
.QuadPart
= 512;
2204 /* Build the write IRP */
2205 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_WRITE
,
2215 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2219 /* Make sure to disable volume verification */
2220 IoStackLocation
= IoGetNextIrpStackLocation(Irp
);
2221 IoStackLocation
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
2223 /* Call the driver */
2224 Status
= IoCallDriver(DeviceObject
, Irp
);
2225 if (Status
== STATUS_PENDING
)
2227 /* Wait for completion */
2228 KeWaitForSingleObject(&Event
,
2233 Status
= IoStatusBlock
.Status
;
2236 /* Check for failure */
2237 if (!NT_SUCCESS(Status
)) break;
2239 /* If we biased for EZ-Drive, unbias now */
2240 if (IsEzDrive
&& (Offset
.QuadPart
== 512)) Offset
.QuadPart
= 0;
2243 /* Update the partition offset and set the extended offset if needed */
2244 Offset
= NextOffset
;
2245 if (IsMbr
) ExtendedOffset
= NextOffset
;
2248 /* If we had a buffer, free it, then return status */
2249 if (Buffer
) ExFreePoolWithTag(Buffer
, TAG_FILE_SYSTEM
);
2253 /* PUBLIC FUNCTIONS **********************************************************/
2260 HalExamineMBR(IN PDEVICE_OBJECT DeviceObject
,
2261 IN ULONG SectorSize
,
2262 IN ULONG MbrTypeIdentifier
,
2263 OUT PVOID
*MbrBuffer
)
2265 HALDISPATCH
->HalExamineMBR(DeviceObject
,
2276 IoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject
,
2277 IN ULONG SectorSize
,
2278 IN BOOLEAN ReturnRecognizedPartitions
,
2279 IN OUT PDRIVE_LAYOUT_INFORMATION
*PartitionBuffer
)
2281 return HALDISPATCH
->HalIoReadPartitionTable(DeviceObject
,
2283 ReturnRecognizedPartitions
,
2292 IoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject
,
2293 IN ULONG SectorSize
,
2294 IN ULONG PartitionNumber
,
2295 IN ULONG PartitionType
)
2297 return HALDISPATCH
->HalIoSetPartitionInformation(DeviceObject
,
2308 IoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject
,
2309 IN ULONG SectorSize
,
2310 IN ULONG SectorsPerTrack
,
2311 IN ULONG NumberOfHeads
,
2312 IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer
)
2314 return HALDISPATCH
->HalIoWritePartitionTable(DeviceObject
,
2326 IoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock
,
2327 IN PSTRING NtDeviceName
,
2328 OUT PUCHAR NtSystemPath
,
2329 OUT PSTRING NtSystemPathString
)
2331 HALDISPATCH
->HalIoAssignDriveLetters(LoaderBlock
,
2334 NtSystemPathString
);