ReactOS  0.4.15-dev-494-g1d8c567
part.c File Reference
#include "disk.h"
Include dependency graph for part.c:

Go to the source code of this file.

Macros

#define PtCache   ClassDebugExternal1
 

Functions

NTSTATUS NTAPI DiskReadPartitionTableEx (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN BypassCache, OUT PDRIVE_LAYOUT_INFORMATION_EX *DriveLayout)
 
NTSTATUS NTAPI DiskWritePartitionTableEx (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN PDRIVE_LAYOUT_INFORMATION_EX DriveLayout)
 
NTSTATUS NTAPI DiskSetPartitionInformationEx (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN ULONG PartitionNumber, IN struct _SET_PARTITION_INFORMATION_EX *PartitionInfo)
 
NTSTATUS NTAPI DiskSetPartitionInformation (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
 
BOOLEAN NTAPI DiskInvalidatePartitionTable (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN PartitionLockHeld)
 
NTSTATUS NTAPI DiskVerifyPartitionTable (IN PFUNCTIONAL_DEVICE_EXTENSION Fdo, IN BOOLEAN FixErrors)
 

Variables

ULONG DiskBreakOnPtInval = FALSE
 
ULONG DiskDisableGpt = TRUE
 

Macro Definition Documentation

◆ PtCache

#define PtCache   ClassDebugExternal1

Definition at line 25 of file part.c.

Function Documentation

◆ DiskInvalidatePartitionTable()

BOOLEAN NTAPI DiskInvalidatePartitionTable ( IN PFUNCTIONAL_DEVICE_EXTENSION  Fdo,
IN BOOLEAN  PartitionLockHeld 
)

Definition at line 291 of file part.c.

295 {
296  PDISK_DATA diskData = Fdo->CommonExtension.DriverData;
297  BOOLEAN wasValid;
298 
299  wasValid = (BOOLEAN) (diskData->CachedPartitionTableValid ? TRUE : FALSE);
300  diskData->CachedPartitionTableValid = FALSE;
301 
302  DebugPrint((PtCache, "DiskIPT: Invalidating PT cache for FDO %#p\n",
303  Fdo));
304 
305  if((PartitionLockHeld) && (diskData->CachedPartitionTable != NULL)) {
306  DebugPrint((PtCache, "DiskIPT: Freeing PT cache (%#p) for FDO %#p\n",
307  diskData->CachedPartitionTable, Fdo));
308  ExFreePool(diskData->CachedPartitionTable);
309  diskData->CachedPartitionTable = NULL;
310  }
311 
312  return wasValid;
313 }
#define TRUE
Definition: types.h:120
PDRIVE_LAYOUT_INFORMATION_EX CachedPartitionTable
Definition: disk.h:292
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
#define BOOLEAN
Definition: pedump.c:73
ULONG CachedPartitionTableValid
Definition: disk.h:282
#define PtCache
Definition: part.c:25
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by DiskDeviceControl(), DiskFdoProcessError(), DiskIoctlCreateDisk(), DiskIoctlSetDriveLayoutEx(), DiskRemoveDevice(), DiskStartFdo(), and DiskStopDevice().

◆ DiskReadPartitionTableEx()

NTSTATUS NTAPI DiskReadPartitionTableEx ( IN PFUNCTIONAL_DEVICE_EXTENSION  Fdo,
IN BOOLEAN  BypassCache,
OUT PDRIVE_LAYOUT_INFORMATION_EX DriveLayout 
)

Definition at line 49 of file part.c.

79 {
80  PDISK_DATA diskData = Fdo->CommonExtension.DriverData;
83 
84  layoutEx = NULL;
85 
86  if(BypassCache) {
87  diskData->CachedPartitionTableValid = FALSE;
88  DebugPrint((PtCache, "DiskRPTEx: cache bypassed and invalidated for "
89  "FDO %#p\n", Fdo));
90  }
91 
92  //
93  // If the cached partition table is present then return a copy of it.
94  //
95 
96  if (diskData->CachedPartitionTableValid != FALSE) {
97 
98  ULONG partitionNumber;
100 
101  //
102  // Clear the partition numbers from the list entries
103  //
104 
105  for(partitionNumber = 0;
106  partitionNumber < layout->PartitionCount;
107  partitionNumber++) {
108  layout->PartitionEntry[partitionNumber].PartitionNumber = 0;
109  }
110 
111  *DriveLayout = diskData->CachedPartitionTable;
112 
113  DebugPrint((PtCache, "DiskRPTEx: cached PT returned (%#p) for "
114  "FDO %#p\n",
115  *DriveLayout, Fdo));
116 
117  return STATUS_SUCCESS;
118  }
119 
120  ASSERTMSG("DiskReadPartitionTableEx is not using cached partition table",
122 
123  //
124  // If there's a cached partition table still around then free it.
125  //
126 
127  if(diskData->CachedPartitionTable) {
128  DebugPrint((PtCache, "DiskRPTEx: cached PT (%#p) freed for FDO %#p\n",
129  diskData->CachedPartitionTable, Fdo));
130 
131  ExFreePool(diskData->CachedPartitionTable);
132  diskData->CachedPartitionTable = NULL;
133  }
134 
135  //
136  // By default, X86 disables recognition of GPT disks. Instead we
137  // return the protective MBR partition. Use IoReadPartitionTable
138  // to get this.
139  //
140 
141  status = IoReadPartitionTableEx(Fdo->DeviceObject, &layoutEx);
142 
143  if (DiskDisableGpt) {
145 
146  if (NT_SUCCESS (status) &&
147  layoutEx->PartitionStyle == PARTITION_STYLE_GPT) {
148 
149  //
150  // ISSUE - 2000/29/08 - math: Remove from final product.
151  // Leave this debug print in for a while until everybody
152  // has had a chance to convert their GPT disks to MBR.
153  //
154 
155  DbgPrint ("DISK: Disk %p recognized as a GPT disk on a system without GPT support.\n"
156  " Disk will appear as RAW.\n",
157  Fdo->DeviceObject);
158 
159  ExFreePool (layoutEx);
160  status = IoReadPartitionTable(Fdo->DeviceObject,
161  Fdo->DiskGeometry.BytesPerSector,
162  FALSE,
163  &layout);
164  if (NT_SUCCESS (status)) {
166  ExFreePool (layout);
167  }
168  }
169  }
170 
171  diskData->CachedPartitionTable = layoutEx;
172 
173  //
174  // If the routine fails make sure we don't have a stale partition table
175  // pointer. Otherwise indicate that the table is now valid.
176  //
177 
178  if(!NT_SUCCESS(status)) {
179  diskData->CachedPartitionTable = NULL;
180  } else {
181  diskData->CachedPartitionTableValid = TRUE;
182  }
183 
184  *DriveLayout = diskData->CachedPartitionTable;
185 
186  DebugPrint((PtCache, "DiskRPTEx: returning PT %#p for FDO %#p with status "
187  "%#08lx. PT is %scached\n",
188  *DriveLayout,
189  Fdo,
190  status,
191  (diskData->CachedPartitionTableValid ? "" : "not ")));
192 
193 
194  return status;
195 }
#define TRUE
Definition: types.h:120
PDRIVE_LAYOUT_INFORMATION_EX CachedPartitionTable
Definition: disk.h:292
#define DbgPrint
Definition: loader.c:25
ULONG DiskDisableGpt
Definition: part.c:44
LONG NTSTATUS
Definition: precomp.h:26
ULONG DiskBreakOnPtInval
Definition: part.c:34
NTSTATUS NTAPI IoReadPartitionTableEx(IN PDEVICE_OBJECT DeviceObject, IN struct _DRIVE_LAYOUT_INFORMATION_EX **DriveLayout)
Definition: fstubex.c:2245
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PDRIVE_LAYOUT_INFORMATION_EX NTAPI DiskConvertLayoutToExtended(IN CONST PDRIVE_LAYOUT_INFORMATION Layout)
Definition: enum.c:147
static DWORD layout
Definition: bitmap.c:46
NTSTATUS FASTCALL IoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN BOOLEAN ReturnRecognizedPartitions, OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
Definition: partition.c:495
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
unsigned int ULONG
Definition: retypes.h:1
ULONG CachedPartitionTableValid
Definition: disk.h:282
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PtCache
Definition: part.c:25
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Definition: ps.c:97

Referenced by DiskDeviceControl(), DiskEnumerateDevice(), DiskIoctlGetDriveLayout(), and DiskIoctlGetDriveLayoutEx().

◆ DiskSetPartitionInformation()

NTSTATUS NTAPI DiskSetPartitionInformation ( IN PFUNCTIONAL_DEVICE_EXTENSION  Fdo,
IN ULONG  SectorSize,
IN ULONG  PartitionNumber,
IN ULONG  PartitionType 
)

Definition at line 270 of file part.c.

276 {
277  PDISK_DATA diskData = Fdo->CommonExtension.DriverData;
278 
279  diskData->CachedPartitionTableValid = FALSE;
280  DebugPrint((PtCache, "DiskSPI: Invalidating PT cache for FDO %#p\n",
281  Fdo));
282 
283  return IoSetPartitionInformation(Fdo->DeviceObject,
284  SectorSize,
286  PartitionType);
287 }
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
NTSTATUS FASTCALL IoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
Definition: ntoskrnl.c:60
CHAR PartitionType
Definition: part_xbox.c:32
_In_ ULONG SectorSize
Definition: halfuncs.h:291
ULONG CachedPartitionTableValid
Definition: disk.h:282
#define PtCache
Definition: part.c:25

Referenced by DiskIoctlSetPartitionInfo().

◆ DiskSetPartitionInformationEx()

NTSTATUS NTAPI DiskSetPartitionInformationEx ( IN PFUNCTIONAL_DEVICE_EXTENSION  Fdo,
IN ULONG  PartitionNumber,
IN struct _SET_PARTITION_INFORMATION_EX PartitionInfo 
)

Definition at line 245 of file part.c.

250 {
251  PDISK_DATA diskData = Fdo->CommonExtension.DriverData;
252 
253  diskData->CachedPartitionTableValid = FALSE;
254  DebugPrint((PtCache, "DiskSPIEx: Invalidating PT cache for FDO %#p\n",
255  Fdo));
256 
257  if (DiskDisableGpt) {
258  if (PartitionInfo->PartitionStyle == PARTITION_STYLE_GPT) {
259  return STATUS_NOT_SUPPORTED;
260  }
261  }
262 
263  return IoSetPartitionInformationEx(Fdo->DeviceObject,
265  PartitionInfo);
266 }
ULONG DiskDisableGpt
Definition: part.c:44
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2101
NTSTATUS NTAPI IoSetPartitionInformationEx(IN PDEVICE_OBJECT DeviceObject, IN ULONG PartitionNumber, IN struct _SET_PARTITION_INFORMATION_EX *PartitionInfo)
Definition: fstubex.c:2312
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
ULONG CachedPartitionTableValid
Definition: disk.h:282
#define PtCache
Definition: part.c:25

Referenced by DiskIoctlSetPartitionInfoEx().

◆ DiskVerifyPartitionTable()

NTSTATUS NTAPI DiskVerifyPartitionTable ( IN PFUNCTIONAL_DEVICE_EXTENSION  Fdo,
IN BOOLEAN  FixErrors 
)

Definition at line 317 of file part.c.

321 {
322  PDISK_DATA diskData = Fdo->CommonExtension.DriverData;
323 
324  if(FixErrors) {
325  diskData->CachedPartitionTableValid = FALSE;
326  DebugPrint((PtCache, "DiskWPTEx: Invalidating PT cache for FDO %#p\n",
327  Fdo));
328  }
329 
330  return IoVerifyPartitionTable(Fdo->DeviceObject, FixErrors);
331 }
NTSTATUS NTAPI IoVerifyPartitionTable(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN FixErrors)
Definition: fstubex.c:2377
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
BOOL FixErrors
Definition: chkdsk.c:69
ULONG CachedPartitionTableValid
Definition: disk.h:282
#define PtCache
Definition: part.c:25

Referenced by DiskDeviceControl().

◆ DiskWritePartitionTableEx()

NTSTATUS NTAPI DiskWritePartitionTableEx ( IN PFUNCTIONAL_DEVICE_EXTENSION  Fdo,
IN PDRIVE_LAYOUT_INFORMATION_EX  DriveLayout 
)

Definition at line 199 of file part.c.

221 {
222  PDISK_DATA diskData = Fdo->CommonExtension.DriverData;
223 
224  //
225  // Invalidate the cached partition table. Do not free it as it may be
226  // the very drive layout that was passed in to us.
227  //
228 
229  diskData->CachedPartitionTableValid = FALSE;
230 
231  DebugPrint((PtCache, "DiskWPTEx: Invalidating PT cache for FDO %#p\n",
232  Fdo));
233 
234  if (DiskDisableGpt) {
235  if (DriveLayout->PartitionStyle == PARTITION_STYLE_GPT) {
236  return STATUS_NOT_SUPPORTED;
237  }
238  }
239 
240  return IoWritePartitionTableEx(Fdo->DeviceObject, DriveLayout);
241 }
ULONG DiskDisableGpt
Definition: part.c:44
NTSTATUS NTAPI IoWritePartitionTableEx(IN PDEVICE_OBJECT DeviceObject, IN struct _DRIVE_LAYOUT_INFORMATION_EX *DriveLayout)
Definition: fstubex.c:2429
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
ULONG CachedPartitionTableValid
Definition: disk.h:282
#define PtCache
Definition: part.c:25

Referenced by DiskDeviceControl(), DiskIoctlSetDriveLayout(), and DiskIoctlSetDriveLayoutEx().

Variable Documentation

◆ DiskBreakOnPtInval

ULONG DiskBreakOnPtInval = FALSE

Definition at line 34 of file part.c.

Referenced by DiskReadPartitionTableEx().

◆ DiskDisableGpt