ReactOS  0.4.15-dev-2103-g9dff498
partition.c
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: Partition device code
5  * COPYRIGHT: 2020 Victor Perevertkin (victor.perevertkin@reactos.org)
6  */
7 
8 #include "partmgr.h"
9 
10 static const WCHAR PartitionSymLinkFormat[] = L"\\Device\\Harddisk%u\\Partition%u";
11 
12 
13 CODE_SEG("PAGE")
16  _In_ PDEVICE_OBJECT FDObject,
17  _In_ PPARTITION_INFORMATION_EX PartitionEntry,
18  _In_ UINT32 PdoNumber,
19  _In_ PARTITION_STYLE PartitionStyle,
20  _Out_ PDEVICE_OBJECT *PDO)
21 {
22  PAGED_CODE();
23 
24  static UINT32 HarddiskVolumeNextId = 1; // this is 1-based
25 
26  WCHAR nameBuf[64];
27  UNICODE_STRING deviceName;
28 
29  // create the device object
30 
31  swprintf(nameBuf, L"\\Device\\HarddiskVolume%u", HarddiskVolumeNextId++);
32  RtlCreateUnicodeString(&deviceName, nameBuf);
33 
34  PDEVICE_OBJECT partitionDevice;
35  NTSTATUS status = IoCreateDevice(FDObject->DriverObject,
36  sizeof(PARTITION_EXTENSION),
37  &deviceName,
40  FALSE,
41  &partitionDevice);
42 
43  if (!NT_SUCCESS(status))
44  {
45  ERR("Unable to create device object %wZ\n", &deviceName);
46  return status;
47  }
48 
49  INFO("Created device object %p %wZ\n", partitionDevice, &deviceName);
50 
51  PPARTITION_EXTENSION partExt = partitionDevice->DeviceExtension;
52  RtlZeroMemory(partExt, sizeof(*partExt));
53 
54  partitionDevice->StackSize = FDObject->StackSize;
55  partitionDevice->Flags |= DO_DIRECT_IO;
56 
57  if (PartitionStyle == PARTITION_STYLE_MBR)
58  {
59  partExt->Mbr.PartitionType = PartitionEntry->Mbr.PartitionType;
60  partExt->Mbr.BootIndicator = PartitionEntry->Mbr.BootIndicator;
61  partExt->Mbr.HiddenSectors = PartitionEntry->Mbr.HiddenSectors;
62  }
63  else
64  {
65  partExt->Gpt.PartitionType = PartitionEntry->Gpt.PartitionType;
66  partExt->Gpt.PartitionId = PartitionEntry->Gpt.PartitionType;
67  partExt->Gpt.Attributes = PartitionEntry->Gpt.Attributes;
68 
69  RtlCopyMemory(partExt->Gpt.Name, PartitionEntry->Gpt.Name, sizeof(partExt->Gpt.Name));
70  }
71 
72  partExt->DeviceName = deviceName;
73  partExt->StartingOffset = PartitionEntry->StartingOffset.QuadPart;
74  partExt->PartitionLength = PartitionEntry->PartitionLength.QuadPart;
75  partExt->OnDiskNumber = PartitionEntry->PartitionNumber; // the "physical" partition number
76  partExt->DetectedNumber = PdoNumber; // counts only partitions with PDO created
77 
78  partExt->DeviceObject = partitionDevice;
79  partExt->LowerDevice = FDObject;
80 
81  partitionDevice->Flags &= ~DO_DEVICE_INITIALIZING;
82 
83  *PDO = partitionDevice;
84 
85  return status;
86 }
87 
88 static
89 CODE_SEG("PAGE")
92  _In_ PPARTITION_EXTENSION PartExt,
93  _In_ PIRP Irp)
94 {
95  PAGED_CODE();
96 
97  // first, create a symbolic link for our device
98  WCHAR nameBuf[64];
99  UNICODE_STRING partitionSymlink, interfaceName;
100  PFDO_EXTENSION fdoExtension = PartExt->LowerDevice->DeviceExtension;
101 
102  // \\Device\\Harddisk%u\\Partition%u
104  fdoExtension->DiskData.DeviceNumber, PartExt->DetectedNumber);
105 
106  if (!RtlCreateUnicodeString(&partitionSymlink, nameBuf))
107  {
109  }
110 
111  NTSTATUS status = IoCreateSymbolicLink(&partitionSymlink, &PartExt->DeviceName);
112 
113  if (!NT_SUCCESS(status))
114  {
115  return status;
116  }
117 
118  PartExt->SymlinkCreated = TRUE;
119 
120  TRACE("Symlink created %wZ -> %wZ\n", &PartExt->DeviceName, &partitionSymlink);
121 
122  // our partition device will have two interfaces:
123  // GUID_DEVINTERFACE_PARTITION and GUID_DEVINTERFACE_VOLUME
124  // the former one is used to notify mountmgr about new device
125 
126  status = IoRegisterDeviceInterface(PartExt->DeviceObject,
127  &GUID_DEVINTERFACE_PARTITION,
128  NULL,
129  &interfaceName);
130 
131  if (!NT_SUCCESS(status))
132  {
133  return status;
134  }
135 
136  PartExt->PartitionInterfaceName = interfaceName;
137  status = IoSetDeviceInterfaceState(&interfaceName, TRUE);
138 
139  INFO("Partition interface %wZ\n", &interfaceName);
140 
141  if (!NT_SUCCESS(status))
142  {
143  RtlFreeUnicodeString(&interfaceName);
144  RtlInitUnicodeString(&PartExt->PartitionInterfaceName, NULL);
145  return status;
146  }
147 
148  status = IoRegisterDeviceInterface(PartExt->DeviceObject,
149  &GUID_DEVINTERFACE_VOLUME,
150  NULL,
151  &interfaceName);
152 
153  if (!NT_SUCCESS(status))
154  {
155  return status;
156  }
157 
158  PartExt->VolumeInterfaceName = interfaceName;
159  status = IoSetDeviceInterfaceState(&interfaceName, TRUE);
160 
161  INFO("Volume interface %wZ\n", &interfaceName);
162 
163  if (!NT_SUCCESS(status))
164  {
165  RtlFreeUnicodeString(&interfaceName);
166  RtlInitUnicodeString(&PartExt->VolumeInterfaceName, NULL);
167  return status;
168  }
169 
170  return STATUS_SUCCESS;
171 }
172 
173 CODE_SEG("PAGE")
174 NTSTATUS
176  _In_ PPARTITION_EXTENSION PartExt,
177  _In_ BOOLEAN FinalRemove)
178 {
180 
181  PAGED_CODE();
182 
183  // remove the symbolic link
184  if (PartExt->SymlinkCreated)
185  {
186  WCHAR nameBuf[64];
187  UNICODE_STRING partitionSymlink;
188  PFDO_EXTENSION fdoExtension = PartExt->LowerDevice->DeviceExtension;
189 
191  fdoExtension->DiskData.DeviceNumber, PartExt->DetectedNumber);
192 
193  RtlInitUnicodeString(&partitionSymlink, nameBuf);
194 
195  status = IoDeleteSymbolicLink(&partitionSymlink);
196 
197  if (!NT_SUCCESS(status))
198  {
199  return status;
200  }
201  PartExt->SymlinkCreated = FALSE;
202 
203  INFO("Symlink removed %wZ -> %wZ\n", &PartExt->DeviceName, &partitionSymlink);
204  }
205 
206  // release device interfaces
207  if (PartExt->PartitionInterfaceName.Buffer)
208  {
209  status = IoSetDeviceInterfaceState(&PartExt->PartitionInterfaceName, FALSE);
210  if (!NT_SUCCESS(status))
211  {
212  return status;
213  }
214  RtlFreeUnicodeString(&PartExt->PartitionInterfaceName);
215  RtlInitUnicodeString(&PartExt->PartitionInterfaceName, NULL);
216  }
217 
218  if (PartExt->VolumeInterfaceName.Buffer)
219  {
220  status = IoSetDeviceInterfaceState(&PartExt->VolumeInterfaceName, FALSE);
221  if (!NT_SUCCESS(status))
222  {
223  return status;
224  }
225  RtlFreeUnicodeString(&PartExt->VolumeInterfaceName);
226  RtlInitUnicodeString(&PartExt->VolumeInterfaceName, NULL);
227  }
228 
229  if (FinalRemove)
230  {
231  ASSERT(PartExt->DeviceName.Buffer);
232  if (PartExt->DeviceName.Buffer)
233  {
234  INFO("Removed device %wZ\n", &PartExt->DeviceName);
235  RtlFreeUnicodeString(&PartExt->DeviceName);
236  }
237 
238  IoDeleteDevice(PartExt->DeviceObject);
239  }
240 
241  return STATUS_SUCCESS;
242 }
243 
244 static
245 CODE_SEG("PAGE")
246 NTSTATUS
248  _In_ PPARTITION_EXTENSION PartExt,
249  _In_ PIRP Irp)
250 {
251  PAGED_CODE();
252 
254  DEVICE_RELATION_TYPE type = ioStack->Parameters.QueryDeviceRelations.Type;
255 
256  if (type == TargetDeviceRelation)
257  {
258  // Device relations has one entry built in to it's size.
259  PDEVICE_RELATIONS deviceRelations =
260  ExAllocatePoolZero(PagedPool, sizeof(DEVICE_RELATIONS), TAG_PARTMGR);
261 
262  if (deviceRelations != NULL)
263  {
264  deviceRelations->Count = 1;
265  deviceRelations->Objects[0] = PartExt->DeviceObject;
266  ObReferenceObject(deviceRelations->Objects[0]);
267 
268  Irp->IoStatus.Information = (ULONG_PTR)deviceRelations;
269  return STATUS_SUCCESS;
270  }
271  else
272  {
274  }
275  }
276  else
277  {
278  Irp->IoStatus.Information = 0;
279  return Irp->IoStatus.Status;
280  }
281 }
282 
283 static
284 CODE_SEG("PAGE")
285 NTSTATUS
287  _In_ PPARTITION_EXTENSION PartExt,
288  _In_ PIRP Irp)
289 {
291  BUS_QUERY_ID_TYPE idType = ioStack->Parameters.QueryId.IdType;
292  UNICODE_STRING idString;
294 
295  PAGED_CODE();
296 
297  switch (idType)
298  {
299  case BusQueryDeviceID:
300  status = RtlCreateUnicodeString(&idString, L"STORAGE\\Partition")
302  break;
303  case BusQueryHardwareIDs:
305  {
306  static WCHAR volumeID[] = L"STORAGE\\Volume\0";
307 
308  idString.Buffer = ExAllocatePoolWithTag(PagedPool, sizeof(volumeID), TAG_PARTMGR);
309  RtlCopyMemory(idString.Buffer, volumeID, sizeof(volumeID));
310 
312  break;
313  }
314  case BusQueryInstanceID:
315  {
316  WCHAR string[64];
317  PFDO_EXTENSION fdoExtension = PartExt->LowerDevice->DeviceExtension;
318 
319  PartMgrAcquireLayoutLock(fdoExtension);
320 
321  if (fdoExtension->DiskData.PartitionStyle == PARTITION_STYLE_MBR)
322  {
323  swprintf(string, L"S%08lx_O%I64x_L%I64x",
324  fdoExtension->DiskData.Mbr.Signature,
325  PartExt->StartingOffset,
326  PartExt->PartitionLength);
327  }
328  else
329  {
330  swprintf(string,
331  L"S%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02xS_O%I64x_L%I64x",
332  fdoExtension->DiskData.Gpt.DiskId.Data1,
333  fdoExtension->DiskData.Gpt.DiskId.Data2,
334  fdoExtension->DiskData.Gpt.DiskId.Data3,
335  fdoExtension->DiskData.Gpt.DiskId.Data4[0],
336  fdoExtension->DiskData.Gpt.DiskId.Data4[1],
337  fdoExtension->DiskData.Gpt.DiskId.Data4[2],
338  fdoExtension->DiskData.Gpt.DiskId.Data4[3],
339  fdoExtension->DiskData.Gpt.DiskId.Data4[4],
340  fdoExtension->DiskData.Gpt.DiskId.Data4[5],
341  fdoExtension->DiskData.Gpt.DiskId.Data4[6],
342  fdoExtension->DiskData.Gpt.DiskId.Data4[7],
343  PartExt->StartingOffset,
344  PartExt->PartitionLength);
345  }
346 
347  PartMgrReleaseLayoutLock(fdoExtension);
348 
349  status = RtlCreateUnicodeString(&idString, string)
351  break;
352  }
353  default:
355  break;
356  }
357 
358  Irp->IoStatus.Information = NT_SUCCESS(status) ? (ULONG_PTR) idString.Buffer : 0;
359  return status;
360 }
361 
362 static
363 CODE_SEG("PAGE")
364 NTSTATUS
366  _In_ PPARTITION_EXTENSION PartExt,
367  _In_ PIRP Irp)
368 {
370  PDEVICE_CAPABILITIES devCaps = ioStack->Parameters.DeviceCapabilities.Capabilities;
371 
372  PAGED_CODE();
373  ASSERT(devCaps);
374 
375  devCaps->SilentInstall = TRUE;
376  devCaps->RawDeviceOK = TRUE;
377  devCaps->NoDisplayInUI = TRUE;
378  devCaps->Address = PartExt->OnDiskNumber;
379  devCaps->UniqueID = 1;
380 
381  return STATUS_SUCCESS;
382 }
383 
384 CODE_SEG("PAGE")
385 NTSTATUS
388  _In_ PIRP Irp)
389 {
390  PPARTITION_EXTENSION partExt = DeviceObject->DeviceExtension;
393 
394  PAGED_CODE();
395 
396  switch (ioStack->MinorFunction)
397  {
398  case IRP_MN_START_DEVICE:
399  {
401  break;
402  }
404  {
406  break;
407  }
412  case IRP_MN_STOP_DEVICE:
413  {
415  break;
416  }
418  {
419  status = PartitionHandleRemove(partExt, FALSE);
420  break;
421  }
423  {
424  status = PartitionHandleRemove(partExt, TRUE);
425  break;
426  }
427  case IRP_MN_QUERY_ID:
428  {
429  status = PartitionHandleQueryId(partExt, Irp);
430  break;
431  }
433  {
435  break;
436  }
437  default:
438  {
439  Irp->IoStatus.Information = 0;
441  }
442  }
443 
444  Irp->IoStatus.Status = status;
446  return status;
447 }
448 
449 NTSTATUS
452  _In_ PIRP Irp)
453 {
455  PPARTITION_EXTENSION partExt = DeviceObject->DeviceExtension;
456  PFDO_EXTENSION fdoExtension = partExt->LowerDevice->DeviceExtension;
458 
459  ASSERT(!partExt->IsFDO);
460 
461  if (!partExt->IsEnumerated)
462  {
463  Irp->IoStatus.Status = STATUS_DEVICE_DOES_NOT_EXIST;
466  }
467 
468  switch (ioStack->Parameters.DeviceIoControl.IoControlCode)
469  {
470  // disk stuff
472  {
474  {
476  break;
477  }
478 
479  PartMgrAcquireLayoutLock(fdoExtension);
480 
481  // not supported on anything other than MBR
482  if (fdoExtension->DiskData.PartitionStyle != PARTITION_STYLE_MBR)
483  {
485  PartMgrReleaseLayoutLock(fdoExtension);
486  break;
487  }
488 
489  PPARTITION_INFORMATION partInfo = Irp->AssociatedIrp.SystemBuffer;
490 
491  *partInfo = (PARTITION_INFORMATION){
492  .PartitionType = partExt->Mbr.PartitionType,
493  .StartingOffset.QuadPart = partExt->StartingOffset,
494  .PartitionLength.QuadPart = partExt->PartitionLength,
495  .HiddenSectors = partExt->Mbr.HiddenSectors,
496  .PartitionNumber = partExt->DetectedNumber,
497  .BootIndicator = partExt->Mbr.BootIndicator,
498  .RecognizedPartition = partExt->Mbr.RecognizedPartition,
499  .RewritePartition = FALSE,
500  };
501 
502  PartMgrReleaseLayoutLock(fdoExtension);
503 
504  Irp->IoStatus.Information = sizeof(*partInfo);
506  break;
507  }
509  {
511  {
513  break;
514  }
515 
516  PPARTITION_INFORMATION_EX partInfoEx = Irp->AssociatedIrp.SystemBuffer;
517 
518  PartMgrAcquireLayoutLock(fdoExtension);
519 
520  *partInfoEx = (PARTITION_INFORMATION_EX){
522  .PartitionLength.QuadPart = partExt->PartitionLength,
523  .PartitionNumber = partExt->DetectedNumber,
524  .PartitionStyle = fdoExtension->DiskData.PartitionStyle,
525  .RewritePartition = FALSE,
526  };
527 
528  if (fdoExtension->DiskData.PartitionStyle == PARTITION_STYLE_MBR)
529  {
530  partInfoEx->Mbr = (PARTITION_INFORMATION_MBR){
531  .PartitionType = partExt->Mbr.PartitionType,
532  .HiddenSectors = partExt->Mbr.HiddenSectors,
533  .BootIndicator = partExt->Mbr.BootIndicator,
534  .RecognizedPartition = partExt->Mbr.RecognizedPartition,
535  };
536  }
537  else
538  {
539  partInfoEx->Gpt = (PARTITION_INFORMATION_GPT){
540  .PartitionType = partExt->Gpt.PartitionType,
541  .PartitionId = partExt->Gpt.PartitionId,
542  .Attributes = partExt->Gpt.Attributes,
543  };
544 
545  RtlCopyMemory(partInfoEx->Gpt.Name,
546  partExt->Gpt.Name,
547  sizeof(partInfoEx->Gpt.Name));
548  }
549 
550  PartMgrReleaseLayoutLock(fdoExtension);
551 
552  Irp->IoStatus.Information = sizeof(*partInfoEx);
554  break;
555  }
557  {
558  PSET_PARTITION_INFORMATION inputBuffer = Irp->AssociatedIrp.SystemBuffer;
559  if (!VerifyIrpInBufferSize(Irp, sizeof(*inputBuffer)))
560  {
562  break;
563  }
564 
565  PartMgrAcquireLayoutLock(fdoExtension);
566 
567  // these functions use on disk numbers, not detected ones
569  fdoExtension->DiskData.BytesPerSector,
570  partExt->OnDiskNumber,
571  inputBuffer->PartitionType);
572 
573  if (NT_SUCCESS(status))
574  {
575  partExt->Mbr.PartitionType = inputBuffer->PartitionType;
576  }
577 
578  PartMgrReleaseLayoutLock(fdoExtension);
579 
580  Irp->IoStatus.Information = 0;
581  break;
582  }
584  {
585  PSET_PARTITION_INFORMATION_EX inputBuffer = Irp->AssociatedIrp.SystemBuffer;
586  if (!VerifyIrpInBufferSize(Irp, sizeof(*inputBuffer)))
587  {
589  break;
590  }
591 
592  PartMgrAcquireLayoutLock(fdoExtension);
593 
594  // these functions use on disk numbers, not detected ones
596  partExt->OnDiskNumber,
597  inputBuffer);
598 
599  if (NT_SUCCESS(status))
600  {
601  if (fdoExtension->DiskData.PartitionStyle == PARTITION_STYLE_MBR)
602  {
603  partExt->Mbr.PartitionType = inputBuffer->Mbr.PartitionType;
604  }
605  else
606  {
607  partExt->Gpt.PartitionType = inputBuffer->Gpt.PartitionType;
608  partExt->Gpt.PartitionId = inputBuffer->Gpt.PartitionId;
609  partExt->Gpt.Attributes = inputBuffer->Gpt.Attributes;
610 
611  RtlMoveMemory(partExt->Gpt.Name,
612  inputBuffer->Gpt.Name,
613  sizeof(partExt->Gpt.Name));
614  }
615  }
616 
617  PartMgrReleaseLayoutLock(fdoExtension);
618 
619  Irp->IoStatus.Information = 0;
620  break;
621  }
623  {
624  PGET_LENGTH_INFORMATION lengthInfo = Irp->AssociatedIrp.SystemBuffer;
625  if (!VerifyIrpOutBufferSize(Irp, sizeof(*lengthInfo)))
626  {
628  break;
629  }
630 
631  PartMgrAcquireLayoutLock(fdoExtension);
632 
633  lengthInfo->Length.QuadPart = partExt->PartitionLength;
634 
635  PartMgrReleaseLayoutLock(fdoExtension);
636 
638  Irp->IoStatus.Information = sizeof(*lengthInfo);
639  break;
640  }
641  case IOCTL_DISK_VERIFY:
642  {
643  PVERIFY_INFORMATION verifyInfo = Irp->AssociatedIrp.SystemBuffer;
644  if (!VerifyIrpInBufferSize(Irp, sizeof(*verifyInfo)))
645  {
647  break;
648  }
649 
650  // Partition device should just adjust the starting offset
651  verifyInfo->StartingOffset.QuadPart += partExt->StartingOffset;
653  }
655  {
656  fdoExtension->LayoutValid = FALSE;
658 
660  break;
661  }
663  {
665  }
666  // volume stuff (most of that should be in volmgr.sys one it is implemented)
668  {
669  PVOLUME_DISK_EXTENTS volExts = Irp->AssociatedIrp.SystemBuffer;
670 
671  // we fill only one extent entry so sizeof(*volExts) is enough
672  if (!VerifyIrpOutBufferSize(Irp, sizeof(*volExts)))
673  {
675  break;
676  }
677 
678  PartMgrAcquireLayoutLock(fdoExtension);
679 
680  // the only type of volume we support right now is disk partition
681  // so this structure is simple
682 
683  *volExts = (VOLUME_DISK_EXTENTS) {
684  .NumberOfDiskExtents = 1,
685  .Extents = {{
686  .DiskNumber = fdoExtension->DiskData.DeviceNumber,
687  .StartingOffset.QuadPart = partExt->StartingOffset,
688  .ExtentLength.QuadPart = partExt->PartitionLength
689  }}
690  };
691 
692  PartMgrReleaseLayoutLock(fdoExtension);
693 
695  Irp->IoStatus.Information = sizeof(*volExts);
696  break;
697  }
698  case IOCTL_VOLUME_ONLINE:
699  {
701  break;
702  }
704  {
705  PVOLUME_GET_GPT_ATTRIBUTES_INFORMATION gptAttrs = Irp->AssociatedIrp.SystemBuffer;
706  if (!VerifyIrpOutBufferSize(Irp, sizeof(*gptAttrs)))
707  {
709  break;
710  }
711 
712  // not supported on anything other than GPT
713  if (fdoExtension->DiskData.PartitionStyle != PARTITION_STYLE_GPT)
714  {
716  break;
717  }
718 
719  gptAttrs->GptAttributes = partExt->Gpt.Attributes;
720 
722  Irp->IoStatus.Information = sizeof(*gptAttrs);
723  break;
724  }
725  // mountmgr stuff
727  {
728  PMOUNTDEV_NAME name = Irp->AssociatedIrp.SystemBuffer;
729 
730  if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT)))
731  {
733  break;
734  }
735 
736  name->NameLength = partExt->DeviceName.Length;
737 
738  // return NameLength back
739  if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT) + name->NameLength))
740  {
741  Irp->IoStatus.Information = sizeof(USHORT);
743  break;
744  }
745 
746  RtlCopyMemory(name->Name, partExt->DeviceName.Buffer, name->NameLength);
747 
749  Irp->IoStatus.Information = sizeof(USHORT) + name->NameLength;
750  break;
751  }
753  {
754  PMOUNTDEV_UNIQUE_ID uniqueId = Irp->AssociatedIrp.SystemBuffer;
755 
756  if (!partExt->VolumeInterfaceName.Buffer)
757  {
759  break;
760  }
761 
762  if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT)))
763  {
765  break;
766  }
767 
768  uniqueId->UniqueIdLength = partExt->VolumeInterfaceName.Length;
769 
770  // return UniqueIdLength back
771  if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT) + uniqueId->UniqueIdLength))
772  {
773  Irp->IoStatus.Information = sizeof(USHORT);
775  break;
776  }
777 
778  RtlCopyMemory(uniqueId->UniqueId,
779  partExt->VolumeInterfaceName.Buffer,
780  uniqueId->UniqueIdLength);
781 
783  Irp->IoStatus.Information = sizeof(USHORT) + uniqueId->UniqueIdLength;
784  break;
785  }
786  default:
788  }
789 
790  Irp->IoStatus.Status = status;
792  return status;
793 }
struct _PARTITION_EXTENSION::@1292::@1294 Gpt
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
return STATUS_NOT_SUPPORTED
UNICODE_STRING VolumeInterfaceName
Definition: partmgr.h:99
enum _BUS_QUERY_ID_TYPE BUS_QUERY_ID_TYPE
#define IRP_MN_REMOVE_DEVICE
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_ID
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define IOCTL_STORAGE_MEDIA_REMOVAL
Definition: ntddstor.h:104
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2160
PDEVICE_OBJECT LowerDevice
Definition: partmgr.h:38
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
LONG NTSTATUS
Definition: precomp.h:26
static const WCHAR PartitionSymLinkFormat[]
Definition: partition.c:10
struct _VOLUME_DISK_EXTENTS VOLUME_DISK_EXTENTS
USHORT UniqueIdLength
Definition: imports.h:138
BOOLEAN LayoutValid
Definition: partmgr.h:42
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
PDEVICE_OBJECT PhysicalDiskDO
Definition: partmgr.h:39
struct _PARTITION_EXTENSION::@1292::@1295 Mbr
#define swprintf
Definition: precomp.h:40
NTSTATUS PartitionHandlePnp(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: partition.c:386
struct _PARTITION_INFORMATION PARTITION_INFORMATION
NTSTATUS NTAPI IoSetPartitionInformationEx(IN PDEVICE_OBJECT DeviceObject, IN ULONG PartitionNumber, IN PSET_PARTITION_INFORMATION_EX PartitionInfo)
Definition: fstubex.c:2339
PARTITION_INFORMATION_MBR Mbr
Definition: imports.h:226
LARGE_INTEGER Length
Definition: imports.h:232
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
static NTSTATUS PartitionHandleDeviceRelations(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:247
NTSTATUS PartitionHandleDeviceControl(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: partition.c:450
PARTITION_INFORMATION_GPT Gpt
Definition: imports.h:227
struct _PARTITION_INFORMATION_GPT PARTITION_INFORMATION_GPT
#define IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
Definition: imports.h:93
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IOCTL_MOUNTDEV_QUERY_UNIQUE_ID
Definition: imports.h:80
struct _PARTITION_INFORMATION_EX PARTITION_INFORMATION_EX
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
unsigned int UINT32
#define IRP_MN_QUERY_REMOVE_DEVICE
UNICODE_STRING DeviceName
Definition: partmgr.h:100
#define IOCTL_DISK_VERIFY
Definition: cdrw_usr.h:170
struct _FDO_EXTENSION::@1287 DiskData
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
#define IOCTL_VOLUME_ONLINE
Definition: ntddvol.h:62
#define _Out_
Definition: no_sal2.h:160
#define IoCompleteRequest
Definition: irp.c:1240
static NTSTATUS PartitionHandleQueryId(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:286
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define IOCTL_DISK_SET_PARTITION_INFO
Definition: ntdddisk.h:214
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
static NTSTATUS PartitionHandleQueryCapabilities(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:365
enum _DEVICE_RELATION_TYPE DEVICE_RELATION_TYPE
#define IRP_MN_QUERY_STOP_DEVICE
#define IOCTL_DISK_UPDATE_PROPERTIES
Definition: ntdddisk.h:242
UINT64 PartitionLength
Definition: partmgr.h:73
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
FORCEINLINE BOOLEAN VerifyIrpOutBufferSize(_In_ PIRP Irp, _In_ SIZE_T Size)
Definition: partmgr.h:144
#define TRACE(s)
Definition: solgame.cpp:4
#define IRP_MN_STOP_DEVICE
#define ASSERT(a)
Definition: mode.c:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS PartitionCreateDevice(_In_ PDEVICE_OBJECT FDObject, _In_ PPARTITION_INFORMATION_EX PartitionEntry, _In_ UINT32 PdoNumber, _In_ PARTITION_STYLE PartitionStyle, _Out_ PDEVICE_OBJECT *PDO)
Definition: partition.c:15
#define IRP_MN_START_DEVICE
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
CODE_SEG("INIT")
Definition: fsrtlpc.c:19
UINT32 OnDiskNumber
Definition: partmgr.h:77
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
LARGE_INTEGER StartingOffset
Definition: imports.h:221
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
static const WCHAR L[]
Definition: oid.c:1250
PDEVICE_OBJECT LowerDevice
Definition: partmgr.h:69
enum _PARTITION_STYLE PARTITION_STYLE
UINT32 DetectedNumber
Definition: partmgr.h:76
#define IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
Definition: ntddvol.h:41
FORCEINLINE BOOLEAN VerifyIrpInBufferSize(_In_ PIRP Irp, _In_ SIZE_T Size)
Definition: partmgr.h:159
* PDEVICE_CAPABILITIES
Definition: iotypes.h:965
FORCEINLINE VOID PartMgrReleaseLayoutLock(_In_ PFDO_EXTENSION FDOExtension)
Definition: partmgr.h:184
#define ERR(fmt,...)
Definition: debug.h:110
#define _In_
Definition: no_sal2.h:158
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
ULONG NumberOfDiskExtents
Definition: ntddvol.h:119
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
static NTSTATUS PartitionHandleStartDevice(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:91
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:2343
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
unsigned short USHORT
Definition: pedump.c:61
PDEVICE_OBJECT DeviceObject
Definition: partmgr.h:68
#define IOCTL_DISK_SET_PARTITION_INFO_EX
Definition: ntdddisk.h:217
#define NULL
Definition: types.h:112
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define INFO(fmt,...)
Definition: debug.h:13
NTSTATUS PartitionHandleRemove(_In_ PPARTITION_EXTENSION PartExt, _In_ BOOLEAN FinalRemove)
Definition: partition.c:175
Definition: name.c:38
NTSTATUS FASTCALL IoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
Definition: ntoskrnl.c:60
#define ObReferenceObject
Definition: obfuncs.h:204
BOOLEAN IsEnumerated
Definition: partmgr.h:78
#define IO_NO_INCREMENT
Definition: iotypes.h:598
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define IRP_MN_CANCEL_STOP_DEVICE
#define STATUS_SUCCESS
Definition: shellext.h:65
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3124
FORCEINLINE VOID PartMgrAcquireLayoutLock(_In_ PFDO_EXTENSION FDOExtension)
Definition: partmgr.h:174
static SERVICE_STATUS status
Definition: service.c:31
#define IOCTL_VOLUME_GET_GPT_ATTRIBUTES
Definition: ntddvol.h:56
struct _PARTITION_INFORMATION_MBR PARTITION_INFORMATION_MBR
UCHAR UniqueId[1]
Definition: imports.h:139
UINT64 StartingOffset
Definition: partmgr.h:72
#define TAG_PARTMGR
Definition: partmgr.h:23
#define IOCTL_DISK_GET_PARTITION_INFO_EX
Definition: ntddk_ex.h:206
LONGLONG QuadPart
Definition: typedefs.h:114
#define IRP_MN_QUERY_CAPABILITIES
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:656
#define PAGED_CODE()
Definition: ps.c:97