2020-11-13 00:04:15 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: Partition manager driver
|
|
|
|
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
|
|
|
* PURPOSE: Main header
|
|
|
|
* COPYRIGHT: 2020 Victor Perevertkin (victor.perevertkin@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PARTMGR_H_
|
|
|
|
#define _PARTMGR_H_
|
|
|
|
|
|
|
|
#include <ntifs.h>
|
|
|
|
#include <mountdev.h>
|
|
|
|
#include <ntddvol.h>
|
|
|
|
#include <ntdddisk.h>
|
|
|
|
#include <ndk/psfuncs.h>
|
|
|
|
#include <ndk/section_attribs.h>
|
|
|
|
#include <ioevent.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <debug/driverdbg.h>
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#define TAG_PARTMGR 'MtrP'
|
|
|
|
|
|
|
|
// from disk.sys
|
|
|
|
typedef struct _DISK_GEOMETRY_EX_INTERNAL
|
|
|
|
{
|
|
|
|
DISK_GEOMETRY Geometry;
|
|
|
|
INT64 DiskSize;
|
|
|
|
DISK_PARTITION_INFO Partition;
|
|
|
|
DISK_DETECTION_INFO Detection;
|
|
|
|
} DISK_GEOMETRY_EX_INTERNAL, *PDISK_GEOMETRY_EX_INTERNAL;
|
|
|
|
|
2024-05-22 20:45:52 +00:00
|
|
|
// Unique ID data for basic (disk partition-based) volumes.
|
|
|
|
// It is stored in the MOUNTDEV_UNIQUE_ID::UniqueId member
|
|
|
|
// as an array of bytes.
|
|
|
|
#include <pshpack1.h>
|
|
|
|
typedef union _BASIC_VOLUME_UNIQUE_ID
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
ULONG Signature;
|
|
|
|
ULONGLONG StartingOffset;
|
|
|
|
} Mbr;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
ULONGLONG Signature; // UCHAR[8] // "DMIO:ID:"
|
|
|
|
GUID PartitionGuid;
|
|
|
|
} Gpt;
|
|
|
|
} BASIC_VOLUME_UNIQUE_ID, *PBASIC_VOLUME_UNIQUE_ID;
|
|
|
|
#include <poppack.h>
|
|
|
|
C_ASSERT(RTL_FIELD_SIZE(BASIC_VOLUME_UNIQUE_ID, Mbr) == 0x0C);
|
|
|
|
C_ASSERT(RTL_FIELD_SIZE(BASIC_VOLUME_UNIQUE_ID, Gpt) == 0x18);
|
|
|
|
|
|
|
|
#define DMIO_ID_SIGNATURE (*(ULONGLONG*)"DMIO:ID:")
|
|
|
|
|
2020-11-13 00:04:15 +00:00
|
|
|
typedef struct _FDO_EXTENSION
|
|
|
|
{
|
|
|
|
BOOLEAN IsFDO;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PDEVICE_OBJECT LowerDevice;
|
|
|
|
PDEVICE_OBJECT PhysicalDiskDO;
|
|
|
|
KEVENT SyncEvent;
|
|
|
|
|
|
|
|
BOOLEAN LayoutValid;
|
|
|
|
PDRIVE_LAYOUT_INFORMATION_EX LayoutCache;
|
|
|
|
|
|
|
|
SINGLE_LIST_ENTRY PartitionList;
|
|
|
|
UINT32 EnumeratedPartitionsTotal;
|
2024-05-22 20:45:52 +00:00
|
|
|
BOOLEAN IsSuperFloppy;
|
2020-11-13 00:04:15 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
UINT64 DiskSize;
|
|
|
|
UINT32 DeviceNumber;
|
|
|
|
UINT32 BytesPerSector;
|
|
|
|
PARTITION_STYLE PartitionStyle;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
UINT32 Signature;
|
|
|
|
} Mbr;
|
|
|
|
struct {
|
|
|
|
GUID DiskId;
|
|
|
|
} Gpt;
|
|
|
|
};
|
|
|
|
} DiskData;
|
2024-05-22 20:45:52 +00:00
|
|
|
UNICODE_STRING DiskInterfaceName;
|
2020-11-13 00:04:15 +00:00
|
|
|
} FDO_EXTENSION, *PFDO_EXTENSION;
|
|
|
|
|
|
|
|
typedef struct _PARTITION_EXTENSION
|
|
|
|
{
|
|
|
|
BOOLEAN IsFDO;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PDEVICE_OBJECT LowerDevice;
|
|
|
|
PDEVICE_OBJECT Part0Device;
|
|
|
|
|
|
|
|
UINT64 StartingOffset;
|
|
|
|
UINT64 PartitionLength;
|
|
|
|
SINGLE_LIST_ENTRY ListEntry;
|
|
|
|
|
2024-05-19 18:28:15 +00:00
|
|
|
UINT32 VolumeNumber; // Volume number in the "\Device\HarddiskVolumeN" device name
|
2020-11-13 00:04:15 +00:00
|
|
|
UINT32 DetectedNumber;
|
|
|
|
UINT32 OnDiskNumber; // partition number for issuing Io requests to the kernel
|
|
|
|
BOOLEAN IsEnumerated; // reported via IRP_MN_QUERY_DEVICE_RELATIONS
|
|
|
|
BOOLEAN SymlinkCreated;
|
|
|
|
BOOLEAN Attached; // attached to PartitionList of the FDO
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
GUID PartitionType;
|
|
|
|
GUID PartitionId;
|
|
|
|
UINT64 Attributes;
|
|
|
|
WCHAR Name[36];
|
|
|
|
} Gpt;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
UINT8 PartitionType;
|
|
|
|
BOOLEAN BootIndicator;
|
|
|
|
BOOLEAN RecognizedPartition;
|
|
|
|
UINT32 HiddenSectors;
|
|
|
|
} Mbr;
|
|
|
|
};
|
|
|
|
UNICODE_STRING PartitionInterfaceName;
|
|
|
|
UNICODE_STRING VolumeInterfaceName;
|
|
|
|
UNICODE_STRING DeviceName;
|
|
|
|
} PARTITION_EXTENSION, *PPARTITION_EXTENSION;
|
|
|
|
|
2021-05-11 15:13:14 +00:00
|
|
|
CODE_SEG("PAGE")
|
2020-11-13 00:04:15 +00:00
|
|
|
NTSTATUS
|
|
|
|
PartitionCreateDevice(
|
|
|
|
_In_ PDEVICE_OBJECT FDObject,
|
|
|
|
_In_ PPARTITION_INFORMATION_EX PartitionEntry,
|
|
|
|
_In_ UINT32 OnDiskNumber,
|
|
|
|
_In_ PARTITION_STYLE PartitionStyle,
|
|
|
|
_Out_ PDEVICE_OBJECT *PDO);
|
|
|
|
|
2021-05-11 15:13:14 +00:00
|
|
|
CODE_SEG("PAGE")
|
2020-11-13 00:04:15 +00:00
|
|
|
NTSTATUS
|
|
|
|
PartitionHandleRemove(
|
|
|
|
_In_ PPARTITION_EXTENSION PartExt,
|
|
|
|
_In_ BOOLEAN FinalRemove);
|
|
|
|
|
2021-05-11 15:13:14 +00:00
|
|
|
CODE_SEG("PAGE")
|
2020-11-13 00:04:15 +00:00
|
|
|
NTSTATUS
|
|
|
|
PartitionHandlePnp(
|
|
|
|
_In_ PDEVICE_OBJECT DeviceObject,
|
|
|
|
_In_ PIRP Irp);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
PartitionHandleDeviceControl(
|
|
|
|
_In_ PDEVICE_OBJECT DeviceObject,
|
|
|
|
_In_ PIRP Irp);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
ForwardIrpAndForget(
|
|
|
|
_In_ PDEVICE_OBJECT DeviceObject,
|
|
|
|
_In_ PIRP Irp);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
IssueSyncIoControlRequest(
|
|
|
|
_In_ UINT32 IoControlCode,
|
|
|
|
_In_ PDEVICE_OBJECT DeviceObject,
|
|
|
|
_In_ PVOID InputBuffer,
|
|
|
|
_In_ ULONG InputBufferLength,
|
|
|
|
_In_ PVOID OutputBuffer,
|
|
|
|
_In_ ULONG OutputBufferLength,
|
|
|
|
_In_ BOOLEAN InternalDeviceIoControl);
|
|
|
|
|
2020-11-16 13:27:47 +00:00
|
|
|
FORCEINLINE
|
2020-11-13 00:04:15 +00:00
|
|
|
BOOLEAN
|
|
|
|
VerifyIrpOutBufferSize(
|
|
|
|
_In_ PIRP Irp,
|
|
|
|
_In_ SIZE_T Size)
|
|
|
|
{
|
|
|
|
PIO_STACK_LOCATION ioStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
if (ioStack->Parameters.DeviceIoControl.OutputBufferLength < Size)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Information = Size;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-11-16 13:27:47 +00:00
|
|
|
FORCEINLINE
|
2020-11-13 00:04:15 +00:00
|
|
|
BOOLEAN
|
|
|
|
VerifyIrpInBufferSize(
|
|
|
|
_In_ PIRP Irp,
|
|
|
|
_In_ SIZE_T Size)
|
|
|
|
{
|
|
|
|
PIO_STACK_LOCATION ioStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
if (ioStack->Parameters.DeviceIoControl.InputBufferLength < Size)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Information = Size;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-11-16 13:27:47 +00:00
|
|
|
FORCEINLINE
|
2020-11-13 00:04:15 +00:00
|
|
|
VOID
|
|
|
|
PartMgrAcquireLayoutLock(
|
|
|
|
_In_ PFDO_EXTENSION FDOExtension)
|
|
|
|
{
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
KeWaitForSingleObject(&FDOExtension->SyncEvent, Executive, KernelMode, FALSE, NULL);
|
|
|
|
}
|
|
|
|
|
2020-11-16 13:27:47 +00:00
|
|
|
FORCEINLINE
|
2020-11-13 00:04:15 +00:00
|
|
|
VOID
|
|
|
|
PartMgrReleaseLayoutLock(
|
|
|
|
_In_ PFDO_EXTENSION FDOExtension)
|
|
|
|
{
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
KeSetEvent(&FDOExtension->SyncEvent, IO_NO_INCREMENT, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _PARTMGR_H_
|