ReactOS  0.4.15-dev-3193-g74513a7
partmgr.h
Go to the documentation of this file.
1 /*
2  * PROJECT: Partition manager driver
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Main header
5  * COPYRIGHT: 2020 Victor Perevertkin (victor.perevertkin@reactos.org)
6  */
7 
8 #ifndef _PARTMGR_H_
9 #define _PARTMGR_H_
10 
11 #include <ntifs.h>
12 #include <mountdev.h>
13 #include <ntddvol.h>
14 #include <ntdddisk.h>
15 #include <ndk/psfuncs.h>
16 #include <ndk/section_attribs.h>
17 #include <ioevent.h>
18 #include <stdio.h>
19 #include <debug/driverdbg.h>
20 
21 #include "debug.h"
22 
23 #define TAG_PARTMGR 'MtrP'
24 
25 // from disk.sys
26 typedef struct _DISK_GEOMETRY_EX_INTERNAL
27 {
30  DISK_PARTITION_INFO Partition;
31  DISK_DETECTION_INFO Detection;
33 
34 typedef struct _FDO_EXTENSION
35 {
41 
43  PDRIVE_LAYOUT_INFORMATION_EX LayoutCache;
44 
48 
49  struct {
54  union {
55  struct {
57  } Mbr;
58  struct {
60  } Gpt;
61  };
62  } DiskData;
64 
65 typedef struct _PARTITION_EXTENSION
66 {
71 
75 
77  UINT32 OnDiskNumber; // partition number for issuing Io requests to the kernel
78  BOOLEAN IsEnumerated; // reported via IRP_MN_QUERY_DEVICE_RELATIONS
80  BOOLEAN Attached; // attached to PartitionList of the FDO
81  union
82  {
83  struct
84  {
88  WCHAR Name[36];
89  } Gpt;
90  struct
91  {
96  } Mbr;
97  };
102 
103 CODE_SEG("PAGE")
104 NTSTATUS
106  _In_ PDEVICE_OBJECT FDObject,
107  _In_ PPARTITION_INFORMATION_EX PartitionEntry,
108  _In_ UINT32 OnDiskNumber,
109  _In_ PARTITION_STYLE PartitionStyle,
110  _Out_ PDEVICE_OBJECT *PDO);
111 
112 CODE_SEG("PAGE")
113 NTSTATUS
115  _In_ PPARTITION_EXTENSION PartExt,
116  _In_ BOOLEAN FinalRemove);
117 
118 CODE_SEG("PAGE")
119 NTSTATUS
122  _In_ PIRP Irp);
123 
124 NTSTATUS
127  _In_ PIRP Irp);
128 
129 NTSTATUS
130 NTAPI
133  _In_ PIRP Irp);
134 
135 NTSTATUS
144 
146 BOOLEAN
148  _In_ PIRP Irp,
149  _In_ SIZE_T Size)
150 {
152  if (ioStack->Parameters.DeviceIoControl.OutputBufferLength < Size)
153  {
154  Irp->IoStatus.Information = Size;
155  return FALSE;
156  }
157  return TRUE;
158 }
159 
161 BOOLEAN
163  _In_ PIRP Irp,
164  _In_ SIZE_T Size)
165 {
167  if (ioStack->Parameters.DeviceIoControl.InputBufferLength < Size)
168  {
169  Irp->IoStatus.Information = Size;
170  return FALSE;
171  }
172  return TRUE;
173 }
174 
176 VOID
178  _In_ PFDO_EXTENSION FDOExtension)
179 {
180  PAGED_CODE();
181 
182  KeWaitForSingleObject(&FDOExtension->SyncEvent, Executive, KernelMode, FALSE, NULL);
183 }
184 
186 VOID
188  _In_ PFDO_EXTENSION FDOExtension)
189 {
190  PAGED_CODE();
191 
192  KeSetEvent(&FDOExtension->SyncEvent, IO_NO_INCREMENT, FALSE);
193 }
194 
195 #endif // _PARTMGR_H_
UNICODE_STRING VolumeInterfaceName
Definition: partmgr.h:99
Definition: ntbasedef.h:628
DISK_GEOMETRY Geometry
Definition: disk.c:3665
#define _Out_
Definition: ms_sal.h:345
#define TRUE
Definition: types.h:120
PDEVICE_OBJECT LowerDevice
Definition: partmgr.h:38
struct _FDO_EXTENSION FDO_EXTENSION
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID _In_ ULONG _In_ BOOLEAN InternalDeviceIoControl
Definition: iofuncs.h:715
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS PartitionHandlePnp(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: partition.c:385
BOOLEAN LayoutValid
Definition: partmgr.h:42
UNICODE_STRING DiskInterfaceName
Definition: partmgr.h:47
BOOLEAN RecognizedPartition
Definition: partmgr.h:94
PDEVICE_OBJECT PhysicalDiskDO
Definition: partmgr.h:39
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:318
PDEVICE_OBJECT Part0Device
Definition: partmgr.h:70
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
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 _PARTITION_EXTENSION::@1267::@1269 Gpt
UINT32 HiddenSectors
Definition: partmgr.h:95
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:318
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
BOOLEAN Attached
Definition: partmgr.h:80
unsigned int UINT32
UNICODE_STRING DeviceName
Definition: partmgr.h:100
struct _FDO_EXTENSION::@1262::@1263::@1265 Mbr
unsigned char BOOLEAN
PDEVICE_OBJECT DeviceObject
Definition: partmgr.h:37
UINT32 DeviceNumber
Definition: partmgr.h:51
#define _In_
Definition: ms_sal.h:308
NTSTATUS NTAPI ForwardIrpAndForget(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: utils.c:5
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:859
struct _PARTITION_EXTENSION::@1267::@1270 Mbr
NTSTATUS IssueSyncIoControlRequest(_In_ UINT32 IoControlCode, _In_ PDEVICE_OBJECT DeviceObject, _In_ PVOID InputBuffer, _In_ ULONG InputBufferLength, _In_ PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _In_ BOOLEAN InternalDeviceIoControl)
Definition: utils.c:19
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
PARTITION_STYLE PartitionStyle
Definition: partmgr.h:53
UINT64 PartitionLength
Definition: partmgr.h:73
FORCEINLINE BOOLEAN VerifyIrpOutBufferSize(_In_ PIRP Irp, _In_ SIZE_T Size)
Definition: partmgr.h:147
GUID DiskId
Definition: partmgr.h:59
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSTATUS PartitionHandleRemove(_In_ PPARTITION_EXTENSION PartExt, _In_ BOOLEAN FinalRemove)
Definition: partition.c:175
NTSTATUS PartitionHandleDeviceControl(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: partition.c:449
NTSTATUS PartitionCreateDevice(_In_ PDEVICE_OBJECT FDObject, _In_ PPARTITION_INFORMATION_EX PartitionEntry, _In_ UINT32 OnDiskNumber, _In_ PARTITION_STYLE PartitionStyle, _Out_ PDEVICE_OBJECT *PDO)
Definition: partition.c:15
struct _DISK_GEOMETRY_EX_INTERNAL * PDISK_GEOMETRY_EX_INTERNAL
UINT32 OnDiskNumber
Definition: partmgr.h:77
struct _FDO_EXTENSION::@1262 DiskData
SINGLE_LIST_ENTRY PartitionList
Definition: partmgr.h:45
struct _FDO_EXTENSION * PFDO_EXTENSION
PDEVICE_OBJECT LowerDevice
Definition: partmgr.h:69
signed long long INT64
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:318
enum _PARTITION_STYLE PARTITION_STYLE
UINT32 DetectedNumber
Definition: partmgr.h:76
UINT64 DiskSize
Definition: partmgr.h:50
struct _DISK_GEOMETRY_EX_INTERNAL DISK_GEOMETRY_EX_INTERNAL
FORCEINLINE BOOLEAN VerifyIrpInBufferSize(_In_ PIRP Irp, _In_ SIZE_T Size)
Definition: partmgr.h:162
FORCEINLINE VOID PartMgrReleaseLayoutLock(_In_ PFDO_EXTENSION FDOExtension)
Definition: partmgr.h:187
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
ULONG_PTR SIZE_T
Definition: typedefs.h:80
UNICODE_STRING PartitionInterfaceName
Definition: partmgr.h:98
KEVENT SyncEvent
Definition: partmgr.h:40
PDEVICE_OBJECT DeviceObject
Definition: partmgr.h:68
#define FORCEINLINE
Definition: wdftypes.h:67
struct _PARTITION_EXTENSION * PPARTITION_EXTENSION
#define NULL
Definition: types.h:112
struct _PARTITION_EXTENSION PARTITION_EXTENSION
UINT32 EnumeratedPartitionsTotal
Definition: partmgr.h:46
PDRIVE_LAYOUT_INFORMATION_EX LayoutCache
Definition: partmgr.h:43
DISK_DETECTION_INFO Detection
Definition: disk.c:3668
struct _FDO_EXTENSION::@1262::@1263::@1266 Gpt
DISK_PARTITION_INFO Partition
Definition: disk.c:3667
BOOLEAN IsEnumerated
Definition: partmgr.h:78
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
SINGLE_LIST_ENTRY ListEntry
Definition: partmgr.h:74
UINT32 BytesPerSector
Definition: partmgr.h:52
BOOLEAN IsFDO
Definition: partmgr.h:36
unsigned long long UINT64
BOOLEAN SymlinkCreated
Definition: partmgr.h:79
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
unsigned char UINT8
FORCEINLINE VOID PartMgrAcquireLayoutLock(_In_ PFDO_EXTENSION FDOExtension)
Definition: partmgr.h:177
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
UINT32 Signature
Definition: partmgr.h:56
UINT64 StartingOffset
Definition: partmgr.h:72
#define PAGED_CODE()
BOOLEAN BootIndicator
Definition: partmgr.h:93