ReactOS  0.4.15-dev-1397-g19779b3
disksup.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
#include <internal/hal.h>
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for disksup.c:

Go to the source code of this file.

Classes

struct  _REG_DISK_MOUNT_INFO
 

Macros

#define NDEBUG
 
#define AUTO_DRIVE   MAXULONG
 
#define PARTITION_MAGIC   0xaa55
 
#define EFI_PMBR_OSTYPE_EFI   0xEE
 

Typedefs

typedef struct _REG_DISK_MOUNT_INFO REG_DISK_MOUNT_INFO
 
typedef struct _REG_DISK_MOUNT_INFOPREG_DISK_MOUNT_INFO
 
typedef enum _DISK_MANAGER DISK_MANAGER
 
typedef enum _PARTITION_TYPE PARTITION_TYPE
 
typedef enum _PARTITION_TYPEPPARTITION_TYPE
 

Enumerations

enum  _DISK_MANAGER { NoDiskManager, OntrackDiskManager, EZ_Drive }
 
enum  _PARTITION_TYPE {
  BootablePartition, PrimaryPartition, LogicalPartition, FtPartition,
  UnknownPartition, DataPartition
}
 

Functions

NTSTATUS FASTCALL HalpQueryDriveLayout (IN PUNICODE_STRING DeviceName, OUT PDRIVE_LAYOUT_INFORMATION *LayoutInfo)
 
NTSTATUS HalpQueryPartitionType (IN PUNICODE_STRING DeviceName, IN PDRIVE_LAYOUT_INFORMATION LayoutInfo, OUT PPARTITION_TYPE PartitionType)
 
PULONG IopComputeHarddiskDerangements (IN ULONG DiskCount)
 
NTSTATUS HalpNextMountLetter (IN PUNICODE_STRING DeviceName, OUT PUCHAR DriveLetter)
 
NTSTATUS HalpSetMountLetter (IN PUNICODE_STRING DeviceName, UCHAR DriveLetter)
 
UCHAR HalpNextDriveLetter (IN PUNICODE_STRING DeviceName, IN PSTRING NtDeviceName, OUT PUCHAR NtSystemPath, BOOLEAN IsRemovable)
 
BOOLEAN HalpIsOldStyleFloppy (PUNICODE_STRING DeviceName)
 
NTSTATUS HalpDeleteMountLetter (UCHAR DriveLetter)
 
VOID HalpEnableAutomaticDriveLetterAssignment (VOID)
 
VOID FASTCALL xHalIoAssignDriveLetters (IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN PSTRING NtDeviceName, OUT PUCHAR NtSystemPath, OUT PSTRING NtSystemPathString)
 
NTSTATUS NTAPI HalpGetFullGeometry (IN PDEVICE_OBJECT DeviceObject, OUT PDISK_GEOMETRY_EX Geometry)
 
BOOLEAN NTAPI HalpIsValidPartitionEntry (IN PPARTITION_DESCRIPTOR Entry, IN ULONGLONG MaxOffset, IN ULONGLONG MaxSector)
 
VOID NTAPI 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)
 
VOID FASTCALL xHalGetPartialGeometry (IN PDEVICE_OBJECT DeviceObject, IN PULONG ConventionalCylinders, IN PLONGLONG DiskSize)
 
VOID FASTCALL xHalExamineMBR (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG MbrTypeIdentifier, OUT PVOID *MbrBuffer)
 
VOID NTAPI FstubFixupEfiPartition (IN PPARTITION_DESCRIPTOR PartitionDescriptor, IN ULONGLONG MaxOffset)
 
NTSTATUS FASTCALL xHalIoReadPartitionTable (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN BOOLEAN ReturnRecognizedPartitions, IN 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 FASTCALL HalExamineMBR (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG MbrTypeIdentifier, OUT PVOID *MbrBuffer)
 
NTSTATUS FASTCALL IoReadPartitionTable (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN BOOLEAN ReturnRecognizedPartitions, IN OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
 
NTSTATUS FASTCALL IoSetPartitionInformation (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
 
NTSTATUS FASTCALL IoWritePartitionTable (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG SectorsPerTrack, IN ULONG NumberOfHeads, IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer)
 
VOID FASTCALL IoAssignDriveLetters (IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN PSTRING NtDeviceName, OUT PUCHAR NtSystemPath, OUT PSTRING NtSystemPathString)
 

Variables

const WCHAR DiskMountString [] = L"\\DosDevices\\%C:"
 

Macro Definition Documentation

◆ AUTO_DRIVE

#define AUTO_DRIVE   MAXULONG

Definition at line 21 of file disksup.c.

◆ EFI_PMBR_OSTYPE_EFI

#define EFI_PMBR_OSTYPE_EFI   0xEE

Definition at line 25 of file disksup.c.

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file disksup.c.

◆ PARTITION_MAGIC

#define PARTITION_MAGIC   0xaa55

Definition at line 23 of file disksup.c.

Typedef Documentation

◆ DISK_MANAGER

◆ PARTITION_TYPE

◆ PPARTITION_TYPE

◆ PREG_DISK_MOUNT_INFO

◆ REG_DISK_MOUNT_INFO

Enumeration Type Documentation

◆ _DISK_MANAGER

Enumerator
NoDiskManager 
OntrackDiskManager 
EZ_Drive 

Definition at line 37 of file disksup.c.

38 {
41  EZ_Drive
42 } DISK_MANAGER;
enum _DISK_MANAGER DISK_MANAGER

◆ _PARTITION_TYPE

Enumerator
BootablePartition 
PrimaryPartition 
LogicalPartition 
FtPartition 
UnknownPartition 
DataPartition 

Definition at line 44 of file disksup.c.

45 {
enum _PARTITION_TYPE * PPARTITION_TYPE
enum _PARTITION_TYPE PARTITION_TYPE

Function Documentation

◆ FstubFixupEfiPartition()

VOID NTAPI FstubFixupEfiPartition ( IN PPARTITION_DESCRIPTOR  PartitionDescriptor,
IN ULONGLONG  MaxOffset 
)

Definition at line 1750 of file disksup.c.

1752 {
1753  ULONG PartitionMaxOffset, PartitionLength;
1754  PAGED_CODE();
1755 
1756  /* Compute partition length (according to MBR entry) */
1757  PartitionMaxOffset = GET_STARTING_SECTOR(PartitionDescriptor) + GET_PARTITION_LENGTH(PartitionDescriptor);
1758  /* In case the partition length goes beyond disk size... */
1759  if (PartitionMaxOffset > MaxOffset)
1760  {
1761  /* Resize partition to its maximum real length */
1762  PartitionLength = (ULONG)(PartitionMaxOffset - GET_STARTING_SECTOR(PartitionDescriptor));
1763  SET_PARTITION_LENGTH(PartitionDescriptor, PartitionLength);
1764  }
1765 }
#define GET_STARTING_SECTOR(p)
Definition: hal.h:252
#define SET_PARTITION_LENGTH(p, l)
Definition: hal.h:267
#define GET_PARTITION_LENGTH(p)
Definition: hal.h:261
unsigned int ULONG
Definition: retypes.h:1
#define PAGED_CODE()

Referenced by xHalIoReadPartitionTable().

◆ HalExamineMBR()

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

Definition at line 2688 of file disksup.c.

2692 {
2693  HALDISPATCH->HalExamineMBR(DeviceObject,
2694  SectorSize,
2695  MbrTypeIdentifier,
2696  MbrBuffer);
2697 }
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ ULONG SectorSize
Definition: halfuncs.h:291
#define HALDISPATCH
Definition: haltypes.h:278

Referenced by CreatePartitionDeviceObjects(), DiskInitFdo(), IopCreateArcNamesDisk(), UpdateGeometry(), xHalIoReadPartitionTable(), xHalIoSetPartitionInformation(), and xHalIoWritePartitionTable().

◆ HalpCalculateChsValues()

VOID NTAPI 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 at line 1482 of file disksup.c.

1489 {
1490  LARGE_INTEGER FirstSector, SectorCount;
1491  ULONG LastSector, Remainder, SectorsPerCylinder;
1492  ULONG StartingCylinder, EndingCylinder;
1493  ULONG StartingTrack, EndingTrack;
1494  ULONG StartingSector, EndingSector;
1495  PAGED_CODE();
1496 
1497  /* Calculate the number of sectors for each cylinder */
1498  SectorsPerCylinder = SectorsPerTrack * NumberOfTracks;
1499 
1500  /* Calculate the first sector, and the sector count */
1501  FirstSector.QuadPart = PartitionOffset->QuadPart >> ShiftCount;
1502  SectorCount.QuadPart = PartitionLength->QuadPart >> ShiftCount;
1503 
1504  /* Now calculate the last sector */
1505  LastSector = FirstSector.LowPart + SectorCount.LowPart - 1;
1506 
1507  /* Calculate the first and last cylinders */
1508  StartingCylinder = FirstSector.LowPart / SectorsPerCylinder;
1509  EndingCylinder = LastSector / SectorsPerCylinder;
1510 
1511  /* Set the default number of cylinders */
1512  if (!ConventionalCylinders) ConventionalCylinders = 1024;
1513 
1514  /* Normalize the values */
1515  if (StartingCylinder >= ConventionalCylinders)
1516  {
1517  /* Set the maximum to 1023 */
1518  StartingCylinder = ConventionalCylinders - 1;
1519  }
1520  if (EndingCylinder >= ConventionalCylinders)
1521  {
1522  /* Set the maximum to 1023 */
1523  EndingCylinder = ConventionalCylinders - 1;
1524  }
1525 
1526  /* Calculate the starting head and sector that still remain */
1527  Remainder = FirstSector.LowPart % SectorsPerCylinder;
1528  StartingTrack = Remainder / SectorsPerTrack;
1529  StartingSector = Remainder % SectorsPerTrack;
1530 
1531  /* Calculate the ending head and sector that still remain */
1532  Remainder = LastSector % SectorsPerCylinder;
1533  EndingTrack = Remainder / SectorsPerTrack;
1534  EndingSector = Remainder % SectorsPerTrack;
1535 
1536  /* Set cylinder data for the MSB */
1537  PartitionDescriptor->StartingCylinderMsb = (UCHAR)StartingCylinder;
1538  PartitionDescriptor->EndingCylinderMsb = (UCHAR)EndingCylinder;
1539 
1540  /* Set the track data */
1541  PartitionDescriptor->StartingTrack = (UCHAR)StartingTrack;
1542  PartitionDescriptor->EndingTrack = (UCHAR)EndingTrack;
1543 
1544  /* Update cylinder data for the LSB */
1545  StartingCylinder = ((StartingSector + 1) & 0x3F) |
1546  ((StartingCylinder >> 2) & 0xC0);
1547  EndingCylinder = ((EndingSector + 1) & 0x3F) |
1548  ((EndingCylinder >> 2) & 0xC0);
1549 
1550  /* Set the cylinder data for the LSB */
1551  PartitionDescriptor->StartingCylinderLsb = (UCHAR)StartingCylinder;
1552  PartitionDescriptor->EndingCylinderLsb = (UCHAR)EndingCylinder;
1553 }
_In_ ULONG _In_ ULONG SectorsPerTrack
Definition: iofuncs.h:2066
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG LowPart
Definition: typedefs.h:106
ULONG SectorCount
Definition: part_xbox.c:31
unsigned int ULONG
Definition: retypes.h:1
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3046
#define PAGED_CODE()

Referenced by xHalIoWritePartitionTable().

◆ HalpDeleteMountLetter()

NTSTATUS HalpDeleteMountLetter ( UCHAR  DriveLetter)

Definition at line 766 of file disksup.c.

767 {
768  PIRP Irp;
769  KEVENT Event;
771  WCHAR Buffer[30];
777  UNICODE_STRING DosDevice, MountMgr;
779 
780  /* Setup the device name of the letter to delete */
781  swprintf(Buffer, L"\\DosDevices\\%c:", DriveLetter);
782  RtlInitUnicodeString(&DosDevice, Buffer);
783 
784  /* Allocate the input buffer for MountMgr */
785  InputBufferLength = DosDevice.Length + sizeof(MOUNTMGR_MOUNT_POINT);
787  if (InputBuffer == NULL)
788  {
790  }
791 
792  /* Fill it in */
794  InputBuffer->SymbolicLinkNameOffset = sizeof(MOUNTMGR_MOUNT_POINT);
795  InputBuffer->SymbolicLinkNameLength = DosDevice.Length;
796  RtlCopyMemory(&InputBuffer[1], DosDevice.Buffer, DosDevice.Length);
797 
798  /* Allocate big enough output buffer (we don't care about the output) */
800  if (OutputBuffer == NULL)
801  {
804  }
805 
806  /* Get the device pointer to the MountMgr */
807  RtlInitUnicodeString(&MountMgr, L"\\Device\\MountPointManager");
808  Status = IoGetDeviceObjectPointer(&MountMgr,
810  &FileObject,
811  &DeviceObject);
812  if (!NT_SUCCESS(Status))
813  {
816  return Status;
817  }
818 
819  /* Call the mount manager to delete the drive letter */
822  DeviceObject,
823  InputBuffer,
825  OutputBuffer,
826  0x1000,
827  FALSE,
828  &Event,
829  &IoStatusBlock);
830  if (Irp == NULL)
831  {
836  }
837 
839  if (Status == STATUS_PENDING)
840  {
842  Executive,
843  KernelMode,
844  FALSE,
845  NULL);
847  }
848 
852 
853  return Status;
854 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _MOUNTMGR_MOUNT_POINT MOUNTMGR_MOUNT_POINT
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:318
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
Definition: bufpool.h:45
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:859
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define ObDereferenceObject
Definition: obfuncs.h:203
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
#define TAG_FSTUB
Definition: tag.h:195
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define IOCTL_MOUNTMGR_DELETE_POINTS
Definition: imports.h:124

Referenced by xHalIoAssignDriveLetters().

◆ HalpEnableAutomaticDriveLetterAssignment()

VOID HalpEnableAutomaticDriveLetterAssignment ( VOID  )

Definition at line 857 of file disksup.c.

858 {
859  PIRP Irp;
860  KEVENT Event;
862  UNICODE_STRING MountMgr;
866 
867  /* Get the device pointer to the MountMgr */
868  RtlInitUnicodeString(&MountMgr, L"\\Device\\MountPointManager");
869  Status = IoGetDeviceObjectPointer(&MountMgr,
871  &FileObject,
872  &DeviceObject);
873  if (!NT_SUCCESS(Status))
874  {
875  return;
876  }
877 
878  /* Just send an IOCTL to enable the feature */
881  DeviceObject,
882  NULL,
883  0,
884  NULL,
885  0,
886  FALSE,
887  &Event,
888  &IoStatusBlock);
889  if (Irp == NULL)
890  {
891  return;
892  }
893 
895  if (Status == STATUS_PENDING)
896  {
898  Executive,
899  KernelMode,
900  FALSE,
901  NULL);
903  }
904 
906 
907  return;
908 }
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_MOUNTMGR_AUTO_DL_ASSIGNMENTS
Definition: mountmgr.h:36
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ObDereferenceObject
Definition: obfuncs.h:203
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
static const WCHAR L[]
Definition: oid.c:1250
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

Referenced by xHalIoAssignDriveLetters().

◆ HalpGetFullGeometry()

NTSTATUS NTAPI HalpGetFullGeometry ( IN PDEVICE_OBJECT  DeviceObject,
OUT PDISK_GEOMETRY_EX  Geometry 
)

Definition at line 1389 of file disksup.c.

1391 {
1392  PIRP Irp;
1394  PKEVENT Event;
1395  NTSTATUS Status;
1396 
1397  PAGED_CODE();
1398 
1399  /* Allocate a non-paged event */
1401  sizeof(KEVENT),
1402  TAG_FILE_SYSTEM);
1403  if (!Event) return STATUS_INSUFFICIENT_RESOURCES;
1404 
1405  /* Initialize it */
1407 
1408  /* Build the IRP */
1410  DeviceObject,
1411  NULL,
1412  0UL,
1413  Geometry,
1414  sizeof(DISK_GEOMETRY_EX),
1415  FALSE,
1416  Event,
1417  &IoStatusBlock);
1418  if (!Irp)
1419  {
1420  /* Fail, free the event */
1423  }
1424 
1425  /* Call the driver and check if it's pending */
1427  if (Status == STATUS_PENDING)
1428  {
1429  /* Wait on the driver */
1432  }
1433 
1434  /* Free the event and return the Status */
1436  return Status;
1437 }
#define TAG_FILE_SYSTEM
Definition: tag.h:50
#define IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
Definition: ntddk_ex.h:208
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
Status
Definition: gdiplustypes.h:24
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define UL
Definition: tui.h:82
#define PAGED_CODE()

Referenced by xHalIoReadPartitionTable().

◆ HalpIsOldStyleFloppy()

BOOLEAN HalpIsOldStyleFloppy ( PUNICODE_STRING  DeviceName)

Definition at line 707 of file disksup.c.

708 {
709  PIRP Irp;
710  KEVENT Event;
712  MOUNTDEV_NAME DevName;
716  PAGED_CODE();
717 
718  /* Get the attached device object to our device */
721  &FileObject,
722  &DeviceObject)))
723  {
724  return FALSE;
725  }
726 
729 
730  /* Query its device name (ie, check floppy.sys implements MountMgr interface) */
733  DeviceObject,
734  NULL,
735  0,
736  &DevName,
737  sizeof(DevName),
738  FALSE,
739  &Event,
740  &IoStatusBlock);
741  if (Irp == NULL)
742  {
744  return FALSE;
745  }
746 
748  if (Status == STATUS_PENDING)
749  {
751  Executive,
752  KernelMode,
753  FALSE,
754  NULL);
756  }
757 
758  /* If status is not STATUS_BUFFER_OVERFLOW, it means
759  * it's pre-mountmgr driver, aka "Old style".
760  */
762  return (Status != STATUS_BUFFER_OVERFLOW);
763 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
Definition: imports.h:93
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ObDereferenceObject
Definition: obfuncs.h:203
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define PAGED_CODE()

Referenced by xHalIoAssignDriveLetters().

◆ HalpIsValidPartitionEntry()

BOOLEAN NTAPI HalpIsValidPartitionEntry ( IN PPARTITION_DESCRIPTOR  Entry,
IN ULONGLONG  MaxOffset,
IN ULONGLONG  MaxSector 
)

Definition at line 1441 of file disksup.c.

1444 {
1445  ULONGLONG EndingSector;
1446  PAGED_CODE();
1447 
1448  /* Unused partitions are considered valid */
1449  if (Entry->PartitionType == PARTITION_ENTRY_UNUSED) return TRUE;
1450 
1451  /* Get the last sector of the partition */
1453 
1454  /* Check if it's more then the maximum sector */
1455  if (EndingSector > MaxSector)
1456  {
1457  /* Invalid partition */
1458  DPRINT1("FSTUB: entry is invalid\n");
1459  DPRINT1("FSTUB: offset %#08lx\n", GET_STARTING_SECTOR(Entry));
1460  DPRINT1("FSTUB: length %#08lx\n", GET_PARTITION_LENGTH(Entry));
1461  DPRINT1("FSTUB: end %#I64x\n", EndingSector);
1462  DPRINT1("FSTUB: max %#I64x\n", MaxSector);
1463  return FALSE;
1464  }
1465  else if (GET_STARTING_SECTOR(Entry) > MaxOffset)
1466  {
1467  /* Invalid partition */
1468  DPRINT1("FSTUB: entry is invalid\n");
1469  DPRINT1("FSTUB: offset %#08lx\n", GET_STARTING_SECTOR(Entry));
1470  DPRINT1("FSTUB: length %#08lx\n", GET_PARTITION_LENGTH(Entry));
1471  DPRINT1("FSTUB: end %#I64x\n", EndingSector);
1472  DPRINT1("FSTUB: maxOffset %#I64x\n", MaxOffset);
1473  return FALSE;
1474  }
1475 
1476  /* It's fine, return success */
1477  return TRUE;
1478 }
#define GET_STARTING_SECTOR(p)
Definition: hal.h:252
#define TRUE
Definition: types.h:120
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
#define FALSE
Definition: types.h:117
#define GET_PARTITION_LENGTH(p)
Definition: hal.h:261
uint64_t ULONGLONG
Definition: typedefs.h:67
#define DPRINT1
Definition: precomp.h:8
base of all file and directory entries
Definition: entries.h:82
#define PAGED_CODE()

Referenced by xHalIoReadPartitionTable().

◆ HalpNextDriveLetter()

UCHAR HalpNextDriveLetter ( IN PUNICODE_STRING  DeviceName,
IN PSTRING  NtDeviceName,
OUT PUCHAR  NtSystemPath,
BOOLEAN  IsRemovable 
)

Definition at line 607 of file disksup.c.

611 {
612  UCHAR i;
613  WCHAR Buffer[40];
614  UCHAR DriveLetter;
615  UNICODE_STRING FloppyString, CdString, NtDeviceNameU, DosDevice;
616 
617  /* Quick path, ask directly the mount manager to assign the next
618  * free drive letter
619  */
620  if (NT_SUCCESS(HalpNextMountLetter(DeviceName, &DriveLetter)))
621  {
622  return DriveLetter;
623  }
624 
625  /* We'll allow MountMgr to fail only for non vital path */
626  if (NtDeviceName == NULL || NtSystemPath == NULL)
627  {
628  return -1;
629  }
630 
631  /* And for removable devices */
632  if (!IsRemovable)
633  {
634  return 0;
635  }
636 
637  /* Removable might be floppy or cdrom */
638  RtlInitUnicodeString(&FloppyString, L"\\Device\\Floppy");
639  RtlInitUnicodeString(&CdString, L"\\Device\\CdRom");
640 
641  /* If floppy, start at A */
642  if (RtlPrefixUnicodeString(&FloppyString, DeviceName, TRUE))
643  {
644  DriveLetter = 'A';
645  }
646  /* If CD start C */
647  else if (RtlPrefixUnicodeString(&CdString, DeviceName, TRUE))
648  {
649  DriveLetter = 'D';
650  }
651  /* For the rest start at C */
652  else
653  {
654  DriveLetter = 'C';
655  }
656 
657  /* Now, try to assign a drive letter manually with the MountMgr */
658  for (i = DriveLetter; i <= 'Z'; ++i)
659  {
661  {
662  /* If it worked, if we were managing system path, update manually */
663  if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&NtDeviceNameU, NtDeviceName, TRUE)))
664  {
665  if (RtlEqualUnicodeString(&NtDeviceNameU, DeviceName, TRUE))
666  {
667  *NtSystemPath = i;
668  }
669 
670  RtlFreeUnicodeString(&NtDeviceNameU);
671  }
672 
673  return i;
674  }
675  }
676 
677  /* Last fall back, we're not on a PnP device... */
678  for (i = DriveLetter; i <= 'Z'; ++i)
679  {
680  /* We'll link manually, without MountMgr knowing anything about the device */
681  swprintf(Buffer, L"\\DosDevices\\%c:", i);
682  RtlInitUnicodeString(&DosDevice, Buffer);
683 
684  /* If linking worked, then the letter was free ;-) */
685  if (NT_SUCCESS(IoCreateSymbolicLink(&DosDevice, DeviceName)))
686  {
687  /* If it worked, if we were managing system path, update manually */
688  if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&NtDeviceNameU, NtDeviceName, TRUE)))
689  {
690  if (RtlEqualUnicodeString(&NtDeviceNameU, DeviceName, TRUE))
691  {
692  *NtSystemPath = i;
693  }
694 
695  RtlFreeUnicodeString(&NtDeviceNameU);
696  }
697 
698  return i;
699  }
700  }
701 
702  /* We're done, nothing happened */
703  return 0;
704 }
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSTATUS HalpSetMountLetter(IN PUNICODE_STRING DeviceName, UCHAR DriveLetter)
Definition: disksup.c:522
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
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
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define NULL
Definition: types.h:112
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS HalpNextMountLetter(IN PUNICODE_STRING DeviceName, OUT PUCHAR DriveLetter)
Definition: disksup.c:441
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)

Referenced by xHalIoAssignDriveLetters().

◆ HalpNextMountLetter()

NTSTATUS HalpNextMountLetter ( IN PUNICODE_STRING  DeviceName,
OUT PUCHAR  DriveLetter 
)

Definition at line 441 of file disksup.c.

443 {
444  PIRP Irp;
445  KEVENT Event;
447  UNICODE_STRING MountMgr;
453 
454  /* To get next mount letter, we need the MountMgr */
455  RtlInitUnicodeString(&MountMgr, L"\\Device\\MountPointManager");
456  Status = IoGetDeviceObjectPointer(&MountMgr,
458  &FileObject,
459  &DeviceObject);
460  if (!NT_SUCCESS(Status))
461  {
462  return Status;
463  }
464 
465  /* Allocate our input buffer */
468  TAG_FSTUB);
469  if (Target == NULL)
470  {
473  }
474 
475  /* And fill it with the device hat needs a drive letter */
476  Target->DeviceNameLength = DeviceName->Length;
477  RtlCopyMemory(&Target->DeviceName[0], DeviceName->Buffer, DeviceName->Length);
478 
479  /* Call the mount manager */
482  DeviceObject,
483  Target,
485  &LetterInfo,
486  sizeof(LetterInfo),
487  FALSE,
488  &Event,
489  &IoStatusBlock);
490  if (Irp == NULL)
491  {
495  }
496 
498  if (Status == STATUS_PENDING)
499  {
501  Executive,
502  KernelMode,
503  FALSE,
504  NULL);
506  }
507 
510 
511  DPRINT("Done: %d %c\n", LetterInfo.DriveLetterWasAssigned,
512  LetterInfo.CurrentDriveLetter);
513 
514  /* Return the drive letter the MountMgr potentially assigned */
515  *DriveLetter = LetterInfo.CurrentDriveLetter;
516 
517  /* Also return the success */
518  return Status;
519 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define IOCTL_MOUNTMGR_NEXT_DRIVE_LETTER
Definition: mountmgr.h:34
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
void DPRINT(...)
Definition: polytest.cpp:61
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ObDereferenceObject
Definition: obfuncs.h:203
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
#define TAG_FSTUB
Definition: tag.h:195
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by HalpNextDriveLetter().

◆ HalpQueryDriveLayout()

NTSTATUS FASTCALL HalpQueryDriveLayout ( IN PUNICODE_STRING  DeviceName,
OUT PDRIVE_LAYOUT_INFORMATION LayoutInfo 
)

Definition at line 56 of file disksup.c.

58 {
59  IO_STATUS_BLOCK StatusBlock;
62  KEVENT Event;
63  PIRP Irp;
67  PAGED_CODE();
68 
69  /* Get device pointers */
72  &FileObject,
73  &DeviceObject);
74  if (!NT_SUCCESS(Status))
75  {
76  return Status;
77  }
78 
79  /* Get attached device object */
82 
83  /* Do not handle removable media */
84  if (BooleanFlagOn(DeviceObject->Characteristics, FILE_REMOVABLE_MEDIA))
85  {
87  return STATUS_NO_MEDIA;
88  }
89 
90  /* We'll loop until our buffer is big enough */
91  Buffer = NULL;
92  BufferSize = 0x1000;
94  do
95  {
96  /* If we already had a buffer, it means it's not big
97  * enough, so free and multiply size by two
98  */
99  if (Buffer != NULL)
100  {
102  BufferSize *= 2;
103  }
104 
105  /* Allocate buffer for output buffer */
107  if (Buffer == NULL)
108  {
110  break;
111  }
112 
113  /* Build the IRP to query drive layout */
115  DeviceObject,
116  NULL,
117  0,
118  Buffer,
119  BufferSize,
120  FALSE,
121  &Event,
122  &StatusBlock);
123  if (Irp == NULL)
124  {
126  break;
127  }
128 
129  /* Call the driver and wait if appropriate */
131  if (Status == STATUS_PENDING)
132  {
134  Executive,
135  KernelMode,
136  FALSE,
137  NULL);
138  Status = StatusBlock.Status;
139  }
140  /* If buffer is too small, keep looping */
141  } while (Status == STATUS_BUFFER_TOO_SMALL);
142 
143  /* We're done with the device */
145 
146  /* If querying worked, then return the buffer to the caller */
147  if (NT_SUCCESS(Status))
148  {
149  ASSERT(Buffer != NULL);
150  *LayoutInfo = Buffer;
151  }
152  /* Else, release the buffer if still allocated and fail */
153  else
154  {
155  if (Buffer != NULL)
156  {
158  }
159  }
160 
161  return Status;
162 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
Definition: bufpool.h:45
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ObDereferenceObject
Definition: obfuncs.h:203
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define TAG_FSTUB
Definition: tag.h:195
#define IOCTL_DISK_GET_DRIVE_LAYOUT
Definition: ntdddisk.h:91
#define STATUS_NO_MEDIA
Definition: ntstatus.h:610
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
#define PAGED_CODE()

Referenced by xHalIoAssignDriveLetters().

◆ HalpQueryPartitionType()

NTSTATUS HalpQueryPartitionType ( IN PUNICODE_STRING  DeviceName,
IN PDRIVE_LAYOUT_INFORMATION  LayoutInfo,
OUT PPARTITION_TYPE  PartitionType 
)

Definition at line 165 of file disksup.c.

168 {
169  USHORT i;
170  PIRP Irp;
171  KEVENT Event;
177 
178  PAGED_CODE();
179 
180  /* Get device pointers */
183  &FileObject,
184  &DeviceObject);
185  if (!NT_SUCCESS(Status))
186  {
187  return Status;
188  }
189 
190  /* Get attached device object */
193 
194  /* Assume logical partition for removable devices */
195  if (BooleanFlagOn(DeviceObject->Characteristics, FILE_REMOVABLE_MEDIA))
196  {
199  return STATUS_SUCCESS;
200  }
201 
202  /* For the others, query partition info */
205  DeviceObject,
206  NULL,
207  0,
208  &PartitionInfo,
209  sizeof(PartitionInfo),
210  FALSE,
211  &Event,
212  &IoStatusBlock);
213  if (Irp == NULL)
214  {
217  }
218 
220  if (Status == STATUS_PENDING)
221  {
223  Executive,
224  KernelMode,
225  FALSE,
226  NULL);
228  }
229 
230  /* We're done with the device */
232 
233  /* If we failed querying partition info, try to return something
234  * if caller didn't provide a precise layout, assume logical
235  * partition and fake success. Otherwise, just fail.
236  */
237  if (!NT_SUCCESS(Status))
238  {
239  if (LayoutInfo == NULL)
240  {
242  return STATUS_SUCCESS;
243  }
244 
245  return Status;
246  }
247 
248  /* First, handle non MBR style (easy cases) */
249  if (PartitionInfo.PartitionStyle != PARTITION_STYLE_MBR)
250  {
251  /* If not GPT, we don't know what it is */
252  if (PartitionInfo.PartitionStyle != PARTITION_STYLE_GPT)
253  {
255  return STATUS_SUCCESS;
256  }
257 
258  /* Check whether that's data partition */
259  if (RtlCompareMemory(&PartitionInfo.Gpt.PartitionType,
260  &PARTITION_BASIC_DATA_GUID,
261  sizeof(GUID)) == sizeof(GUID))
262  {
264  return STATUS_SUCCESS;
265  }
266 
267  /* Otherwise, we don't know */
269  return STATUS_SUCCESS;
270  }
271 
272  /* If we don't recognize partition type, return unknown */
273  if (!IsRecognizedPartition(PartitionInfo.Mbr.PartitionType))
274  {
276  return STATUS_SUCCESS;
277  }
278 
279  /* Check if that's a FT volume */
280  if (IsFTPartition(PartitionInfo.Mbr.PartitionType))
281  {
283  return STATUS_SUCCESS;
284  }
285 
286  /* If the caller didn't provide the complete layout, just return */
287  if (LayoutInfo == NULL)
288  {
290  return STATUS_SUCCESS;
291  }
292 
293  /* Now, evaluate the partition to the 4 in the input layout */
294  for (i = 0; i < 4; ++i)
295  {
296  /* If we find a partition matching */
297  if (LayoutInfo->PartitionEntry[i].StartingOffset.QuadPart == PartitionInfo.StartingOffset.QuadPart)
298  {
299  /* Return boot if boot flag is set */
300  if (PartitionInfo.Mbr.BootIndicator)
301  {
303  }
304  /* Primary otherwise */
305  else
306  {
308  }
309 
310  return STATUS_SUCCESS;
311  }
312  }
313 
314  /* Otherwise, assume logical */
316  return STATUS_SUCCESS;
317 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IsRecognizedPartition(PartitionType)
Definition: ntdddisk.h:342
#define ObDereferenceObject
Definition: obfuncs.h:203
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2101
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
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
unsigned short USHORT
Definition: pedump.c:61
#define IsFTPartition(PartitionType)
Definition: ntdddisk.h:307
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
CHAR PartitionType
Definition: part_xbox.c:32
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define IOCTL_DISK_GET_PARTITION_INFO_EX
Definition: ntddk_ex.h:206
#define PAGED_CODE()

Referenced by xHalIoAssignDriveLetters().

◆ HalpSetMountLetter()

NTSTATUS HalpSetMountLetter ( IN PUNICODE_STRING  DeviceName,
UCHAR  DriveLetter 
)

Definition at line 522 of file disksup.c.

524 {
525  PIRP Irp;
526  KEVENT Event;
528  WCHAR Buffer[30];
533  UNICODE_STRING DosDevice, MountMgr;
535 
536  /* Setup the DosDevice name */
537  swprintf(Buffer, L"\\DosDevices\\%c:", DriveLetter);
538  RtlInitUnicodeString(&DosDevice, Buffer);
539 
540  /* Allocate the input buffer for the MountMgr */
541  InputBufferLength = DosDevice.Length + DeviceName->Length + sizeof(MOUNTMGR_CREATE_POINT_INPUT);
543  if (InputBuffer == NULL)
544  {
546  }
547 
548  /* Fill the input buffer */
549  InputBuffer->SymbolicLinkNameOffset = sizeof(MOUNTMGR_CREATE_POINT_INPUT);
550  InputBuffer->SymbolicLinkNameLength = DosDevice.Length;
551  InputBuffer->DeviceNameOffset = DosDevice.Length + sizeof(MOUNTMGR_CREATE_POINT_INPUT);
552  InputBuffer->DeviceNameLength = DeviceName->Length;
553  RtlCopyMemory(&InputBuffer[1], DosDevice.Buffer, DosDevice.Length);
554  RtlCopyMemory((PVOID)((ULONG_PTR)InputBuffer + InputBuffer->DeviceNameOffset),
555  DeviceName->Buffer,
556  DeviceName->Length);
557 
558  /* Get the MountMgr device pointer, to send the IOCTL */
559  RtlInitUnicodeString(&MountMgr, L"\\Device\\MountPointManager");
560  Status = IoGetDeviceObjectPointer(&MountMgr,
562  &FileObject,
563  &DeviceObject);
564  if (!NT_SUCCESS(Status))
565  {
567  return Status;
568  }
569 
570  /* Call the MountMgr */
573  DeviceObject,
574  InputBuffer,
576  NULL,
577  0,
578  FALSE,
579  &Event,
580  &IoStatusBlock);
581  if (Irp == NULL)
582  {
586  }
587 
589  if (Status == STATUS_PENDING)
590  {
592  Executive,
593  KernelMode,
594  FALSE,
595  NULL);
597  }
598 
601 
602  /* Return the MountMgr status */
603  return Status;
604 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_MOUNTMGR_CREATE_POINT
Definition: imports.h:118
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:318
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
Definition: bufpool.h:45
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define ObDereferenceObject
Definition: obfuncs.h:203
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
#define TAG_FSTUB
Definition: tag.h:195
struct _MOUNTMGR_CREATE_POINT_INPUT MOUNTMGR_CREATE_POINT_INPUT
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by HalpNextDriveLetter(), and xHalIoAssignDriveLetters().

◆ IoAssignDriveLetters()

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

Definition at line 2754 of file disksup.c.

2758 {
2759  HALDISPATCH->HalIoAssignDriveLetters(LoaderBlock,
2760  NtDeviceName,
2761  NtSystemPath,
2762  NtSystemPathString);
2763 }
#define HALDISPATCH
Definition: haltypes.h:278

◆ IopComputeHarddiskDerangements()

PULONG IopComputeHarddiskDerangements ( IN ULONG  DiskCount)

Definition at line 320 of file disksup.c.

321 {
322  PIRP Irp;
323  KEVENT Event;
324  ULONG i, j, k;
325  PULONG Devices;
327  WCHAR Buffer[100];
328  UNICODE_STRING ArcName;
333 
334  /* No disks, nothing to do */
335  if (DiskCount == 0)
336  {
337  return NULL;
338  }
339 
340  /* Allocate a buffer big enough to hold all the disks */
342  sizeof(ULONG) * DiskCount,
343  TAG_FSTUB);
344  if (Devices == NULL)
345  {
346  return NULL;
347  }
348 
349  /* Now, we'll query all the disks */
350  for (i = 0; i < DiskCount; ++i)
351  {
352  /* Using their ARC name */
353  swprintf(Buffer, L"\\ArcName\\multi(0)disk(0)rdisk(%d)", i);
354  RtlInitUnicodeString(&ArcName, Buffer);
355  /* Get the attached DeviceObject */
357  {
360 
361  /* And query it for device number */
364  DeviceObject,
365  NULL,
366  0,
367  &DeviceNumber,
368  sizeof(DeviceNumber),
369  FALSE,
370  &Event,
371  &IoStatusBlock);
372  if (Irp != NULL)
373  {
375  if (Status == STATUS_PENDING)
376  {
378  Executive,
379  KernelMode,
380  FALSE,
381  NULL);
383  }
384 
386 
387  /* In case of a success remember device number */
388  if (NT_SUCCESS(Status))
389  {
390  Devices[i] = DeviceNumber.DeviceNumber;
391  /* Move on, not to fall into our default case */
392  continue;
393  }
394  }
395  else
396  {
398  }
399 
400  /* Default case, for failures, set -1 */
401  Devices[i] = -1;
402  }
403  }
404 
405  /* Now, we'll check all device numbers */
406  for (i = 0; i < DiskCount; ++i)
407  {
408  /* First of all, check if we're at the right place */
409  for (j = 0; j < DiskCount; ++j)
410  {
411  if (Devices[j] == i)
412  {
413  break;
414  }
415  }
416 
417  /* If not, perform the change */
418  if (j >= DiskCount)
419  {
420  k = 0;
421  while (Devices[k] != -1)
422  {
423  if (++k >= DiskCount)
424  {
425  break;
426  }
427  }
428 
429  if (k < DiskCount)
430  {
431  Devices[k] = i;
432  }
433  }
434  }
435 
436  /* Return our device derangement map */
437  return Devices;
438 }
LONG NTSTATUS
Definition: precomp.h:26
#define POOL_COLD_ALLOCATION
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
Definition: bufpool.h:45
#define IOCTL_STORAGE_GET_DEVICE_NUMBER
Definition: ntddstor.h:143
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
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
Status
Definition: gdiplustypes.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define ObDereferenceObject
Definition: obfuncs.h:203
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
#define TAG_FSTUB
Definition: tag.h:195
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
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
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1229
int k
Definition: mpi.c:3369

Referenced by xHalIoAssignDriveLetters().

◆ IoReadPartitionTable()

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

Definition at line 2704 of file disksup.c.

2708 {
2709  return HALDISPATCH->HalIoReadPartitionTable(DeviceObject,
2710  SectorSize,
2712  PartitionBuffer);
2713 }
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2048
_In_ ULONG _In_ BOOLEAN ReturnRecognizedPartitions
Definition: iofuncs.h:2046
_In_ ULONG SectorSize
Definition: halfuncs.h:291
#define HALDISPATCH
Definition: haltypes.h:278

◆ IoSetPartitionInformation()

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

Definition at line 2720 of file disksup.c.

2724 {
2725  return HALDISPATCH->HalIoSetPartitionInformation(DeviceObject,
2726  SectorSize,
2728  PartitionType);
2729 }
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
CHAR PartitionType
Definition: part_xbox.c:32
_In_ ULONG SectorSize
Definition: halfuncs.h:291
#define HALDISPATCH
Definition: haltypes.h:278

◆ IoWritePartitionTable()

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

Definition at line 2736 of file disksup.c.

2741 {
2742  return HALDISPATCH->HalIoWritePartitionTable(DeviceObject,
2743  SectorSize,
2745  NumberOfHeads,
2746  PartitionBuffer);
2747 }
_In_ ULONG _In_ ULONG _In_ ULONG NumberOfHeads
Definition: iofuncs.h:2066
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ ULONG _In_ ULONG SectorsPerTrack
Definition: iofuncs.h:2066
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2048
_In_ ULONG SectorSize
Definition: halfuncs.h:291
#define HALDISPATCH
Definition: haltypes.h:278

◆ xHalExamineMBR()

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

Definition at line 1643 of file disksup.c.

1647 {
1649  PUCHAR Buffer;
1650  ULONG BufferSize;
1651  KEVENT Event;
1653  PIRP Irp;
1654  PPARTITION_DESCRIPTOR PartitionDescriptor;
1655  NTSTATUS Status;
1656  PIO_STACK_LOCATION IoStackLocation;
1657 
1658  Offset.QuadPart = 0;
1659 
1660  /* Assume failure */
1661  *MbrBuffer = NULL;
1662 
1663  /* Normalize the buffer size */
1664  BufferSize = max(512, SectorSize);
1665 
1666  /* Allocate the buffer */
1669  TAG_FILE_SYSTEM);
1670  if (!Buffer) return;
1671 
1672  /* Initialize the Event */
1674 
1675  /* Build the IRP */
1677  DeviceObject,
1678  Buffer,
1679  BufferSize,
1680  &Offset,
1681  &Event,
1682  &IoStatusBlock);
1683  if (!Irp)
1684  {
1685  /* Failed */
1687  return;
1688  }
1689 
1690  /* Make sure to override volume verification */
1691  IoStackLocation = IoGetNextIrpStackLocation(Irp);
1692  IoStackLocation->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
1693 
1694  /* Call the driver */
1696  if (Status == STATUS_PENDING)
1697  {
1698  /* Wait for completion */
1701  }
1702 
1703  /* Check driver Status */
1704  if (NT_SUCCESS(Status))
1705  {
1706  /* Validate the MBR Signature */
1708  {
1709  /* Failed */
1711  return;
1712  }
1713 
1714  /* Get the partition entry */
1715  PartitionDescriptor = (PPARTITION_DESCRIPTOR)
1717 
1718  /* Make sure it's what the caller wanted */
1719  if (PartitionDescriptor->PartitionType != MbrTypeIdentifier)
1720  {
1721  /* It's not, free our buffer */
1723  }
1724  else
1725  {
1726  /* Check for OnTrack Disk Manager 6.0 / EZ-Drive partitions */
1727 
1728  if (PartitionDescriptor->PartitionType == PARTITION_DM)
1729  {
1730  /* Return our buffer, but at sector 63 */
1731  *(PULONG)Buffer = 63;
1732  *MbrBuffer = Buffer;
1733  }
1734  else if (PartitionDescriptor->PartitionType == PARTITION_EZDRIVE)
1735  {
1736  /* EZ-Drive, return the buffer directly */
1737  *MbrBuffer = Buffer;
1738  }
1739  else
1740  {
1741  /* Otherwise crash on debug builds */
1742  ASSERT(PartitionDescriptor->PartitionType == PARTITION_EZDRIVE);
1743  }
1744  }
1745  }
1746 }
#define TAG_FILE_SYSTEM
Definition: tag.h:50
#define max(a, b)
Definition: svc.c:63
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
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
unsigned char * PUCHAR
Definition: retypes.h:3
#define PARTITION_EZDRIVE
Definition: ntdddisk.h:289
LONG NTSTATUS
Definition: precomp.h:26
#define PARTITION_TABLE_OFFSET
Definition: hal.h:243
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1803
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
#define PARTITION_DM
Definition: ntdddisk.h:288
#define ASSERT(a)
Definition: mode.c:45
#define BOOT_RECORD_SIGNATURE
Definition: parttest.c:17
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
UCHAR PartitionType
Definition: hal.h:282
struct _PARTITION_DESCRIPTOR * PPARTITION_DESCRIPTOR
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define BOOT_SIGNATURE_OFFSET
Definition: hal.h:244
#define PAGE_SIZE
Definition: env_spec_w32.h:49
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MJ_READ
Definition: rdpdr.c:46
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
_In_ ULONG SectorSize
Definition: halfuncs.h:291
unsigned short * PUSHORT
Definition: retypes.h:2
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251

◆ xHalGetPartialGeometry()

VOID FASTCALL xHalGetPartialGeometry ( IN PDEVICE_OBJECT  DeviceObject,
IN PULONG  ConventionalCylinders,
IN PLONGLONG  DiskSize 
)

Definition at line 1557 of file disksup.c.

1560 {
1561  PDISK_GEOMETRY DiskGeometry = NULL;
1563  PKEVENT Event = NULL;
1564  PIRP Irp;
1565  NTSTATUS Status;
1566 
1567  /* Set defaults */
1568  *ConventionalCylinders = 0;
1569  *DiskSize = 0;
1570 
1571  /* Allocate the structure in nonpaged pool */
1572  DiskGeometry = ExAllocatePoolWithTag(NonPagedPool,
1573  sizeof(DISK_GEOMETRY),
1574  TAG_FILE_SYSTEM);
1575  if (!DiskGeometry) goto Cleanup;
1576 
1577  /* Allocate the status block in nonpaged pool */
1579  sizeof(IO_STATUS_BLOCK),
1580  TAG_FILE_SYSTEM);
1581  if (!IoStatusBlock) goto Cleanup;
1582 
1583  /* Allocate the event in nonpaged pool too */
1585  sizeof(KEVENT),
1586  TAG_FILE_SYSTEM);
1587  if (!Event) goto Cleanup;
1588 
1589  /* Initialize the event */
1591 
1592  /* Build the IRP */
1594  DeviceObject,
1595  NULL,
1596  0,
1597  DiskGeometry,
1598  sizeof(DISK_GEOMETRY),
1599  FALSE,
1600  Event,
1601  IoStatusBlock);
1602  if (!Irp) goto Cleanup;
1603 
1604  /* Now call the driver */
1606  if (Status == STATUS_PENDING)
1607  {
1608  /* Wait for it to complete */
1611  }
1612 
1613  /* Check driver status */
1614  if (NT_SUCCESS(Status))
1615  {
1616  /* Return the cylinder count */
1617  *ConventionalCylinders = DiskGeometry->Cylinders.LowPart;
1618 
1619  /* Make sure it's not larger then 1024 */
1620  if (DiskGeometry->Cylinders.LowPart >= 1024)
1621  {
1622  /* Otherwise, normalize the value */
1623  *ConventionalCylinders = 1024;
1624  }
1625 
1626  /* Calculate the disk size */
1627  *DiskSize = DiskGeometry->Cylinders.QuadPart *
1628  DiskGeometry->TracksPerCylinder *
1629  DiskGeometry->SectorsPerTrack *
1630  DiskGeometry->BytesPerSector;
1631  }
1632 
1633 Cleanup:
1634  /* Free all the pointers */
1637  if (DiskGeometry) ExFreePoolWithTag(DiskGeometry, TAG_FILE_SYSTEM);
1638  return;
1639 }
#define TAG_FILE_SYSTEM
Definition: tag.h:50
LONG NTSTATUS
Definition: precomp.h:26
ULONG BytesPerSector
Definition: ntdddisk.h:442
ULONG TracksPerCylinder
Definition: ntdddisk.h:440
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:438
ULONG SectorsPerTrack
Definition: ntdddisk.h:441
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG LowPart
Definition: typedefs.h:106
static const WCHAR Cleanup[]
Definition: register.c:80
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by xHalIoWritePartitionTable().

◆ xHalIoAssignDriveLetters()

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

Definition at line 912 of file disksup.c.

916 {
917  USHORT i;
918  PULONG Devices;
920  WCHAR Buffer[50];
922  UCHAR DriveLetter;
923  BOOLEAN SystemFound;
924  IO_STATUS_BLOCK StatusBlock;
926  ANSI_STRING StringA1, StringA2;
927  PSTR Buffer1, Buffer2, LoadOptions;
929  PDRIVE_LAYOUT_INFORMATION LayoutInfo;
930  PCONFIGURATION_INFORMATION ConfigInfo;
931  UNICODE_STRING StringU1, StringU2, StringU3;
932  ULONG Increment, DiskCount, RealDiskCount, HarddiskCount, PartitionCount, SystemPartition;
933 
934  PAGED_CODE();
935 
936  /* Get our disk count */
937  ConfigInfo = IoGetConfigurationInformation();
938  DiskCount = ConfigInfo->DiskCount;
939  RealDiskCount = 0;
940 
941  /* Allocate two generic string buffers we'll use and reuser later on */
944  if (Buffer1 == NULL || Buffer2 == NULL)
945  {
946  KeBugCheck(ASSIGN_DRIVE_LETTERS_FAILED);
947  }
948 
949  /* In case of a remote boot, setup system path */
950  if (IoRemoteBootClient)
951  {
952  PSTR Last, Saved;
953 
954  /* Find last \ */
955  Last = strrchr(LoaderBlock->NtBootPathName, '\\');
956  Saved = NULL;
957  /* Misformed name, fail */
958  if (Last == NULL)
959  {
960  KeBugCheck(ASSIGN_DRIVE_LETTERS_FAILED);
961  }
962 
963  /* In case the name was terminated by a \... */
964  if (Last[1] == ANSI_NULL)
965  {
966  /* Erase it, save position and find the previous \ */
967  *Last = ANSI_NULL;
968  Saved = Last;
969  Last = strrchr(LoaderBlock->NtBootPathName, '\\');
970  *Saved = '\\';
971  }
972 
973  /* Misformed name, fail */
974  if (Last == NULL)
975  {
976  KeBugCheck(ASSIGN_DRIVE_LETTERS_FAILED);
977  }
978 
979  /* For a remote boot, assign X drive letter */
980  NtSystemPath[0] = 'X';
981  NtSystemPath[1] = ':';
982  /* And copy the end of the boot path */
983  strcpy((PSTR)&NtSystemPath[2], Last);
984 
985  /* If we had to remove the trailing \, remove it here too */
986  if (Saved != NULL)
987  {
988  NtSystemPath[strlen((PSTR)NtSystemPath) - 1] = ANSI_NULL;
989  }
990 
991  /* Setup output string */
992  RtlInitString(NtSystemPathString, (PSTR)NtSystemPath);
993  }
994 
995  /* For each of our disks, create the physical device DOS device */
996  Increment = 0;
997  if (DiskCount != 0)
998  {
999  for (i = 0; i < DiskCount; ++i)
1000  {
1001  /* Setup the origin name */
1002  sprintf(Buffer1, "\\Device\\Harddisk%d\\Partition%d", i, 0);
1003  RtlInitAnsiString(&StringA1, Buffer1);
1004  if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&StringU1, &StringA1, TRUE)))
1005  {
1006  /* We cannot fail */
1007  KeBugCheck(ASSIGN_DRIVE_LETTERS_FAILED);
1008  }
1009 
1010  /* Open the device */
1012  &StringU1,
1014  NULL,
1015  NULL);
1019  &StatusBlock,
1022  if (NT_SUCCESS(Status))
1023  {
1024  /* If we managed, create the link */
1025  sprintf(Buffer2, "\\DosDevices\\PhysicalDrive%d", i);
1026  RtlInitAnsiString(&StringA2, Buffer2);
1027  Status = RtlAnsiStringToUnicodeString(&StringU2, &StringA2, TRUE);
1028  if (NT_SUCCESS(Status))
1029  {
1030  IoCreateSymbolicLink(&StringU2, &StringU1);
1031  RtlFreeUnicodeString(&StringU2);
1032  }
1033 
1035 
1036  RealDiskCount = i + 1;
1037  }
1038 
1039  RtlFreeUnicodeString(&StringU1);
1040 
1041  if (!NT_SUCCESS(Status))
1042  {
1043  if (Increment < 50)
1044  {
1045  ++Increment;
1046  ++DiskCount;
1047  }
1048  }
1049  }
1050  }
1051 
1052  /* We done for our buffers */
1053  ExFreePoolWithTag(Buffer1, TAG_FSTUB);
1054  ExFreePoolWithTag(Buffer2, TAG_FSTUB);
1055 
1056  /* Upcase our load options, if any */
1057  if (LoaderBlock->LoadOptions != NULL)
1058  {
1059  LoadOptions = _strupr(LoaderBlock->LoadOptions);
1060  }
1061  else
1062  {
1063  LoadOptions = NULL;
1064  }
1065 
1066  /* If we boot with /MININT (system hive as volatile) option, assign X letter to boot device */
1067  if (LoadOptions != NULL &&
1068  strstr(LoadOptions, "MININT") != 0 &&
1069  NT_SUCCESS(RtlAnsiStringToUnicodeString(&StringU1, NtDeviceName, TRUE)))
1070  {
1071  if (NT_SUCCESS(HalpSetMountLetter(&StringU1, 'X')))
1072  {
1073  *NtSystemPath = 'X';
1074  }
1075 
1076  RtlFreeUnicodeString(&StringU1);
1077  }
1078 
1079  /* Compute our disks derangements */
1080  DiskCount -= Increment;
1081  if (RealDiskCount > DiskCount)
1082  {
1083  DiskCount = RealDiskCount;
1084  }
1085  Devices = IopComputeHarddiskDerangements(DiskCount);
1086 
1087  /* Now, start browsing all our disks for assigning drive letters
1088  * Here, we'll only handle boot partition and primary partitions
1089  */
1090  HarddiskCount = 0;
1091  for (i = 0; i < DiskCount; ++i)
1092  {
1093  /* Get device ID according to derangements map */
1094  if (Devices != NULL)
1095  {
1096  HarddiskCount = Devices[i];
1097  }
1098 
1099  /* Query disk layout */
1100  swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition0", HarddiskCount);
1101  RtlInitUnicodeString(&StringU1, Buffer);
1102  if (!NT_SUCCESS(HalpQueryDriveLayout(&StringU1, &LayoutInfo)))
1103  {
1104  LayoutInfo = NULL;
1105  }
1106 
1107  /* Assume we didn't find system */
1108  SystemFound = FALSE;
1109  swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, 1);
1110  RtlInitUnicodeString(&StringU1, Buffer);
1111  /* Query partition info for our disk */
1112  if (!NT_SUCCESS(HalpQueryPartitionType(&StringU1, LayoutInfo, &PartitionType)))
1113  {
1114  /* It failed, retry for all the partitions */
1115  for (PartitionCount = 1; ; ++PartitionCount)
1116  {
1117  swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1118  RtlInitUnicodeString(&StringU1, Buffer);
1119  if (!NT_SUCCESS(HalpQueryPartitionType(&StringU1, LayoutInfo, &PartitionType)))
1120  {
1121  break;
1122  }
1123 
1124  /* We found a primary partition, assign a drive letter */
1126  {
1127  HalpNextDriveLetter(&StringU1, NtDeviceName, NtSystemPath, 0);
1128  break;
1129  }
1130  }
1131  }
1132  else
1133  {
1134  /* All right */
1135  for (PartitionCount = 2; ; ++PartitionCount)
1136  {
1137  /* If our partition is bootable (MBR) or data (GPT), that's system partition */
1139  {
1140  SystemFound = TRUE;
1141 
1142  /* Assign a drive letter and stop here if MBR */
1143  HalpNextDriveLetter(&StringU1, NtDeviceName, NtSystemPath, 0);
1145  {
1146  break;
1147  }
1148  }
1149 
1150  /* Keep looping on all the partitions */
1151  swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1152  RtlInitUnicodeString(&StringU1, Buffer);
1153  if (!NT_SUCCESS(HalpQueryPartitionType(&StringU1, LayoutInfo, &PartitionType)))
1154  {
1155  /* Mount every primary partition if we didn't find system */
1156  if (!SystemFound)
1157  {
1158  for (PartitionCount = 1; ; ++PartitionCount)
1159  {
1160  swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1161  RtlInitUnicodeString(&StringU1, Buffer);
1162  if (!NT_SUCCESS(HalpQueryPartitionType(&StringU1, LayoutInfo, &PartitionType)))
1163  {
1164  break;
1165  }
1166 
1168  {
1169  HalpNextDriveLetter(&StringU1, NtDeviceName, NtSystemPath, 0);
1170  break;
1171  }
1172  }
1173  }
1174 
1175  break;
1176  }
1177  }
1178  }
1179 
1180  /* Free layout, we'll reallocate it for next device */
1181  if (LayoutInfo != NULL)
1182  {
1183  ExFreePoolWithTag(LayoutInfo, TAG_FSTUB);
1184  }
1185 
1186  HarddiskCount = i + 1;
1187  }
1188 
1189  /* Now, assign logical partitions */
1190  for (i = 0; i < DiskCount; ++i)
1191  {
1192  /* Get device ID according to derangements map */
1193  if (Devices != NULL)
1194  {
1195  HarddiskCount = Devices[i];
1196  }
1197  else
1198  {
1199  HarddiskCount = i;
1200  }
1201 
1202  /* Query device layout */
1203  swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition0", HarddiskCount);
1204  RtlInitUnicodeString(&StringU1, Buffer);
1205  if (!NT_SUCCESS(HalpQueryDriveLayout(&StringU1, &LayoutInfo)))
1206  {
1207  LayoutInfo = NULL;
1208  }
1209 
1210  /* And assign drive letter to logical partitions */
1211  for (PartitionCount = 1; ; ++PartitionCount)
1212  {
1213  swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1214  RtlInitUnicodeString(&StringU1, Buffer);
1215  if (!NT_SUCCESS(HalpQueryPartitionType(&StringU1, LayoutInfo, &PartitionType)))
1216  {
1217  break;
1218  }
1219 
1221  {
1222  HalpNextDriveLetter(&StringU1, NtDeviceName, NtSystemPath, 0);
1223  }
1224  }
1225 
1226  /* Free layout, we'll reallocate it for next device */
1227  if (LayoutInfo != NULL)
1228  {
1229  ExFreePoolWithTag(LayoutInfo, 0);
1230  }
1231  }
1232 
1233  /* Now, assign drive letters to everything else */
1234  for (i = 0; i < DiskCount; ++i)
1235  {
1236  /* Get device ID according to derangements map */
1237  if (Devices != NULL)
1238  {
1239  HarddiskCount = Devices[i];
1240  }
1241  else
1242  {
1243  HarddiskCount = i;
1244  }
1245 
1246  /* Query device layout */
1247  swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition0", HarddiskCount);
1248  RtlInitUnicodeString(&StringU1, Buffer);
1249  if (!NT_SUCCESS(HalpQueryDriveLayout(&StringU1, &LayoutInfo)))
1250  {
1251  LayoutInfo = NULL;
1252  }
1253 
1254  /* Save system partition if any */
1255  SystemPartition = 0;
1256  for (PartitionCount = 1; ; ++PartitionCount)
1257  {
1258  swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1259  RtlInitUnicodeString(&StringU1, Buffer);
1260  if (!NT_SUCCESS(HalpQueryPartitionType(&StringU1, LayoutInfo, &PartitionType)))
1261  {
1262  break;
1263  }
1264 
1266  {
1267  SystemPartition = PartitionCount;
1268  }
1269  }
1270 
1271  /* And assign drive letter to anything but system partition */
1272  for (PartitionCount = 1; ; ++PartitionCount)
1273  {
1274  if (PartitionCount != SystemPartition)
1275  {
1276  swprintf(Buffer, L"\\Device\\Harddisk%d\\Partition%d", HarddiskCount, PartitionCount);
1277  RtlInitUnicodeString(&StringU1, Buffer);
1278  if (!NT_SUCCESS(HalpQueryPartitionType(&StringU1, LayoutInfo, &PartitionType)))
1279  {
1280  if (LayoutInfo != NULL)
1281  {
1282  ExFreePoolWithTag(LayoutInfo, 0);
1283  }
1284 
1285  break;
1286  }
1287 
1289  {
1290  HalpNextDriveLetter(&StringU1, NtDeviceName, NtSystemPath, 0);
1291  }
1292  }
1293  }
1294  }
1295 
1296  /* We're done with disks, if we have a device map, free it */
1297  if (Devices != NULL)
1298  {
1299  ExFreePoolWithTag(Devices, TAG_FSTUB);
1300  }
1301 
1302  /* Now, assign drive letter to floppy drives */
1303  for (i = 0; i < ConfigInfo->FloppyCount; ++i)
1304  {
1305  swprintf(Buffer, L"\\Device\\Floppy%d", i);
1306  RtlInitUnicodeString(&StringU1, Buffer);
1307  if (HalpIsOldStyleFloppy(&StringU1))
1308  {
1309  HalpNextDriveLetter(&StringU1, NtDeviceName, NtSystemPath, TRUE);
1310  }
1311  }
1312 
1313  /* And CD drives */
1314  for (i = 0; i < ConfigInfo->CdRomCount; ++i)
1315  {
1316  swprintf(Buffer, L"\\Device\\CdRom%d", i);
1317  RtlInitUnicodeString(&StringU1, Buffer);
1318  HalpNextDriveLetter(&StringU1, NtDeviceName, NtSystemPath, TRUE);
1319  }
1320 
1321  /* If not remote boot, handle NtDeviceName */
1322  if (!IoRemoteBootClient && NT_SUCCESS(RtlAnsiStringToUnicodeString(&StringU1, NtDeviceName, TRUE)))
1323  {
1324  /* Assign it a drive letter */
1325  DriveLetter = HalpNextDriveLetter(&StringU1, NULL, NULL, TRUE);
1326  if (DriveLetter != 0)
1327  {
1328  if (DriveLetter != 0xFF)
1329  {
1330  *NtSystemPath = DriveLetter;
1331  }
1332  }
1333  /* If it fails through mount manager, retry manually */
1334  else
1335  {
1336  RtlInitUnicodeString(&StringU2, L"\\Device\\Floppy");
1337  RtlInitUnicodeString(&StringU3, L"\\Device\\CdRom");
1338 
1339  if (RtlPrefixUnicodeString(&StringU2, &StringU1, TRUE))
1340  {
1341  DriveLetter = 'A';
1342  }
1343  else if (RtlPrefixUnicodeString(&StringU3, &StringU1, TRUE))
1344  {
1345  DriveLetter = 'D';
1346  }
1347  else
1348  {
1349  DriveLetter = 'C';
1350  }
1351 
1352  /* Try any drive letter */
1353  while (HalpSetMountLetter(&StringU1, DriveLetter) != STATUS_SUCCESS)
1354  {
1355  ++DriveLetter;
1356 
1357  if (DriveLetter > 'Z')
1358  {
1359  break;
1360  }
1361  }
1362 
1363  /* If we're beyond Z (ie, no slot left) */
1364  if (DriveLetter > 'Z')
1365  {
1366  /* Delete Z, and reuse it for system */
1367  HalpDeleteMountLetter('Z');
1368  HalpSetMountLetter(&StringU1, 'Z');
1369  *NtSystemPath = 'Z';
1370  }
1371  else
1372  {
1373  /* Return matching drive letter */
1374  *NtSystemPath = DriveLetter;
1375  }
1376  }
1377 
1378  RtlFreeUnicodeString(&StringU1);
1379  }
1380 
1381  /* Enable auto assignement for mountmgr */
1383 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Definition: iorsrce.c:830
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
LONG NTSTATUS
Definition: precomp.h:26
VOID HalpEnableAutomaticDriveLetterAssignment(VOID)
Definition: disksup.c:857
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
NTSTATUS HalpDeleteMountLetter(UCHAR DriveLetter)
Definition: disksup.c:766
#define FILE_SHARE_READ
Definition: compat.h:136
NTSTATUS HalpQueryPartitionType(IN PUNICODE_STRING DeviceName, IN PDRIVE_LAYOUT_INFORMATION LayoutInfo, OUT PPARTITION_TYPE PartitionType)
Definition: disksup.c:165
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define sprintf(buf, format,...)
Definition: sprintf.c:55
HANDLE FileHandle
Definition: stats.c:38
#define FALSE
Definition: types.h:117
#define ANSI_NULL
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
#define FILE_READ_DATA
Definition: nt_native.h:628
unsigned char BOOLEAN
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
UCHAR HalpNextDriveLetter(IN PUNICODE_STRING DeviceName, IN PSTRING NtDeviceName, OUT PUCHAR NtSystemPath, BOOLEAN IsRemovable)
Definition: disksup.c:607
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
static PPARTENTRY SystemPartition
Definition: usetup.c:61
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
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)
NTSTATUS HalpSetMountLetter(IN PUNICODE_STRING DeviceName, UCHAR DriveLetter)
Definition: disksup.c:522
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
#define TAG_FSTUB
Definition: tag.h:195
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI VOID NTAPI RtlInitString(PSTRING DestinationString, PCSZ SourceString)
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
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
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
signed char * PSTR
Definition: retypes.h:7
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
PULONG IopComputeHarddiskDerangements(IN ULONG DiskCount)
Definition: disksup.c:320
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
BOOLEAN HalpIsOldStyleFloppy(PUNICODE_STRING DeviceName)
Definition: disksup.c:707
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
CHAR PartitionType
Definition: part_xbox.c:32
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS FASTCALL HalpQueryDriveLayout(IN PUNICODE_STRING DeviceName, OUT PDRIVE_LAYOUT_INFORMATION *LayoutInfo)
Definition: disksup.c:56
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42
#define PAGED_CODE()
BOOLEAN IoRemoteBootClient
Definition: init.c:68

◆ xHalIoReadPartitionTable()

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

Definition at line 1769 of file disksup.c.

1773 {
1774  KEVENT Event;
1776  PIRP Irp;
1777  PPARTITION_DESCRIPTOR PartitionDescriptor;
1778  CCHAR Entry;
1779  NTSTATUS Status;
1781  PUCHAR Buffer = NULL;
1782  ULONG BufferSize = 2048, InputSize;
1783  PDRIVE_LAYOUT_INFORMATION DriveLayoutInfo = NULL;
1784  LONG j = -1, i = -1, k;
1785  DISK_GEOMETRY_EX DiskGeometryEx;
1786  LONGLONG EndSector, MaxSector, StartOffset;
1787  LARGE_INTEGER Offset, VolumeOffset;
1788  BOOLEAN IsPrimary = TRUE, IsEzDrive = FALSE, MbrFound = FALSE;
1789  BOOLEAN IsValid, IsEmpty = TRUE;
1790  PVOID MbrBuffer;
1791  PIO_STACK_LOCATION IoStackLocation;
1793  LARGE_INTEGER HiddenSectors64;
1794 
1795  PAGED_CODE();
1796 
1797  VolumeOffset.QuadPart = Offset.QuadPart = 0;
1798 
1799  /* Allocate the buffer */
1801  BufferSize,
1802  TAG_FILE_SYSTEM);
1804 
1805  /* Normalize the buffer size */
1806  InputSize = max(512, SectorSize);
1807 
1808  /* Check for EZ-Drive */
1809  HalExamineMBR(DeviceObject, InputSize, PARTITION_EZDRIVE, &MbrBuffer);
1810  if (MbrBuffer)
1811  {
1812  /* EZ-Drive found, bias the offset */
1813  IsEzDrive = TRUE;
1814  ExFreePoolWithTag(MbrBuffer, TAG_FILE_SYSTEM);
1815  Offset.QuadPart = 512;
1816  }
1817 
1818  /* Get drive geometry */
1819  Status = HalpGetFullGeometry(DeviceObject, &DiskGeometryEx);
1820  if (!NT_SUCCESS(Status))
1821  {
1823  *PartitionBuffer = NULL;
1824  return Status;
1825  }
1826 
1827  /* Get the end and maximum sector */
1828  EndSector = DiskGeometryEx.DiskSize.QuadPart / DiskGeometryEx.Geometry.BytesPerSector;
1829  MaxSector = EndSector << 1;
1830  DPRINT("FSTUB: DiskSize = %#I64x, MaxSector = %#I64x\n",
1831  DiskGeometryEx.DiskSize, MaxSector);
1832 
1833  /* Allocate our buffer */
1835  if (!Buffer)
1836  {
1837  /* Fail, free the input buffer */
1839  *PartitionBuffer = NULL;
1841  }
1842 
1843  /* Start partition loop */
1844  do
1845  {
1846  /* Assume the partition is valid */
1847  IsValid = TRUE;
1848 
1849  /* Initialize the event */
1851 
1852  /* Clear the buffer and build the IRP */
1853  RtlZeroMemory(Buffer, InputSize);
1855  DeviceObject,
1856  Buffer,
1857  InputSize,
1858  &Offset,
1859  &Event,
1860  &IoStatusBlock);
1861  if (!Irp)
1862  {
1863  /* Failed */
1865  break;
1866  }
1867 
1868  /* Make sure to disable volume verification */
1869  IoStackLocation = IoGetNextIrpStackLocation(Irp);
1870  IoStackLocation->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
1871 
1872  /* Call the driver */
1874  if (Status == STATUS_PENDING)
1875  {
1876  /* Wait for completion */
1879  }
1880 
1881  /* Normalize status code and check for failure */
1883  if (!NT_SUCCESS(Status)) break;
1884 
1885  /* If we biased for EZ-Drive, unbias now */
1886  if (IsEzDrive && (Offset.QuadPart == 512)) Offset.QuadPart = 0;
1887 
1888  /* Make sure this is a valid MBR */
1890  {
1891  /* It's not, fail */
1892  DPRINT1("FSTUB: (IoReadPartitionTable) No 0xaa55 found in "
1893  "partition table %d\n", j + 1);
1894  break;
1895  }
1896 
1897  /* At this point we have a valid MBR */
1898  MbrFound = TRUE;
1899 
1900  /* Check if we weren't given an offset */
1901  if (!Offset.QuadPart)
1902  {
1903  /* Then read the signature off the disk */
1904  (*PartitionBuffer)->Signature = ((PULONG)Buffer)[PARTITION_TABLE_OFFSET / 2 - 1];
1905  }
1906 
1907  /* Get the partition descriptor array */
1908  PartitionDescriptor = (PPARTITION_DESCRIPTOR)
1910 
1911  /* Start looping partitions */
1912  j++;
1913  DPRINT("FSTUB: Partition Table %d:\n", j);
1914  for (Entry = 1, k = 0; Entry <= NUM_PARTITION_TABLE_ENTRIES; Entry++, PartitionDescriptor++)
1915  {
1916  /* Get the partition type */
1917  PartitionType = PartitionDescriptor->PartitionType;
1918 
1919  /* Print debug messages */
1920  DPRINT("Partition Entry %d,%d: type %#x %s\n",
1921  j,
1922  Entry,
1923  PartitionType,
1924  (PartitionDescriptor->ActiveFlag) ? "Active" : "");
1925  DPRINT("\tOffset %#08lx for %#08lx Sectors\n",
1926  GET_STARTING_SECTOR(PartitionDescriptor),
1927  GET_PARTITION_LENGTH(PartitionDescriptor));
1928 
1929  /* Check whether we're facing a protective MBR */
1931  {
1932  /* Partition length might be bigger than disk size */
1933  FstubFixupEfiPartition(PartitionDescriptor, DiskGeometryEx.DiskSize.QuadPart);
1934  }
1935 
1936  /* Make sure that the partition is valid, unless it's the first */
1937  if (!(HalpIsValidPartitionEntry(PartitionDescriptor,
1938  DiskGeometryEx.DiskSize.QuadPart,
1939  MaxSector)) && (j == 0))
1940  {
1941  /* It's invalid, so fail */
1942  IsValid = FALSE;
1943  break;
1944  }
1945 
1946  /* Check if it's a container */
1948  {
1949  /* Increase the count of containers */
1950  if (++k != 1)
1951  {
1952  /* More then one table is invalid */
1953  DPRINT1("FSTUB: Multiple container partitions found in "
1954  "partition table %d\n - table is invalid\n",
1955  j);
1956  IsValid = FALSE;
1957  break;
1958  }
1959  }
1960 
1961  /* Check if the partition is supposedly empty */
1962  if (IsEmpty)
1963  {
1964  /* But check if it actually has a start and/or length */
1965  if ((GET_STARTING_SECTOR(PartitionDescriptor)) ||
1966  (GET_PARTITION_LENGTH(PartitionDescriptor)))
1967  {
1968  /* So then it's not really empty */
1969  IsEmpty = FALSE;
1970  }
1971  }
1972 
1973  /* Check if the caller wanted only recognized partitions */
1975  {
1976  /* Then check if this one is unused, or a container */
1979  {
1980  /* Skip it, since the caller doesn't want it */
1981  continue;
1982  }
1983  }
1984 
1985  /* Increase the structure count and check if they can fit */
1986  if ((sizeof(DRIVE_LAYOUT_INFORMATION) +
1987  (++i * sizeof(PARTITION_INFORMATION))) >
1988  BufferSize)
1989  {
1990  /* Allocate a new buffer that's twice as big */
1991  DriveLayoutInfo = ExAllocatePoolWithTag(NonPagedPool,
1992  BufferSize << 1,
1993  TAG_FILE_SYSTEM);
1994  if (!DriveLayoutInfo)
1995  {
1996  /* Out of memory, undo this extra structure */
1997  --i;
1999  break;
2000  }
2001 
2002  /* Copy the contents of the old buffer */
2003  RtlMoveMemory(DriveLayoutInfo,
2004  *PartitionBuffer,
2005  BufferSize);
2006 
2007  /* Free the old buffer and set this one as the new one */
2009  *PartitionBuffer = DriveLayoutInfo;
2010 
2011  /* Double the size */
2012  BufferSize <<= 1;
2013  }
2014 
2015  /* Now get the current structure being filled and initialize it */
2016  PartitionInfo = &(*PartitionBuffer)->PartitionEntry[i];
2017  PartitionInfo->PartitionType = PartitionType;
2018  PartitionInfo->RewritePartition = FALSE;
2019 
2020  /* Check if we're dealing with a partition that's in use */
2022  {
2023  /* Check if it's bootable */
2024  PartitionInfo->BootIndicator = PartitionDescriptor->
2025  ActiveFlag & 0x80 ?
2026  TRUE : FALSE;
2027 
2028  /* Check if its' a container */
2030  {
2031  /* Then don't recognize it and use the volume offset */
2032  PartitionInfo->RecognizedPartition = FALSE;
2033  StartOffset = VolumeOffset.QuadPart;
2034  }
2035  else
2036  {
2037  /* Then recognize it and use the partition offset */
2038  PartitionInfo->RecognizedPartition = TRUE;
2039  StartOffset = Offset.QuadPart;
2040  }
2041 
2042  /* Get the starting offset */
2043  PartitionInfo->StartingOffset.QuadPart =
2044  StartOffset +
2045  UInt32x32To64(GET_STARTING_SECTOR(PartitionDescriptor),
2046  SectorSize);
2047 
2048  /* Calculate the number of hidden sectors */
2049  HiddenSectors64.QuadPart = (PartitionInfo->
2050  StartingOffset.QuadPart -
2051  StartOffset) /
2052  SectorSize;
2053  PartitionInfo->HiddenSectors = HiddenSectors64.LowPart;
2054 
2055  /* Get the partition length */
2056  PartitionInfo->PartitionLength.QuadPart =
2057  UInt32x32To64(GET_PARTITION_LENGTH(PartitionDescriptor),
2058  SectorSize);
2059 
2060  /* Get the partition number */
2061  /* FIXME: REACTOS HACK -- Needed for xHalIoAssignDriveLetters() */
2062  PartitionInfo->PartitionNumber = (!IsContainerPartition(PartitionType)) ? i + 1 : 0;
2063  }
2064  else
2065  {
2066  /* Otherwise, clear all the relevant fields */
2067  PartitionInfo->BootIndicator = FALSE;
2068  PartitionInfo->RecognizedPartition = FALSE;
2069  PartitionInfo->StartingOffset.QuadPart = 0;
2070  PartitionInfo->PartitionLength.QuadPart = 0;
2071  PartitionInfo->HiddenSectors = 0;
2072 
2073  /* FIXME: REACTOS HACK -- Needed for xHalIoAssignDriveLetters() */
2074  PartitionInfo->PartitionNumber = 0;
2075  }
2076  }
2077 
2078  /* Finish debug log, and check for failure */
2079  DPRINT("\n");
2080  if (!NT_SUCCESS(Status)) break;
2081 
2082  /* Also check if we hit an invalid entry here */
2083  if (!IsValid)
2084  {
2085  /* We did, so break out of the loop minus one entry */
2086  j--;
2087  break;
2088  }
2089 
2090  /* Reset the offset */
2091  Offset.QuadPart = 0;
2092 
2093  /* Go back to the descriptor array and loop it */
2094  PartitionDescriptor = (PPARTITION_DESCRIPTOR)
2096  for (Entry = 1; Entry <= NUM_PARTITION_TABLE_ENTRIES; Entry++, PartitionDescriptor++)
2097  {
2098  /* Check if this is a container partition, since we skipped them */
2099  if (IsContainerPartition(PartitionDescriptor->PartitionType))
2100  {
2101  /* Get its offset */
2102  Offset.QuadPart = VolumeOffset.QuadPart +
2103  UInt32x32To64(
2104  GET_STARTING_SECTOR(PartitionDescriptor),
2105  SectorSize);
2106 
2107  /* If this is a primary partition, this is the volume offset */
2108  if (IsPrimary) VolumeOffset = Offset;
2109 
2110  /* Also update the maximum sector */
2111  MaxSector = GET_PARTITION_LENGTH(PartitionDescriptor);
2112  DPRINT1("FSTUB: MaxSector now = %I64d\n", MaxSector);
2113  break;
2114  }
2115  }
2116 
2117  /* Loop the next partitions, which are not primary anymore */
2118  IsPrimary = FALSE;
2119  } while (Offset.HighPart | Offset.LowPart);
2120 
2121  /* Check if this is a removable device that's probably a super-floppy */
2122  if ((DiskGeometryEx.Geometry.MediaType == RemovableMedia) &&
2123  (j == 0) && (MbrFound) && (IsEmpty))
2124  {
2125  PBOOT_SECTOR_INFO BootSectorInfo = (PBOOT_SECTOR_INFO)Buffer;
2126 
2127  /* Read the jump bytes to detect super-floppy */
2128  if ((BootSectorInfo->JumpByte[0] == 0xeb) ||
2129  (BootSectorInfo->JumpByte[0] == 0xe9))
2130  {
2131  /* Super floppes don't have typical MBRs, so skip them */
2132  DPRINT1("FSTUB: Jump byte %#x found along with empty partition "
2133  "table - disk is a super floppy and has no valid MBR\n",
2134  BootSectorInfo->JumpByte);
2135  j = -1;
2136  }
2137  }
2138 
2139  /* Check if we're still at partition -1 */
2140  if (j == -1)
2141  {
2142  /* The likely cause is the super floppy detection above */
2143  if ((MbrFound) || (DiskGeometryEx.Geometry.MediaType == RemovableMedia))
2144  {
2145  /* Print out debugging information */
2146  DPRINT1("FSTUB: Drive %#p has no valid MBR. Make it into a "
2147  "super-floppy\n",
2148  DeviceObject);
2149  DPRINT1("FSTUB: Drive has %I64d sectors and is %#016I64x "
2150  "bytes large\n",
2151  EndSector, DiskGeometryEx.DiskSize);
2152 
2153  /* We should at least have some sectors */
2154  if (EndSector > 0)
2155  {
2156  /* Get the entry we'll use */
2157  PartitionInfo = &(*PartitionBuffer)->PartitionEntry[0];
2158 
2159  /* Fill it out with data for a super-floppy */
2160  PartitionInfo->RewritePartition = FALSE;
2161  PartitionInfo->RecognizedPartition = TRUE;
2162  PartitionInfo->PartitionType = PARTITION_FAT_16;
2163  PartitionInfo->BootIndicator = FALSE;
2164  PartitionInfo->HiddenSectors = 0;
2165  PartitionInfo->StartingOffset.QuadPart = 0;
2166  PartitionInfo->PartitionLength = DiskGeometryEx.DiskSize;
2167 
2168  /* FIXME: REACTOS HACK -- Needed for xHalIoAssignDriveLetters() */
2169  PartitionInfo->PartitionNumber = 0;
2170 
2171  /* Set the signature and set the count back to 0 */
2172  (*PartitionBuffer)->Signature = 1;
2173  i = 0;
2174  }
2175  }
2176  else
2177  {
2178  /* Otherwise, this isn't a super floppy, so set an invalid count */
2179  i = -1;
2180  }
2181  }
2182 
2183  /* Set the partition count */
2184  (*PartitionBuffer)->PartitionCount = ++i;
2185 
2186  /* If we have no count, delete the signature */
2187  if (!i) (*PartitionBuffer)->Signature = 0;
2188 
2189  /* Free the buffer and check for success */
2191  if (!NT_SUCCESS(Status))
2192  {
2194  *PartitionBuffer = NULL;
2195  }
2196 
2197  /* Return status */
2198  return Status;
2199 }
#define TAG_FILE_SYSTEM
Definition: tag.h:50
#define max(a, b)
Definition: svc.c:63
#define GET_STARTING_SECTOR(p)
Definition: hal.h:252
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define EFI_PMBR_OSTYPE_EFI
Definition: disksup.c:25
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:290
struct _Entry Entry
Definition: kefuncs.h:627
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
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define TRUE
Definition: types.h:120
UCHAR JumpByte[1]
Definition: hal.h:301
unsigned char * PUCHAR
Definition: retypes.h:3
#define PARTITION_EZDRIVE
Definition: ntdddisk.h:289
LONG NTSTATUS
Definition: precomp.h:26
#define PARTITION_TABLE_OFFSET
Definition: hal.h:243
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:316
ULONG BytesPerSector
Definition: ntdddisk.h:442
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
LARGE_INTEGER DiskSize
Definition: ntdddisk.h:447
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
long LONG
Definition: pedump.c:60
DISK_GEOMETRY Geometry
Definition: ntdddisk.h:446
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2048
unsigned char BOOLEAN
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1803
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
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
Status
Definition: gdiplustypes.h:24
int64_t LONGLONG
Definition: typedefs.h:68
#define GET_PARTITION_LENGTH(p)
Definition: hal.h:261
#define BOOT_RECORD_SIGNATURE
Definition: parttest.c:17
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
char CCHAR
Definition: typedefs.h:51
UCHAR PartitionType
Definition: hal.h:282
struct _PARTITION_DESCRIPTOR * PPARTITION_DESCRIPTOR
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2101
MEDIA_TYPE MediaType
Definition: ntdddisk.h:439
#define PARTITION_FAT_16
Definition: disk.h:90
VOID NTAPI FstubFixupEfiPartition(IN PPARTITION_DESCRIPTOR PartitionDescriptor, IN ULONGLONG MaxOffset)
Definition: disksup.c:1750
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
BOOLEAN NTAPI HalpIsValidPartitionEntry(IN PPARTITION_DESCRIPTOR Entry, IN ULONGLONG MaxOffset, IN ULONGLONG MaxSector)
Definition: disksup.c:1441
_In_ ULONG _In_ BOOLEAN ReturnRecognizedPartitions
Definition: iofuncs.h:2046
#define BOOT_SIGNATURE_OFFSET
Definition: hal.h:244
ULONG LowPart
Definition: typedefs.h:106
NTSTATUS NTAPI HalpGetFullGeometry(IN PDEVICE_OBJECT DeviceObject, OUT PDISK_GEOMETRY_EX Geometry)
Definition: disksup.c:1389
#define STATUS_NO_DATA_DETECTED
Definition: udferr_usr.h:131
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
UCHAR ActiveFlag
Definition: hal.h:278
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
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
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_READ
Definition: rdpdr.c:46
CHAR PartitionType
Definition: part_xbox.c:32
#define NUM_PARTITION_TABLE_ENTRIES
Definition: hal.h:247
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
VOID FASTCALL HalExamineMBR(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG MbrTypeIdentifier, OUT PVOID *MbrBuffer)
Definition: disksup.c:2688
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
_In_ ULONG SectorSize
Definition: halfuncs.h:291
#define UInt32x32To64(a, b)
Definition: intsafe.h:250
int k
Definition: mpi.c:3369
unsigned short * PUSHORT
Definition: retypes.h:2
base of all file and directory entries
Definition: entries.h:82
struct _BOOT_SECTOR_INFO * PBOOT_SECTOR_INFO
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
LONGLONG QuadPart
Definition: typedefs.h:114
#define PAGED_CODE()

◆ xHalIoSetPartitionInformation()

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

Definition at line 2203 of file disksup.c.

2207 {
2208  PIRP Irp;
2209  KEVENT Event;
2211  NTSTATUS Status;
2212  LARGE_INTEGER Offset, VolumeOffset;
2213  PUCHAR Buffer = NULL;
2214  ULONG BufferSize;
2215  ULONG i = 0;
2216  ULONG Entry;
2217  PPARTITION_DESCRIPTOR PartitionDescriptor;
2218  BOOLEAN IsPrimary = TRUE, IsEzDrive = FALSE;
2219  PVOID MbrBuffer;
2220  PIO_STACK_LOCATION IoStackLocation;
2221 
2222  PAGED_CODE();
2223 
2224  VolumeOffset.QuadPart = Offset.QuadPart = 0;
2225 
2226  /* Normalize the buffer size */
2227  BufferSize = max(512, SectorSize);
2228 
2229  /* Check for EZ-Drive */
2231  if (MbrBuffer)
2232  {
2233  /* EZ-Drive found, bias the offset */
2234  IsEzDrive = TRUE;
2235  ExFreePoolWithTag(MbrBuffer, TAG_FILE_SYSTEM);
2236  Offset.QuadPart = 512;
2237  }
2238 
2239  /* Allocate our partition buffer */
2242 
2243  /* Initialize the event we'll use and loop partitions */
2245  do
2246  {
2247  /* Reset the event since we reuse it */
2248  KeClearEvent(&Event);
2249 
2250  /* Build the read IRP */
2252  DeviceObject,
2253  Buffer,
2254  BufferSize,
2255  &Offset,
2256  &Event,
2257  &IoStatusBlock);
2258  if (!Irp)
2259  {
2260  /* Fail */
2262  break;
2263  }
2264 
2265  /* Make sure to disable volume verification */
2266  IoStackLocation = IoGetNextIrpStackLocation(Irp);
2267  IoStackLocation->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
2268 
2269  /* Call the driver */
2271  if (Status == STATUS_PENDING)
2272  {
2273  /* Wait for completion */
2276  }
2277 
2278  /* Check for failure */
2279  if (!NT_SUCCESS(Status)) break;
2280 
2281  /* If we biased for EZ-Drive, unbias now */
2282  if (IsEzDrive && (Offset.QuadPart == 512)) Offset.QuadPart = 0;
2283 
2284  /* Make sure this is a valid MBR */
2286  {
2287  /* It's not, fail */
2289  break;
2290  }
2291 
2292  /* Get the partition descriptors and loop them */
2293  PartitionDescriptor = (PPARTITION_DESCRIPTOR)
2295  for (Entry = 1; Entry <= NUM_PARTITION_TABLE_ENTRIES; Entry++, PartitionDescriptor++)
2296  {
2297  /* Check if it's unused or a container partition */
2298  if ((PartitionDescriptor->PartitionType == PARTITION_ENTRY_UNUSED) ||
2299  (IsContainerPartition(PartitionDescriptor->PartitionType)))
2300  {
2301  /* Go to the next one */
2302  continue;
2303  }
2304 
2305  /* It's a valid partition, so increase the partition count */
2306  if (++i == PartitionNumber)
2307  {
2308  /* We found a match, set the type */
2309  PartitionDescriptor->PartitionType = (UCHAR)PartitionType;
2310 
2311  /* Reset the reusable event */
2312  KeClearEvent(&Event);
2313 
2314  /* Build the write IRP */
2316  DeviceObject,
2317  Buffer,
2318  BufferSize,
2319  &Offset,
2320  &Event,
2321  &IoStatusBlock);
2322  if (!Irp)
2323  {
2324  /* Fail */
2326  break;
2327  }
2328 
2329  /* Disable volume verification */
2330  IoStackLocation = IoGetNextIrpStackLocation(Irp);
2331  IoStackLocation->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
2332 
2333  /* Call the driver */
2335  if (Status == STATUS_PENDING)
2336  {
2337  /* Wait for completion */
2339  Executive,
2340  KernelMode,
2341  FALSE,
2342  NULL);
2344  }
2345 
2346  /* We're done, break out of the loop */
2347  break;
2348  }
2349  }
2350 
2351  /* If we looped all the partitions, break out */
2352  if (Entry <= NUM_PARTITION_TABLE_ENTRIES) break;
2353 
2354  /* Nothing found yet, get the partition array again */
2355  PartitionDescriptor = (PPARTITION_DESCRIPTOR)
2357  for (Entry = 1; Entry <= NUM_PARTITION_TABLE_ENTRIES; Entry++, PartitionDescriptor++)
2358  {
2359  /* Check if this was a container partition (we skipped these) */
2360  if (IsContainerPartition(PartitionDescriptor->PartitionType))
2361  {
2362  /* Update the partition offset */
2363  Offset.QuadPart = VolumeOffset.QuadPart +
2364  GET_STARTING_SECTOR(PartitionDescriptor) *
2365  SectorSize;
2366 
2367  /* If this was the primary partition, update the volume too */
2368  if (IsPrimary) VolumeOffset = Offset;
2369  break;
2370  }
2371  }
2372 
2373  /* Check if we already searched all the partitions */
2375  {
2376  /* Then we failed to find a good MBR */
2378  break;
2379  }
2380 
2381  /* Loop the next partitions, which are not primary anymore */
2382  IsPrimary = FALSE;
2383  } while (i < PartitionNumber);
2384 
2385  /* Everything done, cleanup */
2387  return Status;
2388 }
#define TAG_FILE_SYSTEM
Definition: tag.h:50
#define max(a, b)
Definition: svc.c:63
#define GET_STARTING_SECTOR(p)
Definition: hal.h:252
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _Entry Entry
Definition: kefuncs.h:627
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 TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
#define PARTITION_EZDRIVE
Definition: ntdddisk.h:289
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_BAD_MASTER_BOOT_RECORD
Definition: ntstatus.h:405
#define PARTITION_TABLE_OFFSET
Definition: hal.h:243
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:316
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
unsigned char BOOLEAN
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1803
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
#define BOOT_RECORD_SIGNATURE
Definition: parttest.c:17
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
UCHAR PartitionType
Definition: hal.h:282
struct _PARTITION_DESCRIPTOR * PPARTITION_DESCRIPTOR
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
#define BOOT_SIGNATURE_OFFSET
Definition: hal.h:244
#define PAGE_SIZE
Definition: env_spec_w32.h:49
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
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
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MJ_READ
Definition: rdpdr.c:46
CHAR PartitionType
Definition: part_xbox.c:32
#define NUM_PARTITION_TABLE_ENTRIES
Definition: hal.h:247
unsigned int ULONG
Definition: retypes.h:1
VOID FASTCALL HalExamineMBR(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG MbrTypeIdentifier, OUT PVOID *MbrBuffer)
Definition: disksup.c:2688
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
_In_ ULONG SectorSize
Definition: halfuncs.h:291
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
unsigned short * PUSHORT
Definition: retypes.h:2
base of all file and directory entries
Definition: entries.h:82
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
LONGLONG QuadPart
Definition: typedefs.h:114
#define PAGED_CODE()

◆ 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 2392 of file disksup.c.

2397 {
2398  KEVENT Event;
2400  PIRP Irp;
2402  ULONG BufferSize;
2403  PUSHORT Buffer;
2404  PPTE Entry;
2405  PPARTITION_TABLE PartitionTable;
2406  LARGE_INTEGER Offset, NextOffset, ExtendedOffset, SectorOffset;
2407  LARGE_INTEGER StartOffset, PartitionLength;
2408  ULONG i, j;
2409  CCHAR k;
2410  BOOLEAN IsEzDrive = FALSE, IsSuperFloppy = FALSE, DoRewrite = FALSE, IsMbr;
2411  ULONG ConventionalCylinders;
2412  LONGLONG DiskSize;
2414  PVOID MbrBuffer;
2416  PIO_STACK_LOCATION IoStackLocation;
2419 
2420  PAGED_CODE();
2421 
2422  ExtendedOffset.QuadPart = NextOffset.QuadPart = Offset.QuadPart = 0;
2423 
2424  /* Normalize the buffer size */
2425  BufferSize = max(512, SectorSize);
2426 
2427  /* Get the partial drive geometry */
2428  xHalGetPartialGeometry(DeviceObject, &ConventionalCylinders, &DiskSize);
2429 
2430  /* Check for EZ-Drive */
2432  if (MbrBuffer)
2433  {
2434  /* EZ-Drive found, bias the offset */
2435  IsEzDrive = TRUE;
2436  ExFreePoolWithTag(MbrBuffer, TAG_FILE_SYSTEM);
2437  Offset.QuadPart = 512;
2438  }
2439 
2440  /* Get the number of bits to shift to multiply by the sector size */
2441  for (k = 0; k < 32; k++) if ((SectorSize >> k) == 1) break;
2442 
2443  /* Check if there's only one partition */
2444  if (PartitionBuffer->PartitionCount == 1)
2445  {
2446  /* Check if it has no starting offset or hidden sectors */
2447  if (!(PartitionInfo->StartingOffset.QuadPart) &&
2448  !(PartitionInfo->HiddenSectors))
2449  {
2450  /* Then it's a super floppy */
2451  IsSuperFloppy = TRUE;
2452 
2453  /* Which also means it must be non-bootable FAT-16 */
2454  if ((PartitionInfo->PartitionNumber) ||
2455  (PartitionInfo->PartitionType != PARTITION_FAT_16) ||
2456  (PartitionInfo->BootIndicator))
2457  {
2458  /* It's not, so we fail */
2459  return STATUS_INVALID_PARAMETER;
2460  }
2461 
2462  /* Check if it needs a rewrite, and disable EZ-Drive for sure */
2463  if (PartitionInfo->RewritePartition) DoRewrite = TRUE;
2464  IsEzDrive = FALSE;
2465  }
2466  }
2467 
2468  /* Count the number of partition tables */
2470 
2471  /* Allocate our partition buffer */
2474 
2475  /* Loop the entries */
2477  for (i = 0; i < DiskLayout->TableCount; i++)
2478  {
2479  /* Set if this is the MBR partition */
2480  IsMbr= (BOOLEAN)!i;
2481 
2482  /* Initialize th event */
2484 
2485  /* Build the read IRP */
2487  DeviceObject,
2488  Buffer,
2489  BufferSize,
2490  &Offset,
2491  &Event,
2492  &IoStatusBlock);
2493  if (!Irp)
2494  {
2495  /* Fail */
2497  break;
2498  }
2499 
2500  /* Make sure to disable volume verification */
2501  IoStackLocation = IoGetNextIrpStackLocation(Irp);
2502  IoStackLocation->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
2503 
2504  /* Call the driver */
2506  if (Status == STATUS_PENDING)
2507  {
2508  /* Wait for completion */
2511  }
2512 
2513  /* Check for failure */
2514  if (!NT_SUCCESS(Status)) break;
2515 
2516  /* If we biased for EZ-Drive, unbias now */
2517  if (IsEzDrive && (Offset.QuadPart == 512)) Offset.QuadPart = 0;
2518 
2519  /* Check if this is a normal disk */
2520  if (!IsSuperFloppy)
2521  {
2522  /* Set the boot record signature */
2524 
2525  /* By default, don't require a rewrite */
2526  DoRewrite = FALSE;
2527 
2528  /* Check if we don't have an offset */
2529  if (!Offset.QuadPart)
2530  {
2531  /* Check if the signature doesn't match */
2532  if (((PULONG)Buffer)[PARTITION_TABLE_OFFSET / 2 - 1] !=
2533  PartitionBuffer->Signature)
2534  {
2535  /* Then write the signature and now we need a rewrite */
2536  ((PULONG)Buffer)[PARTITION_TABLE_OFFSET / 2 - 1] =
2537  PartitionBuffer->Signature;
2538  DoRewrite = TRUE;
2539  }
2540  }
2541 
2542  /* Loop the partition table entries */
2543  PartitionTable = &DiskLayout->PartitionTable[i];
2544  for (j = 0; j < NUM_PARTITION_TABLE_ENTRIES; j++)
2545  {
2546  /* Get the current entry and type */
2547  TableEntry = &PartitionTable->PartitionEntry[j];
2548  PartitionType = TableEntry->PartitionType;
2549 
2550  /* Check if the entry needs a rewrite */
2551  if (TableEntry->RewritePartition)
2552  {
2553  /* Then we need one too */
2554  DoRewrite = TRUE;
2555 
2556  /* Save the type and if it's a bootable partition */
2557  Entry[j].PartitionType = TableEntry->PartitionType;
2558  Entry[j].ActiveFlag = TableEntry->BootIndicator ? 0x80 : 0;
2559 
2560  /* Make sure it's used */
2562  {
2563  /* Make sure it's not a container (unless primary) */
2564  if ((IsMbr) || !(IsContainerPartition(PartitionType)))
2565  {
2566  /* Use the partition offset */
2567  StartOffset.QuadPart = Offset.QuadPart;
2568  }
2569  else
2570  {
2571  /* Use the extended logical partition offset */
2572  StartOffset.QuadPart = ExtendedOffset.QuadPart;
2573  }
2574 
2575  /* Set the sector offset */
2576  SectorOffset.QuadPart = TableEntry->
2577  StartingOffset.QuadPart -
2578  StartOffset.QuadPart;
2579 
2580  /* Now calculate the starting sector */
2581  StartOffset.QuadPart = SectorOffset.QuadPart >> k;
2582  Entry[j].StartingSector = StartOffset.LowPart;
2583 
2584  /* As well as the length */
2585  PartitionLength.QuadPart = TableEntry->PartitionLength.
2586  QuadPart >> k;
2587  Entry[j].PartitionLength = PartitionLength.LowPart;
2588 
2589  /* Calculate the CHS values */
2590  HalpCalculateChsValues(&TableEntry->StartingOffset,
2591  &TableEntry->PartitionLength,
2592  k,
2594  NumberOfHeads,
2595  ConventionalCylinders,
2597  &Entry[j]);
2598  }
2599  else
2600  {
2601  /* Otherwise set up an empty entry */
2602  Entry[j].StartingSector = 0;
2603  Entry[j].PartitionLength = 0;
2604  Entry[j].StartingTrack = 0;
2605  Entry[j].EndingTrack = 0;
2606  Entry[j].StartingCylinder = 0;
2607  Entry[j].EndingCylinder = 0;
2608  }
2609  }
2610 
2611  /* Check if this is a container partition */
2613  {
2614  /* Then update the offset to use */
2615  NextOffset = TableEntry->StartingOffset;
2616  }
2617  }
2618  }
2619 
2620  /* Check if we need to write back the buffer */
2621  if (DoRewrite)
2622  {
2623  /* We don't need to do this again */
2624  DoRewrite = FALSE;
2625 
2626  /* Initialize the event */
2628 
2629  /* If we unbiased for EZ-Drive, rebias now */
2630  if (IsEzDrive && !Offset.QuadPart) Offset.QuadPart = 512;
2631 
2632  /* Build the write IRP */
2634  DeviceObject,
2635  Buffer,
2636  BufferSize,
2637  &Offset,
2638  &Event,
2639  &IoStatusBlock);
2640  if (!Irp)
2641  {
2642  /* Fail */
2644  break;
2645  }
2646 
2647  /* Make sure to disable volume verification */
2648  IoStackLocation = IoGetNextIrpStackLocation(Irp);
2649  IoStackLocation->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
2650 
2651  /* Call the driver */
2653  if (Status == STATUS_PENDING)
2654  {
2655  /* Wait for completion */
2657  Executive,
2658  KernelMode,
2659  FALSE,
2660  NULL);
2662  }
2663 
2664  /* Check for failure */
2665  if (!NT_SUCCESS(Status)) break;
2666 
2667  /* If we biased for EZ-Drive, unbias now */
2668  if (IsEzDrive && (Offset.QuadPart == 512)) Offset.QuadPart = 0;
2669  }
2670 
2671  /* Update the partition offset and set the extended offset if needed */
2672  Offset = NextOffset;
2673  if (IsMbr) ExtendedOffset = NextOffset;
2674  }
2675 
2676  /* If we had a buffer, free it, then return status */
2678  return Status;
2679 }
#define TAG_FILE_SYSTEM
Definition: tag.h:50
#define max(a, b)
Definition: svc.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:290
struct _Entry Entry
Definition: kefuncs.h:627
Definition: hal.h:331
struct _PTE * PPTE
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
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
VOID NTAPI 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:1482
#define PARTITION_EZDRIVE
Definition: ntdddisk.h:289
LONG NTSTATUS
Definition: precomp.h:26
#define PARTITION_TABLE_OFFSET
Definition: hal.h:243
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:316
_In_ ULONG _In_ ULONG _In_ ULONG NumberOfHeads
Definition: iofuncs.h:2066
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
struct _DISK_LAYOUT * PDISK_LAYOUT
PARTITION_INFORMATION PartitionEntry[4]
Definition: hal.h:318
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ ULONG _In_ ULONG SectorsPerTrack
Definition: iofuncs.h:2066
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2048
#define SectorOffset(L)
Definition: cdprocs.h:1622
unsigned char BOOLEAN
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1803
Definition: bufpool.h:45
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
Status
Definition: gdiplustypes.h:24
int64_t LONGLONG
Definition: typedefs.h:68
#define BOOT_RECORD_SIGNATURE
Definition: parttest.c:17
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
char CCHAR
Definition: typedefs.h:51
ULONG TableCount
Definition: hal.h:323
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2101
PARTITION_TABLE PartitionTable[1]
Definition: hal.h:325
#define PARTITION_FAT_16
Definition: disk.h:90
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
#define BOOT_SIGNATURE_OFFSET
Definition: hal.h:244
ULONG LowPart
Definition: typedefs.h:106
#define PAGE_SIZE
Definition: env_spec_w32.h:49
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
VOID FASTCALL xHalGetPartialGeometry(IN PDEVICE_OBJECT DeviceObject, IN PULONG ConventionalCylinders, IN PLONGLONG DiskSize)
Definition: disksup.c:1557
BOOLEAN IsSuperFloppy(IN PDISKENTRY DiskEntry)
Definition: partlist.c:680
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
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
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
_Must_inspect_result_ typedef _In_ ULONG TableEntry
Definition: iotypes.h:4282
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define BOOLEAN
Definition: pedump.c:73
CHAR PartitionType
Definition: part_xbox.c:32
ret QuadPart
Definition: rtlfuncs.h:3091
#define NUM_PARTITION_TABLE_ENTRIES
Definition: hal.h:247
unsigned int ULONG
Definition: retypes.h:1
VOID FASTCALL HalExamineMBR(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG MbrTypeIdentifier, OUT PVOID *MbrBuffer)
Definition: disksup.c:2688
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
_In_ ULONG SectorSize
Definition: halfuncs.h:291
int k
Definition: mpi.c:3369
unsigned short * PUSHORT
Definition: retypes.h:2
base of all file and directory entries
Definition: entries.h:82
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
LONGLONG QuadPart
Definition: typedefs.h:114
#define PAGED_CODE()

Variable Documentation

◆ DiskMountString

const WCHAR DiskMountString[] = L"\\DosDevices\\%C:"

Definition at line 19 of file disksup.c.