ReactOS 0.4.16-dev-2613-g9533ad7
hal.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _PARTITION_DESCRIPTOR
 
struct  _BOOT_SECTOR_INFO
 
struct  _PARTITION_TABLE
 
struct  _DISK_LAYOUT
 
struct  _PTE
 

Macros

#define DISK_SIGNATURE_OFFSET   0x1B8
 
#define PARTITION_TABLE_OFFSET   0x1BE
 
#define BOOT_SIGNATURE_OFFSET   (0x200 - 2)
 
#define BOOT_RECORD_SIGNATURE   0xAA55
 
#define NUM_PARTITION_TABLE_ENTRIES   4
 
#define GET_STARTING_SECTOR(p)
 
#define GET_ENDING_S_OF_CHS(p)    ((UCHAR)((p)->EndingCylinderLsb & 0x3F))
 
#define GET_PARTITION_LENGTH(p)
 
#define SET_PARTITION_LENGTH(p, l)
 

Typedefs

typedef struct _PARTITION_DESCRIPTOR PARTITION_DESCRIPTOR
 
typedef struct _PARTITION_DESCRIPTORPPARTITION_DESCRIPTOR
 
typedef struct _BOOT_SECTOR_INFO BOOT_SECTOR_INFO
 
typedef struct _BOOT_SECTOR_INFOPBOOT_SECTOR_INFO
 
typedef struct _PARTITION_TABLE PARTITION_TABLE
 
typedef struct _PARTITION_TABLEPPARTITION_TABLE
 
typedef struct _DISK_LAYOUT DISK_LAYOUT
 
typedef struct _DISK_LAYOUTPDISK_LAYOUT
 
typedef struct _PTE PTE
 
typedef struct _PTEPPTE
 

Functions

VOID FASTCALL xHalExamineMBR (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG MbrTypeIdentifier, OUT PVOID *MbrBuffer)
 
VOID FASTCALL xHalIoAssignDriveLetters (IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN PSTRING NtDeviceName, OUT PUCHAR NtSystemPath, OUT PSTRING NtSystemPathString)
 
NTSTATUS FASTCALL xHalIoReadPartitionTable (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN BOOLEAN ReturnRecognizedPartitions, OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
 
NTSTATUS FASTCALL xHalIoSetPartitionInformation (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
 
NTSTATUS FASTCALL xHalIoWritePartitionTable (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG SectorsPerTrack, IN ULONG NumberOfHeads, IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer)
 
VOID NTAPI xHalHaltSystem (VOID)
 
VOID NTAPI xHalEndOfBoot (VOID)
 
VOID NTAPI xHalSetWakeEnable (IN BOOLEAN Enable)
 
UCHAR NTAPI xHalVectorToIDTEntry (IN ULONG Vector)
 
NTSTATUS NTAPI xHalGetInterruptTranslator (IN INTERFACE_TYPE ParentInterfaceType, IN ULONG ParentBusNumber, IN INTERFACE_TYPE BridgeInterfaceType, IN USHORT Size, IN USHORT Version, OUT PTRANSLATOR_INTERFACE Translator, OUT PULONG BridgeBusNumber)
 
PBUS_HANDLER FASTCALL xHalHandlerForBus (IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber)
 
VOID FASTCALL xHalReferenceHandler (IN PBUS_HANDLER BusHandler)
 
NTSTATUS NTAPI xHalInitPnpDriver (VOID)
 
NTSTATUS NTAPI xHalInitPowerManagement (IN PPM_DISPATCH_TABLE PmDriverDispatchTable, OUT PPM_DISPATCH_TABLE *PmHalDispatchTable)
 
NTSTATUS NTAPI xHalStartMirroring (VOID)
 
NTSTATUS NTAPI xHalEndMirroring (IN ULONG PassNumber)
 
NTSTATUS NTAPI xHalMirrorPhysicalMemory (IN PHYSICAL_ADDRESS PhysicalAddress, IN LARGE_INTEGER NumberOfBytes)
 
NTSTATUS NTAPI xHalQueryBusSlots (IN PBUS_HANDLER BusHandler, IN ULONG BufferSize, OUT PULONG SlotNumbers, OUT PULONG ReturnedLength)
 
NTSTATUS NTAPI xHalSetSystemInformation (IN HAL_SET_INFORMATION_CLASS InformationClass, IN ULONG BufferSize, IN PVOID Buffer)
 
NTSTATUS NTAPI xHalQuerySystemInformation (IN HAL_QUERY_INFORMATION_CLASS InformationClass, IN ULONG BufferSize, IN OUT PVOID Buffer, OUT PULONG ReturnedLength)
 
VOID NTAPI xHalLocateHiberRanges (IN PVOID MemoryMap)
 
NTSTATUS NTAPI xHalRegisterBusHandler (IN INTERFACE_TYPE InterfaceType, IN BUS_DATA_TYPE ConfigSpace, IN ULONG BusNumber, IN INTERFACE_TYPE ParentInterfaceType, IN ULONG ParentBusNumber, IN ULONG ContextSize, IN PINSTALL_BUS_HANDLER InstallCallback, OUT PBUS_HANDLER *BusHandler)
 
VOID NTAPI xHalSetWakeAlarm (IN ULONGLONG AlartTime, IN PTIME_FIELDS TimeFields)
 
BOOLEAN NTAPI xHalTranslateBusAddress (IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
 
NTSTATUS NTAPI xHalAllocateMapRegisters (IN PADAPTER_OBJECT AdapterObject, IN ULONG Unknown, IN ULONG Unknown2, PMAP_REGISTER_ENTRY Registers)
 
NTSTATUS NTAPI xKdSetupPciDeviceForDebugging (IN PVOID LoaderBlock OPTIONAL, IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice)
 
NTSTATUS NTAPI xKdReleasePciDeviceForDebugging (IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice)
 
PVOID NTAPI xKdGetAcpiTablePhase (IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock, IN ULONG Signature)
 
PVOID NTAPI MatchAll (IN PHYSICAL_ADDRESS PhysicalAddress, IN ULONG NumberPages, IN BOOLEAN FlushCurrentTLB)
 
VOID NTAPI xKdUnmapVirtualAddress (IN PVOID VirtualAddress, IN ULONG NumberPages, IN BOOLEAN FlushCurrentTLB)
 

Macro Definition Documentation

◆ BOOT_RECORD_SIGNATURE

#define BOOT_RECORD_SIGNATURE   0xAA55

Definition at line 247 of file hal.h.

◆ BOOT_SIGNATURE_OFFSET

#define BOOT_SIGNATURE_OFFSET   (0x200 - 2)

Definition at line 245 of file hal.h.

◆ DISK_SIGNATURE_OFFSET

#define DISK_SIGNATURE_OFFSET   0x1B8

Definition at line 243 of file hal.h.

◆ GET_ENDING_S_OF_CHS

#define GET_ENDING_S_OF_CHS (   p)     ((UCHAR)((p)->EndingCylinderLsb & 0x3F))

Definition at line 259 of file hal.h.

◆ GET_PARTITION_LENGTH

#define GET_PARTITION_LENGTH (   p)
Value:
((ULONG)((p)->PartitionLengthLsb0) + \
(ULONG)((p)->PartitionLengthLsb1 << 8 ) + \
(ULONG)((p)->PartitionLengthMsb0 << 16) + \
(ULONG)((p)->PartitionLengthMsb1 << 24))
GLfloat GLfloat p
Definition: glext.h:8902
uint32_t ULONG
Definition: typedefs.h:59

Definition at line 262 of file hal.h.

◆ GET_STARTING_SECTOR

#define GET_STARTING_SECTOR (   p)
Value:
((ULONG)((p)->StartingSectorLsb0) + \
(ULONG)((p)->StartingSectorLsb1 << 8 ) + \
(ULONG)((p)->StartingSectorMsb0 << 16) + \
(ULONG)((p)->StartingSectorMsb1 << 24))

Definition at line 253 of file hal.h.

◆ NUM_PARTITION_TABLE_ENTRIES

#define NUM_PARTITION_TABLE_ENTRIES   4

Definition at line 248 of file hal.h.

◆ PARTITION_TABLE_OFFSET

#define PARTITION_TABLE_OFFSET   0x1BE

Definition at line 244 of file hal.h.

◆ SET_PARTITION_LENGTH

#define SET_PARTITION_LENGTH (   p,
  l 
)
Value:
((p)->PartitionLengthLsb0 = (l) & 0xFF, \
(p)->PartitionLengthLsb1 = ((l) >> 8 ) & 0xFF, \
(p)->PartitionLengthMsb0 = ((l) >> 16) & 0xFF, \
(p)->PartitionLengthMsb1 = ((l) >> 24) & 0xFF)
r l[0]
Definition: byte_order.h:168

Definition at line 268 of file hal.h.

Typedef Documentation

◆ BOOT_SECTOR_INFO

◆ DISK_LAYOUT

◆ PARTITION_DESCRIPTOR

◆ PARTITION_TABLE

◆ PBOOT_SECTOR_INFO

◆ PDISK_LAYOUT

◆ PPARTITION_DESCRIPTOR

◆ PPARTITION_TABLE

◆ PPTE

typedef struct _PTE * PPTE

◆ PTE

typedef struct _PTE PTE

Function Documentation

◆ MatchAll()

PVOID NTAPI MatchAll ( IN PHYSICAL_ADDRESS  PhysicalAddress,
IN ULONG  NumberPages,
IN BOOLEAN  FlushCurrentTLB 
)

Definition at line 277 of file halstub.c.

280{
281 return NULL;
282}
#define NULL
Definition: types.h:112

◆ xHalAllocateMapRegisters()

NTSTATUS NTAPI xHalAllocateMapRegisters ( IN PADAPTER_OBJECT  AdapterObject,
IN ULONG  Unknown,
IN ULONG  Unknown2,
PMAP_REGISTER_ENTRY  Registers 
)

Definition at line 242 of file halstub.c.

246{
247 PAGED_CODE();
248
250}
#define PAGED_CODE()
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42

◆ xHalEndMirroring()

NTSTATUS NTAPI xHalEndMirroring ( IN ULONG  PassNumber)

Definition at line 146 of file halstub.c.

147{
149}
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48

◆ xHalEndOfBoot()

VOID NTAPI xHalEndOfBoot ( VOID  )

Definition at line 88 of file halstub.c.

89{
90 PAGED_CODE();
91
92 /* Nothing */
93 return;
94}

◆ xHalExamineMBR()

VOID FASTCALL xHalExamineMBR ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  SectorSize,
IN ULONG  MbrTypeIdentifier,
OUT PVOID MbrBuffer 
)

Definition at line 1529 of file disksup.c.

1533{
1535 PUCHAR Buffer;
1537 KEVENT Event;
1539 PIRP Irp;
1540 PPARTITION_DESCRIPTOR PartitionDescriptor;
1543
1544 Offset.QuadPart = 0;
1545
1546 /* Assume failure */
1547 *MbrBuffer = NULL;
1548
1549 /* Normalize the buffer size */
1550 BufferSize = max(512, SectorSize);
1551
1552 /* Allocate the buffer */
1556 if (!Buffer) return;
1557
1558 /* Initialize the Event */
1560
1561 /* Build the IRP */
1564 Buffer,
1565 BufferSize,
1566 &Offset,
1567 &Event,
1568 &IoStatusBlock);
1569 if (!Irp)
1570 {
1571 /* Failed */
1573 return;
1574 }
1575
1576 /* Make sure to override volume verification */
1579
1580 /* Call the driver */
1582 if (Status == STATUS_PENDING)
1583 {
1584 /* Wait for completion */
1587 }
1588
1589 /* Check driver status */
1590 if (NT_SUCCESS(Status))
1591 {
1592 /* Validate the MBR Signature */
1594 {
1595 /* Failed */
1597 return;
1598 }
1599
1600 /* Get the partition entry */
1601 PartitionDescriptor = (PPARTITION_DESCRIPTOR)&Buffer[PARTITION_TABLE_OFFSET];
1602
1603 /* Make sure it's what the caller wanted */
1604 if (PartitionDescriptor->PartitionType != MbrTypeIdentifier)
1605 {
1606 /* It's not, free our buffer */
1608 }
1609 else
1610 {
1611 /* Check for OnTrack Disk Manager 6.0 / EZ-Drive partitions */
1612
1613 if (PartitionDescriptor->PartitionType == PARTITION_DM)
1614 {
1615 /* Return our buffer, but at sector 63 */
1616 *(PULONG)Buffer = 63;
1617 *MbrBuffer = Buffer;
1618 }
1619 else if (PartitionDescriptor->PartitionType == PARTITION_EZDRIVE)
1620 {
1621 /* EZ-Drive, return the buffer directly */
1622 *MbrBuffer = Buffer;
1623 }
1624 else
1625 {
1626 /* Otherwise crash on debug builds */
1627 ASSERT(PartitionDescriptor->PartitionType == PARTITION_EZDRIVE);
1628 }
1629 }
1630 }
1631}
LONG NTSTATUS
Definition: precomp.h:26
unsigned short * PUINT16
Definition: basetsd.h:186
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define BufferSize
Definition: mmc.h:75
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define NonPagedPool
Definition: env_spec_w32.h:307
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define KernelMode
Definition: asm.h:38
#define PARTITION_EZDRIVE
Definition: ntdddisk.h:289
#define PARTITION_DM
Definition: ntdddisk.h:288
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
@ NotificationEvent
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
struct _PARTITION_DESCRIPTOR * PPARTITION_DESCRIPTOR
#define PARTITION_TABLE_OFFSET
Definition: hal.h:244
#define BOOT_SIGNATURE_OFFSET
Definition: hal.h:245
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define IoCallDriver
Definition: irp.c:1225
#define BOOT_RECORD_SIGNATURE
Definition: parttest.c:17
#define IRP_MJ_READ
Definition: rdpdr.c:46
UCHAR PartitionType
Definition: hal.h:283
#define max(a, b)
Definition: svc.c:63
#define TAG_FILE_SYSTEM
Definition: tag.h:64
#define STATUS_PENDING
Definition: telnetd.h:14
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char * PUCHAR
Definition: typedefs.h:53
_In_ PIO_STACK_LOCATION IoStackLocation
Definition: usbdlib.h:265
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_In_ ULONG SectorSize
Definition: halfuncs.h:291
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1823
@ Executive
Definition: ketypes.h:467

◆ xHalGetInterruptTranslator()

NTSTATUS NTAPI xHalGetInterruptTranslator ( IN INTERFACE_TYPE  ParentInterfaceType,
IN ULONG  ParentBusNumber,
IN INTERFACE_TYPE  BridgeInterfaceType,
IN USHORT  Size,
IN USHORT  Version,
OUT PTRANSLATOR_INTERFACE  Translator,
OUT PULONG  BridgeBusNumber 
)

Definition at line 156 of file translate.c.

163{
164 PAGED_CODE();
165
167 ASSERT(Size >= sizeof(TRANSLATOR_INTERFACE));
168
169 /* Only (E)ISA interfaces are supported */
170 if (BridgeInterfaceType == Internal || BridgeInterfaceType >= MicroChannel)
171 {
173 }
174
175 /* Fill in output struct */
176 Translator->Size = sizeof(TRANSLATOR_INTERFACE);
177 Translator->Version = HAL_IRQ_TRANSLATOR_VERSION;
178 /* In case caller set interface to undefined, faulty it to ISA */
179 Translator->Context = UlongToPtr((BridgeInterfaceType == InterfaceTypeUndefined) ? Isa : BridgeInterfaceType);
180 Translator->InterfaceReference = FstubTranslatorNull;
181 Translator->InterfaceDereference = FstubTranslatorNull;
182 Translator->TranslateResources = FstubTranslateResource;
183 Translator->TranslateResourceRequirements = FstubTranslateRequirement;
184
185 return STATUS_SUCCESS;
186}
#define UlongToPtr(u)
Definition: config.h:106
#define HAL_IRQ_TRANSLATOR_VERSION
Definition: haltypes.h:2044
@ InterfaceTypeUndefined
Definition: restypes.h:120
@ Internal
Definition: restypes.h:121
@ MicroChannel
Definition: restypes.h:124
@ Isa
Definition: restypes.h:122
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI FstubTranslateRequirement(IN OUT PVOID Context OPTIONAL, IN PIO_RESOURCE_DESCRIPTOR Source, IN PDEVICE_OBJECT PhysicalDeviceObject, OUT PULONG TargetCount, OUT PIO_RESOURCE_DESCRIPTOR *Target)
Definition: translate.c:113
NTSTATUS NTAPI FstubTranslateResource(IN OUT PVOID Context OPTIONAL, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source, IN RESOURCE_TRANSLATION_DIRECTION Direction, IN ULONG AlternativesCount OPTIONAL, IN IO_RESOURCE_DESCRIPTOR Alternatives[], IN PDEVICE_OBJECT PhysicalDeviceObject, OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target)
Definition: translate.c:35
VOID NTAPI FstubTranslatorNull(PVOID Context)
Definition: translate.c:22
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
struct _TRANSLATOR_INTERFACE TRANSLATOR_INTERFACE

◆ xHalHaltSystem()

VOID NTAPI xHalHaltSystem ( VOID  )

Definition at line 39 of file halstub.c.

40{
41 /* Halt execution */
42 while (TRUE);
43}
#define TRUE
Definition: types.h:120

◆ xHalHandlerForBus()

PBUS_HANDLER FASTCALL xHalHandlerForBus ( IN INTERFACE_TYPE  InterfaceType,
IN ULONG  BusNumber 
)

Definition at line 106 of file halstub.c.

108{
109 return NULL;
110}

◆ xHalInitPnpDriver()

NTSTATUS NTAPI xHalInitPnpDriver ( VOID  )

Definition at line 122 of file halstub.c.

123{
125}

◆ xHalInitPowerManagement()

NTSTATUS NTAPI xHalInitPowerManagement ( IN PPM_DISPATCH_TABLE  PmDriverDispatchTable,
OUT PPM_DISPATCH_TABLE PmHalDispatchTable 
)

Definition at line 129 of file halstub.c.

131{
133}

◆ xHalIoAssignDriveLetters()

VOID FASTCALL xHalIoAssignDriveLetters ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock,
IN PSTRING  NtDeviceName,
OUT PUCHAR  NtSystemPath,
OUT PSTRING  NtSystemPathString 
)

Definition at line 890 of file disksup.c.

894{
895 PULONG Devices;
898 UCHAR DriveLetter;
899 BOOLEAN BootableFound;
900 IO_STATUS_BLOCK StatusBlock;
902 PSTR LoadOptions;
904 PDRIVE_LAYOUT_INFORMATION LayoutInfo;
907 ULONG i, Increment, DiskCount, RealDiskCount, HarddiskCount, PartitionCount;
908 ULONG SkipPartition;
909 PWSTR Buffer2;
910 WCHAR Buffer[sizeof("\\Device\\Harddisk4294967295\\Partition4294967295")];
911
912 PAGED_CODE();
913
914 /* Get our disk count */
915 ConfigInfo = IoGetConfigurationInformation();
916 DiskCount = ConfigInfo->DiskCount;
917 RealDiskCount = 0;
918
919 /* Allocate a generic string buffer we'll use later on */
920 Buffer2 = ExAllocatePoolWithTag(NonPagedPool, 40 * sizeof(WCHAR), TAG_FSTUB);
921 if (Buffer2 == NULL)
922 {
923 /* We cannot fail */
924 KeBugCheck(ASSIGN_DRIVE_LETTERS_FAILED);
925 }
926
927 /* In case of a remote boot, setup the system path */
929 {
930 PSTR Last, Saved;
931
932 /* Find the last separator */
933 Last = strrchr(LoaderBlock->NtBootPathName, '\\');
934 Saved = NULL;
935 if (Last == NULL)
936 {
937 /* Misformed name, fail */
938 KeBugCheck(ASSIGN_DRIVE_LETTERS_FAILED);
939 }
940
941 /* In case the name was terminated by a separator... */
942 if (Last[1] == ANSI_NULL)
943 {
944 /* Erase it, save its position and find the previous separator */
945 *Last = ANSI_NULL;
946 Saved = Last;
947 Last = strrchr(LoaderBlock->NtBootPathName, '\\');
948 *Saved = '\\';
949 }
950
951 if (Last == NULL)
952 {
953 /* Misformed name, fail */
954 KeBugCheck(ASSIGN_DRIVE_LETTERS_FAILED);
955 }
956
957 /* For a remote boot, assign X drive letter */
958 NtSystemPath[0] = 'X';
959 NtSystemPath[1] = ':';
960 /* And copy the end of the boot path */
961 strcpy((PSTR)&NtSystemPath[2], Last);
962
963 /* If we had to remove the trailing separator, remove it here too */
964 if (Saved != NULL)
965 {
966 NtSystemPath[strlen((PSTR)NtSystemPath) - 1] = ANSI_NULL;
967 }
968
969 /* Setup the system path string */
970 RtlInitString(NtSystemPathString, (PSTR)NtSystemPath);
971 }
972
973 /* For each disk, create the physical drive DOS device */
974 Increment = 0;
975 for (i = 0; i < DiskCount; ++i)
976 {
977 /* Setup the device name */
978 swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition0", i);
980
981 /* Open the device */
983 &DeviceName,
985 NULL,
986 NULL);
990 &StatusBlock,
993 if (NT_SUCCESS(Status))
994 {
995 /* If we succeeded, create the link */
996 UNICODE_STRING LinkName;
997 swprintf(Buffer2, L"\\DosDevices\\PhysicalDrive%d", i);
998 RtlInitUnicodeString(&LinkName, Buffer2);
999
1000 IoCreateSymbolicLink(&LinkName, &DeviceName);
1002
1003 RealDiskCount = i + 1;
1004 }
1005 else
1006 {
1007 /* Try to cope with holes in the \Device\HarddiskX namespace */
1008 if (Increment < 50)
1009 {
1010 ++Increment;
1011 ++DiskCount;
1012 }
1013 }
1014 }
1015
1016 /* We are done with the buffer */
1017 ExFreePoolWithTag(Buffer2, TAG_FSTUB);
1018
1019 /* Upcase the load options, if any */
1020 if (LoaderBlock->LoadOptions != NULL)
1021 LoadOptions = _strupr(LoaderBlock->LoadOptions);
1022 else
1023 LoadOptions = NULL;
1024
1025 /* If we boot with MININT option (system hive as volatile),
1026 * assign the X letter to the OS boot volume. */
1027 if (LoadOptions != NULL &&
1028 strstr(LoadOptions, "MININT") != NULL &&
1030 {
1032 *NtSystemPath = 'X';
1033
1035 }
1036
1037 /* Compute the disks derangements */
1038 DiskCount -= Increment;
1039 DiskCount = max(DiskCount, RealDiskCount);
1040 Devices = IopComputeHarddiskDerangements(DiskCount);
1041
1042 /* Now, start browsing all the disks for assigning drive letters.
1043 * Here, we'll only handle the bootable and primary partitions. */
1044 for (i = 0; i < DiskCount; ++i)
1045 {
1046 /* Get the device ID from the derangements map */
1047 HarddiskCount = (Devices ? Devices[i] : i);
1048
1049 /* Query the disk layout */
1050 swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition0", HarddiskCount);
1052 Status = HalpQueryDriveLayout(&DeviceName, &LayoutInfo);
1053 if (!NT_SUCCESS(Status))
1054 LayoutInfo = NULL;
1055
1056 /* Assume we didn't find a bootable partition */
1057 BootableFound = FALSE;
1058 for (PartitionCount = 1; ; ++PartitionCount)
1059 {
1060 swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1063 if (!NT_SUCCESS(Status))
1064 {
1065 /* It failed, retry for all the partitions */
1066 break;
1067 }
1068
1069 /* If the partition is bootable (MBR) or data (GPT), we've found it */
1071 {
1072 BootableFound = TRUE;
1073
1074 /* Assign a drive letter and stop here if MBR */
1075 HalpNextDriveLetter(&DeviceName, NtDeviceName, NtSystemPath, FALSE);
1077 break;
1078 }
1079 /* Keep looping on all the partitions */
1080 }
1081
1082 /* Mount every primary partition if we didn't find a bootable partition */
1083 if (!BootableFound)
1084 {
1085 for (PartitionCount = 1; ; ++PartitionCount)
1086 {
1087 swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1090 if (!NT_SUCCESS(Status))
1091 break;
1092
1093 /* We found a primary partition, assign a drive letter */
1095 {
1096 HalpNextDriveLetter(&DeviceName, NtDeviceName, NtSystemPath, FALSE);
1097 break;
1098 }
1099 }
1100 }
1101
1102 /* Free the layout, we'll reallocate it for the next disk */
1103 if (LayoutInfo != NULL)
1104 ExFreePoolWithTag(LayoutInfo, TAG_FSTUB);
1105 }
1106
1107 /* Now, assign drive letters to logical partitions */
1108 for (i = 0; i < DiskCount; ++i)
1109 {
1110 /* Get the device ID from the derangements map */
1111 HarddiskCount = (Devices ? Devices[i] : i);
1112
1113 /* Query the disk layout */
1114 swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition0", HarddiskCount);
1116 Status = HalpQueryDriveLayout(&DeviceName, &LayoutInfo);
1117 if (!NT_SUCCESS(Status))
1118 LayoutInfo = NULL;
1119
1120 /* And assign drive letters to logical partitions */
1121 for (PartitionCount = 1; ; ++PartitionCount)
1122 {
1123 swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1126 if (!NT_SUCCESS(Status))
1127 break;
1128
1130 {
1131 HalpNextDriveLetter(&DeviceName, NtDeviceName, NtSystemPath, FALSE);
1132 }
1133 }
1134
1135 /* Free the layout, we'll reallocate it for the next disk */
1136 if (LayoutInfo != NULL)
1137 ExFreePoolWithTag(LayoutInfo, TAG_FSTUB);
1138 }
1139
1140 /* Now, assign drive letters to everything else */
1141 for (i = 0; i < DiskCount; ++i)
1142 {
1143 /* Get the device ID from the derangements map */
1144 HarddiskCount = (Devices ? Devices[i] : i);
1145
1146 /* Query the disk layout */
1147 swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition0", HarddiskCount);
1149 Status = HalpQueryDriveLayout(&DeviceName, &LayoutInfo);
1150 if (!NT_SUCCESS(Status))
1151 LayoutInfo = NULL;
1152
1153 /* Save the bootable or first primary (MBR) partition, if any */
1154 SkipPartition = 0;
1155 for (PartitionCount = 1; ; ++PartitionCount)
1156 {
1157 swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1160 if (!NT_SUCCESS(Status))
1161 break;
1162
1164 ((PartitionType == PrimaryPartition) && (SkipPartition == 0)))
1165 {
1166 SkipPartition = PartitionCount;
1167 }
1168 }
1169
1170 /* And assign a drive letter to anything but the bootable partition */
1171 for (PartitionCount = 1; ; ++PartitionCount)
1172 {
1173 if (PartitionCount == SkipPartition)
1174 continue;
1175
1176 swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1179 if (!NT_SUCCESS(Status))
1180 break;
1181
1183 {
1184 HalpNextDriveLetter(&DeviceName, NtDeviceName, NtSystemPath, FALSE);
1185 }
1186 }
1187
1188 /* Free the layout, we'll reallocate it for the next disk */
1189 if (LayoutInfo != NULL)
1190 ExFreePoolWithTag(LayoutInfo, TAG_FSTUB);
1191 }
1192
1193 /* We're done with the disks; free the derangements map */
1194 if (Devices != NULL)
1195 ExFreePoolWithTag(Devices, TAG_FSTUB);
1196
1197 /* Now, assign drive letters to floppy devices:
1198 * first for legacy, then for MountMgr-aware ones. */
1199 for (i = 0; i < ConfigInfo->FloppyCount; ++i)
1200 {
1201 swprintf(Buffer, L"\\Device\\Floppy%d", i);
1203 if (HalpIsOldStyleFloppy(&DeviceName)) // Legacy device
1204 HalpNextDriveLetter(&DeviceName, NtDeviceName, NtSystemPath, TRUE);
1205 }
1206 for (i = 0; i < ConfigInfo->FloppyCount; ++i)
1207 {
1208 swprintf(Buffer, L"\\Device\\Floppy%d", i);
1210 if (!HalpIsOldStyleFloppy(&DeviceName)) // MountMgr-aware device
1211 HalpNextDriveLetter(&DeviceName, NtDeviceName, NtSystemPath, TRUE);
1212 }
1213
1214 /* And CD-ROM drives */
1215 for (i = 0; i < ConfigInfo->CdRomCount; ++i)
1216 {
1217 swprintf(Buffer, L"\\Device\\CdRom%d", i);
1219 HalpNextDriveLetter(&DeviceName, NtDeviceName, NtSystemPath, TRUE);
1220 }
1221
1222 /* If not remote boot, handle NtDeviceName */
1224 {
1225 /* Assign it a drive letter */
1226 DriveLetter = HalpNextDriveLetter(&DeviceName, NULL, NULL, TRUE);
1227 if (DriveLetter != 0)
1228 {
1229 if (DriveLetter != 0xFF)
1230 *NtSystemPath = DriveLetter;
1231 }
1232 /* If it fails through the MountMgr, retry manually */
1233 else
1234 {
1236 DriveLetter = 'A'; /* If floppy, start at A */
1238 DriveLetter = 'D'; /* If CD-ROM, start at D */
1239 else
1240 DriveLetter = 'C'; /* Otherwise, start at C */
1241
1242 /* Try any drive letter */
1243 while (HalpSetMountLetter(&DeviceName, DriveLetter) != STATUS_SUCCESS)
1244 {
1245 ++DriveLetter;
1246 if (DriveLetter > 'Z')
1247 break;
1248 }
1249
1250 /* If we're beyond Z (no letter left), delete Z and
1251 * reuse it for the OS boot volume (SystemRoot) */
1252 if (DriveLetter > 'Z')
1253 {
1254 DriveLetter = 'Z';
1255 HalpDeleteMountLetter(DriveLetter);
1256 HalpSetMountLetter(&DeviceName, DriveLetter);
1257 }
1258
1259 /* Return the matching drive letter */
1260 *NtSystemPath = DriveLetter;
1261 }
1262
1264 }
1265
1266 /* Enable auto assignment for MountMgr */
1268}
unsigned char BOOLEAN
Definition: actypes.h:127
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1434
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
static NTSTATUS HalpQueryDriveLayout(_In_ PUNICODE_STRING DeviceName, _Outptr_ PDRIVE_LAYOUT_INFORMATION *LayoutInfo)
Definition: disksup.c:46
enum _PARTITION_TYPE PARTITION_TYPE
static VOID HalpEnableAutomaticDriveLetterAssignment(VOID)
Definition: disksup.c:835
static PULONG IopComputeHarddiskDerangements(_In_ ULONG DiskCount)
Definition: disksup.c:309
static NTSTATUS HalpSetMountLetter(_In_ PUNICODE_STRING DeviceName, _In_ UCHAR DriveLetter)
Definition: disksup.c:518
static const UNICODE_STRING CdPrefix
Definition: disksup.c:41
@ DataPartition
Definition: disksup.c:37
@ PrimaryPartition
Definition: disksup.c:33
@ BootablePartition
Definition: disksup.c:32
@ LogicalPartition
Definition: disksup.c:34
@ FtPartition
Definition: disksup.c:35
static const UNICODE_STRING FloppyPrefix
Definition: disksup.c:40
static BOOLEAN HalpIsOldStyleFloppy(_In_ PUNICODE_STRING DeviceName)
Definition: disksup.c:683
static NTSTATUS HalpDeleteMountLetter(_In_ UCHAR DriveLetter)
Definition: disksup.c:743
static NTSTATUS HalpQueryPartitionType(_In_ PUNICODE_STRING DeviceName, _In_opt_ PDRIVE_LAYOUT_INFORMATION LayoutInfo, _Out_ PPARTITION_TYPE PartitionType)
Definition: disksup.c:156
static UCHAR HalpNextDriveLetter(_In_ PUNICODE_STRING DeviceName, _In_ PSTRING NtDeviceName, _Out_ PUCHAR NtSystemPath, _In_ BOOLEAN IsRemovable)
Definition: disksup.c:604
#define FILE_SHARE_READ
Definition: compat.h:136
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3415
_ACRTIMP char *__cdecl strrchr(const char *, int)
Definition: string.c:3298
#define swprintf
Definition: precomp.h:40
#define L(x)
Definition: resources.c:13
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:46
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
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
Definition: glfuncs.h:248
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Returns a pointer to the I/O manager's global configuration information structure.
Definition: iorsrce.c:998
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwOpenFile(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_READ_DATA
Definition: nt_native.h:628
NTSYSAPI VOID NTAPI RtlInitString(PSTRING DestinationString, PCSZ SourceString)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
#define ANSI_NULL
BOOLEAN IoRemoteBootClient
Definition: init.c:70
UCHAR PartitionType
Definition: part_brfr.c:23
short WCHAR
Definition: pedump.c:58
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_strupr
Definition: string.h:453
strcpy
Definition: string.h:131
#define TAG_FSTUB
Definition: tag.h:54
uint16_t * PWSTR
Definition: typedefs.h:56
char * PSTR
Definition: typedefs.h:51
unsigned char UCHAR
Definition: typedefs.h:53
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3281

◆ xHalIoReadPartitionTable()

NTSTATUS FASTCALL xHalIoReadPartitionTable ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  SectorSize,
IN BOOLEAN  ReturnRecognizedPartitions,
OUT PDRIVE_LAYOUT_INFORMATION PartitionBuffer 
)

Definition at line 17 of file halstub.c.

22{
27}
NTSTATUS FASTCALL IoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN BOOLEAN ReturnRecognizedPartitions, OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
Definition: ntoskrnl.c:115
_In_ ULONG _In_ BOOLEAN ReturnRecognizedPartitions
Definition: iofuncs.h:2051
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2052

◆ xHalIoSetPartitionInformation()

NTSTATUS FASTCALL xHalIoSetPartitionInformation ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  SectorSize,
IN ULONG  PartitionNumber,
IN ULONG  PartitionType 
)

Definition at line 2084 of file disksup.c.

2088{
2089 PIRP Irp;
2090 KEVENT Event;
2093 LARGE_INTEGER Offset, VolumeOffset;
2094 PUCHAR Buffer = NULL;
2096 ULONG i = 0;
2097 ULONG Entry;
2098 PPARTITION_DESCRIPTOR PartitionDescriptor;
2099 BOOLEAN IsPrimary = TRUE, IsEzDrive = FALSE;
2100 PVOID MbrBuffer;
2102
2103 PAGED_CODE();
2104
2105 VolumeOffset.QuadPart = Offset.QuadPart = 0;
2106
2107 /* Normalize the buffer size */
2108 BufferSize = max(512, SectorSize);
2109
2110 /* Check for EZ-Drive */
2112 if (MbrBuffer)
2113 {
2114 /* EZ-Drive found, bias the offset */
2115 IsEzDrive = TRUE;
2117 Offset.QuadPart = 512;
2118 }
2119
2120 /* Allocate our partition buffer */
2123
2124 /* Initialize the event we'll use and loop partitions */
2126 do
2127 {
2128 /* Reset the event since we reuse it */
2130
2131 /* Build the read IRP */
2134 Buffer,
2135 BufferSize,
2136 &Offset,
2137 &Event,
2138 &IoStatusBlock);
2139 if (!Irp)
2140 {
2141 /* Fail */
2143 break;
2144 }
2145
2146 /* Make sure to disable volume verification */
2149
2150 /* Call the driver */
2152 if (Status == STATUS_PENDING)
2153 {
2154 /* Wait for completion */
2157 }
2158
2159 /* Check for failure */
2160 if (!NT_SUCCESS(Status)) break;
2161
2162 /* If we biased for EZ-Drive, unbias now */
2163 if (IsEzDrive && (Offset.QuadPart == 512)) Offset.QuadPart = 0;
2164
2165 /* Make sure this is a valid MBR */
2167 {
2168 /* It's not, fail */
2170 break;
2171 }
2172
2173 /* Get the partition descriptors and loop them */
2174 PartitionDescriptor = (PPARTITION_DESCRIPTOR)&Buffer[PARTITION_TABLE_OFFSET];
2175 for (Entry = 1; Entry <= NUM_PARTITION_TABLE_ENTRIES; Entry++, PartitionDescriptor++)
2176 {
2177 /* Check if it's unused or a container partition */
2178 if ((PartitionDescriptor->PartitionType == PARTITION_ENTRY_UNUSED) ||
2179 (IsContainerPartition(PartitionDescriptor->PartitionType)))
2180 {
2181 /* Go to the next one */
2182 continue;
2183 }
2184
2185 /* It's a valid partition, so increase the partition count */
2186 if (++i == PartitionNumber)
2187 {
2188 /* We found a match, set the type */
2189 PartitionDescriptor->PartitionType = (UCHAR)PartitionType;
2190
2191 /* Reset the reusable event */
2193
2194 /* Build the write IRP */
2197 Buffer,
2198 BufferSize,
2199 &Offset,
2200 &Event,
2201 &IoStatusBlock);
2202 if (!Irp)
2203 {
2204 /* Fail */
2206 break;
2207 }
2208
2209 /* Disable volume verification */
2212
2213 /* Call the driver */
2215 if (Status == STATUS_PENDING)
2216 {
2217 /* Wait for completion */
2219 Executive,
2220 KernelMode,
2221 FALSE,
2222 NULL);
2224 }
2225
2226 /* We're done, break out of the loop */
2227 break;
2228 }
2229 }
2230
2231 /* If we looped all the partitions, break out */
2232 if (Entry <= NUM_PARTITION_TABLE_ENTRIES) break;
2233
2234 /* Nothing found yet, get the partition array again */
2235 PartitionDescriptor = (PPARTITION_DESCRIPTOR)&Buffer[PARTITION_TABLE_OFFSET];
2236 for (Entry = 1; Entry <= NUM_PARTITION_TABLE_ENTRIES; Entry++, PartitionDescriptor++)
2237 {
2238 /* Check if this was a container partition (we skipped these) */
2239 if (IsContainerPartition(PartitionDescriptor->PartitionType))
2240 {
2241 /* Update the partition offset */
2242 Offset.QuadPart = VolumeOffset.QuadPart +
2243 GET_STARTING_SECTOR(PartitionDescriptor) *
2244 SectorSize;
2245
2246 /* If this was the primary partition, update the volume too */
2247 if (IsPrimary) VolumeOffset = Offset;
2248 break;
2249 }
2250 }
2251
2252 /* Check if we already searched all the partitions */
2254 {
2255 /* Then we failed to find a good MBR */
2257 break;
2258 }
2259
2260 /* Loop the next partitions, which are not primary anymore */
2261 IsPrimary = FALSE;
2262 } while (i < PartitionNumber);
2263
2264 /* Everything done, cleanup */
2266 return Status;
2267}
#define NonPagedPoolCacheAligned
Definition: env_spec_w32.h:310
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:321
#define GET_STARTING_SECTOR(p)
Definition: hal.h:253
#define NUM_PARTITION_TABLE_ENTRIES
Definition: hal.h:248
#define STATUS_BAD_MASTER_BOOT_RECORD
Definition: ntstatus.h:499
#define PARTITION_ENTRY_UNUSED
Definition: part_mbr.h:50
#define HalExamineMBR
Definition: part_xbox.c:325
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
Entry
Definition: section.c:5210
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061

◆ xHalIoWritePartitionTable()

NTSTATUS FASTCALL xHalIoWritePartitionTable ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  SectorSize,
IN ULONG  SectorsPerTrack,
IN ULONG  NumberOfHeads,
IN PDRIVE_LAYOUT_INFORMATION  PartitionBuffer 
)

Definition at line 2271 of file disksup.c.

2276{
2277 KEVENT Event;
2279 PIRP Irp;
2282 PUCHAR Buffer;
2283 PPTE Entry;
2284 PPARTITION_TABLE PartitionTable;
2285 LARGE_INTEGER Offset, NextOffset, ExtendedOffset, SectorOffset;
2286 LARGE_INTEGER StartOffset, PartitionLength;
2287 ULONG i, j;
2288 CCHAR k;
2289 BOOLEAN IsEzDrive = FALSE, IsSuperFloppy = FALSE, DoRewrite = FALSE, IsMbr;
2290 ULONG ConventionalCylinders;
2291 LONGLONG DiskSize;
2293 PVOID MbrBuffer;
2298
2299 PAGED_CODE();
2300
2301 ExtendedOffset.QuadPart = NextOffset.QuadPart = Offset.QuadPart = 0;
2302
2303 /* Normalize the buffer size */
2304 BufferSize = max(512, SectorSize);
2305
2306 /* Get the partial drive geometry */
2307 xHalGetPartialGeometry(DeviceObject, &ConventionalCylinders, &DiskSize);
2308
2309 /* Check for EZ-Drive */
2311 if (MbrBuffer)
2312 {
2313 /* EZ-Drive found, bias the offset */
2314 IsEzDrive = TRUE;
2316 Offset.QuadPart = 512;
2317 }
2318
2319 /* Get the number of bits to shift to multiply by the sector size */
2320 for (k = 0; k < 32; k++) if ((SectorSize >> k) == 1) break;
2321
2322 /* Check if there's only one partition */
2323 if (PartitionBuffer->PartitionCount == 1)
2324 {
2325 /* Check if it has no starting offset or hidden sectors */
2326 if (!(PartitionInfo->StartingOffset.QuadPart) &&
2327 !(PartitionInfo->HiddenSectors))
2328 {
2329 /* Then it's a super floppy */
2331
2332 /* Which also means it must be non-bootable FAT-16 */
2333 if ((PartitionInfo->PartitionNumber) ||
2334 (PartitionInfo->PartitionType != PARTITION_FAT_16) ||
2335 (PartitionInfo->BootIndicator))
2336 {
2337 /* It's not, so we fail */
2339 }
2340
2341 /* Check if it needs a rewrite, and disable EZ-Drive for sure */
2342 if (PartitionInfo->RewritePartition) DoRewrite = TRUE;
2343 IsEzDrive = FALSE;
2344 }
2345 }
2346
2347 /* Count the number of partition tables */
2349
2350 /* Allocate our partition buffer */
2353
2354 /* Loop the entries */
2356 for (i = 0; i < DiskLayout->TableCount; i++)
2357 {
2358 /* Set if this is the MBR partition */
2359 IsMbr= (BOOLEAN)!i;
2360
2361 /* Initialize th event */
2363
2364 /* Build the read IRP */
2367 Buffer,
2368 BufferSize,
2369 &Offset,
2370 &Event,
2371 &IoStatusBlock);
2372 if (!Irp)
2373 {
2374 /* Fail */
2376 break;
2377 }
2378
2379 /* Make sure to disable volume verification */
2382
2383 /* Call the driver */
2385 if (Status == STATUS_PENDING)
2386 {
2387 /* Wait for completion */
2390 }
2391
2392 /* Check for failure */
2393 if (!NT_SUCCESS(Status)) break;
2394
2395 /* If we biased for EZ-Drive, unbias now */
2396 if (IsEzDrive && (Offset.QuadPart == 512)) Offset.QuadPart = 0;
2397
2398 /* Check if this is a normal disk */
2399 if (!IsSuperFloppy)
2400 {
2401 /* Set the boot record signature */
2403
2404 /* By default, don't require a rewrite */
2405 DoRewrite = FALSE;
2406
2407 /* Check if we don't have an offset */
2408 if (!Offset.QuadPart)
2409 {
2410 /* Check if the signature doesn't match */
2412 {
2413 /* Then write the signature and now we need a rewrite */
2415 DoRewrite = TRUE;
2416 }
2417 }
2418
2419 /* Loop the partition table entries */
2420 PartitionTable = &DiskLayout->PartitionTable[i];
2421 for (j = 0; j < NUM_PARTITION_TABLE_ENTRIES; j++)
2422 {
2423 /* Get the current entry and type */
2424 TableEntry = &PartitionTable->PartitionEntry[j];
2425 PartitionType = TableEntry->PartitionType;
2426
2427 /* Check if the entry needs a rewrite */
2428 if (TableEntry->RewritePartition)
2429 {
2430 /* Then we need one too */
2431 DoRewrite = TRUE;
2432
2433 /* Save the type and if it's a bootable partition */
2434 Entry[j].PartitionType = TableEntry->PartitionType;
2435 Entry[j].ActiveFlag = TableEntry->BootIndicator ? 0x80 : 0;
2436
2437 /* Make sure it's used */
2439 {
2440 /* Make sure it's not a container (unless primary) */
2441 if ((IsMbr) || !(IsContainerPartition(PartitionType)))
2442 {
2443 /* Use the partition offset */
2444 StartOffset.QuadPart = Offset.QuadPart;
2445 }
2446 else
2447 {
2448 /* Use the extended logical partition offset */
2449 StartOffset.QuadPart = ExtendedOffset.QuadPart;
2450 }
2451
2452 /* Set the sector offset */
2453 SectorOffset.QuadPart = TableEntry->
2454 StartingOffset.QuadPart -
2455 StartOffset.QuadPart;
2456
2457 /* Now calculate the starting sector */
2458 StartOffset.QuadPart = SectorOffset.QuadPart >> k;
2459 Entry[j].StartingSector = StartOffset.LowPart;
2460
2461 /* As well as the length */
2462 PartitionLength.QuadPart = TableEntry->PartitionLength.
2463 QuadPart >> k;
2464 Entry[j].PartitionLength = PartitionLength.LowPart;
2465
2466 /* Calculate the CHS values */
2467 HalpCalculateChsValues(&TableEntry->StartingOffset,
2468 &TableEntry->PartitionLength,
2469 k,
2472 ConventionalCylinders,
2474 &Entry[j]);
2475 }
2476 else
2477 {
2478 /* Otherwise set up an empty entry */
2479 Entry[j].StartingSector = 0;
2480 Entry[j].PartitionLength = 0;
2481 Entry[j].StartingTrack = 0;
2482 Entry[j].EndingTrack = 0;
2483 Entry[j].StartingCylinder = 0;
2484 Entry[j].EndingCylinder = 0;
2485 }
2486 }
2487
2488 /* Check if this is a container partition */
2490 {
2491 /* Then update the offset to use */
2492 NextOffset = TableEntry->StartingOffset;
2493 }
2494 }
2495 }
2496
2497 /* Check if we need to write back the buffer */
2498 if (DoRewrite)
2499 {
2500 /* We don't need to do this again */
2501 DoRewrite = FALSE;
2502
2503 /* Initialize the event */
2505
2506 /* If we unbiased for EZ-Drive, rebias now */
2507 if (IsEzDrive && !Offset.QuadPart) Offset.QuadPart = 512;
2508
2509 /* Build the write IRP */
2512 Buffer,
2513 BufferSize,
2514 &Offset,
2515 &Event,
2516 &IoStatusBlock);
2517 if (!Irp)
2518 {
2519 /* Fail */
2521 break;
2522 }
2523
2524 /* Make sure to disable volume verification */
2527
2528 /* Call the driver */
2530 if (Status == STATUS_PENDING)
2531 {
2532 /* Wait for completion */
2534 Executive,
2535 KernelMode,
2536 FALSE,
2537 NULL);
2539 }
2540
2541 /* Check for failure */
2542 if (!NT_SUCCESS(Status)) break;
2543
2544 /* If we biased for EZ-Drive, unbias now */
2545 if (IsEzDrive && (Offset.QuadPart == 512)) Offset.QuadPart = 0;
2546 }
2547
2548 /* Update the partition offset and set the extended offset if needed */
2549 Offset = NextOffset;
2550 if (IsMbr) ExtendedOffset = NextOffset;
2551 }
2552
2553 /* If we had a buffer, free it, then return status */
2555 return Status;
2556}
unsigned int * PUINT32
Definition: basetsd.h:119
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:291
#define SectorOffset(L)
Definition: cdprocs.h:1622
static VOID HalpCalculateChsValues(_In_ PLARGE_INTEGER PartitionOffset, _In_ PLARGE_INTEGER PartitionLength, _In_ CCHAR ShiftCount, _In_ ULONG SectorsPerTrack, _In_ ULONG NumberOfTracks, _In_ ULONG ConventionalCylinders, _Out_ PPARTITION_DESCRIPTOR PartitionDescriptor)
Definition: disksup.c:1366
VOID FASTCALL xHalGetPartialGeometry(IN PDEVICE_OBJECT DeviceObject, IN PULONG ConventionalCylinders, IN PLONGLONG DiskSize)
Definition: disksup.c:1443
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 GLint GLint j
Definition: glfuncs.h:250
int k
Definition: mpi.c:3369
struct _DISK_LAYOUT * PDISK_LAYOUT
#define DISK_SIGNATURE_OFFSET
Definition: hal.h:243
struct _PTE * PPTE
#define PARTITION_FAT_16
Definition: part_mbr.h:54
#define BOOLEAN
Definition: pedump.c:73
BOOLEAN IsSuperFloppy(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:602
ULONG TableCount
Definition: hal.h:324
PARTITION_TABLE PartitionTable[1]
Definition: hal.h:326
PARTITION_INFORMATION PartitionEntry[4]
Definition: hal.h:319
Definition: hal.h:333
int64_t LONGLONG
Definition: typedefs.h:68
char CCHAR
Definition: typedefs.h:51
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
ULONG LowPart
Definition: typedefs.h:106
_In_ ULONG _In_ ULONG _In_ ULONG NumberOfHeads
Definition: iofuncs.h:2072
_In_ ULONG _In_ ULONG SectorsPerTrack
Definition: iofuncs.h:2071
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105
_Must_inspect_result_ typedef _In_ ULONG TableEntry
Definition: iotypes.h:4306
ret QuadPart
Definition: rtlfuncs.h:3106

◆ xHalLocateHiberRanges()

VOID NTAPI xHalLocateHiberRanges ( IN PVOID  MemoryMap)

Definition at line 196 of file halstub.c.

197{
198 /* Nothing */
199 return;
200}

◆ xHalMirrorPhysicalMemory()

NTSTATUS NTAPI xHalMirrorPhysicalMemory ( IN PHYSICAL_ADDRESS  PhysicalAddress,
IN LARGE_INTEGER  NumberOfBytes 
)

Definition at line 153 of file halstub.c.

155{
157}

◆ xHalQueryBusSlots()

NTSTATUS NTAPI xHalQueryBusSlots ( IN PBUS_HANDLER  BusHandler,
IN ULONG  BufferSize,
OUT PULONG  SlotNumbers,
OUT PULONG  ReturnedLength 
)

Definition at line 161 of file halstub.c.

165{
166 PAGED_CODE();
167
169}

◆ xHalQuerySystemInformation()

NTSTATUS NTAPI xHalQuerySystemInformation ( IN HAL_QUERY_INFORMATION_CLASS  InformationClass,
IN ULONG  BufferSize,
IN OUT PVOID  Buffer,
OUT PULONG  ReturnedLength 
)

Definition at line 184 of file halstub.c.

188{
189 PAGED_CODE();
190
192}
#define STATUS_INVALID_LEVEL
Definition: ntstatus.h:658

◆ xHalReferenceHandler()

VOID FASTCALL xHalReferenceHandler ( IN PBUS_HANDLER  BusHandler)

Definition at line 114 of file halstub.c.

115{
116 /* Nothing */
117 return;
118}

◆ xHalRegisterBusHandler()

NTSTATUS NTAPI xHalRegisterBusHandler ( IN INTERFACE_TYPE  InterfaceType,
IN BUS_DATA_TYPE  ConfigSpace,
IN ULONG  BusNumber,
IN INTERFACE_TYPE  ParentInterfaceType,
IN ULONG  ParentBusNumber,
IN ULONG  ContextSize,
IN PINSTALL_BUS_HANDLER  InstallCallback,
OUT PBUS_HANDLER BusHandler 
)

Definition at line 204 of file halstub.c.

212{
213 PAGED_CODE();
214
216}

◆ xHalSetSystemInformation()

NTSTATUS NTAPI xHalSetSystemInformation ( IN HAL_SET_INFORMATION_CLASS  InformationClass,
IN ULONG  BufferSize,
IN PVOID  Buffer 
)

Definition at line 173 of file halstub.c.

176{
177 PAGED_CODE();
178
180}

◆ xHalSetWakeAlarm()

VOID NTAPI xHalSetWakeAlarm ( IN ULONGLONG  AlartTime,
IN PTIME_FIELDS  TimeFields 
)

Definition at line 220 of file halstub.c.

222{
223 /* Nothing */
224 return;
225}

◆ xHalSetWakeEnable()

VOID NTAPI xHalSetWakeEnable ( IN BOOLEAN  Enable)

Definition at line 98 of file halstub.c.

99{
100 /* Nothing */
101 return;
102}

◆ xHalStartMirroring()

NTSTATUS NTAPI xHalStartMirroring ( VOID  )

Definition at line 137 of file halstub.c.

138{
139 PAGED_CODE();
140
142}

◆ xHalTranslateBusAddress()

BOOLEAN NTAPI xHalTranslateBusAddress ( IN INTERFACE_TYPE  InterfaceType,
IN ULONG  BusNumber,
IN PHYSICAL_ADDRESS  BusAddress,
IN OUT PULONG  AddressSpace,
OUT PPHYSICAL_ADDRESS  TranslatedAddress 
)

Definition at line 229 of file halstub.c.

234{
235 KeBugCheckEx(HAL_INITIALIZATION_FAILED, 0, 0, 0, 0);
236
237 return FALSE;
238}
DECLSPEC_NORETURN VOID NTAPI KeBugCheckEx(IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4)
Definition: debug.c:485

◆ xHalVectorToIDTEntry()

UCHAR NTAPI xHalVectorToIDTEntry ( IN ULONG  Vector)

Definition at line 31 of file halstub.c.

32{
33 /* Return the vector */
34 return (UCHAR)Vector;
35}

◆ xKdGetAcpiTablePhase()

PVOID NTAPI xKdGetAcpiTablePhase ( IN struct _LOADER_PARAMETER_BLOCK LoaderBlock,
IN ULONG  Signature 
)

Definition at line 269 of file halstub.c.

271{
272 return NULL;
273}

◆ xKdReleasePciDeviceForDebugging()

NTSTATUS NTAPI xKdReleasePciDeviceForDebugging ( IN OUT PDEBUG_DEVICE_DESCRIPTOR  PciDevice)

Definition at line 262 of file halstub.c.

263{
265}

◆ xKdSetupPciDeviceForDebugging()

NTSTATUS NTAPI xKdSetupPciDeviceForDebugging ( IN PVOID LoaderBlock  OPTIONAL,
IN OUT PDEBUG_DEVICE_DESCRIPTOR  PciDevice 
)

Definition at line 254 of file halstub.c.

256{
258}

◆ xKdUnmapVirtualAddress()

VOID NTAPI xKdUnmapVirtualAddress ( IN PVOID  VirtualAddress,
IN ULONG  NumberPages,
IN BOOLEAN  FlushCurrentTLB 
)

Definition at line 286 of file halstub.c.

289{
290 /* Nothing */
291 return;
292}