ReactOS  0.4.15-dev-3302-ga37d9a4
partmgr.h File Reference
#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"
Include dependency graph for partmgr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _DISK_GEOMETRY_EX_INTERNAL
 
struct  _FDO_EXTENSION
 
struct  _PARTITION_EXTENSION
 

Macros

#define TAG_PARTMGR   'MtrP'
 

Typedefs

typedef struct _DISK_GEOMETRY_EX_INTERNAL DISK_GEOMETRY_EX_INTERNAL
 
typedef struct _DISK_GEOMETRY_EX_INTERNALPDISK_GEOMETRY_EX_INTERNAL
 
typedef struct _FDO_EXTENSION FDO_EXTENSION
 
typedef struct _FDO_EXTENSIONPFDO_EXTENSION
 
typedef struct _PARTITION_EXTENSION PARTITION_EXTENSION
 
typedef struct _PARTITION_EXTENSIONPPARTITION_EXTENSION
 

Functions

NTSTATUS PartitionCreateDevice (_In_ PDEVICE_OBJECT FDObject, _In_ PPARTITION_INFORMATION_EX PartitionEntry, _In_ UINT32 OnDiskNumber, _In_ PARTITION_STYLE PartitionStyle, _Out_ PDEVICE_OBJECT *PDO)
 
NTSTATUS PartitionHandleRemove (_In_ PPARTITION_EXTENSION PartExt, _In_ BOOLEAN FinalRemove)
 
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)
 
FORCEINLINE BOOLEAN VerifyIrpOutBufferSize (_In_ PIRP Irp, _In_ SIZE_T Size)
 
FORCEINLINE BOOLEAN VerifyIrpInBufferSize (_In_ PIRP Irp, _In_ SIZE_T Size)
 
FORCEINLINE VOID PartMgrAcquireLayoutLock (_In_ PFDO_EXTENSION FDOExtension)
 
FORCEINLINE VOID PartMgrReleaseLayoutLock (_In_ PFDO_EXTENSION FDOExtension)
 

Macro Definition Documentation

◆ TAG_PARTMGR

#define TAG_PARTMGR   'MtrP'

Definition at line 23 of file partmgr.h.

Typedef Documentation

◆ DISK_GEOMETRY_EX_INTERNAL

◆ FDO_EXTENSION

◆ PARTITION_EXTENSION

◆ PDISK_GEOMETRY_EX_INTERNAL

◆ PFDO_EXTENSION

◆ PPARTITION_EXTENSION

Function Documentation

◆ ForwardIrpAndForget()

NTSTATUS NTAPI ForwardIrpAndForget ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)

Definition at line 5 of file utils.c.

8 {
9  // this part of a structure is identical in both FDO and PDO
10  PDEVICE_OBJECT LowerDevice = ((PFDO_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
11 
12  ASSERT(LowerDevice);
13 
15  return IoCallDriver(LowerDevice, Irp);
16 }
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define ASSERT(a)
Definition: mode.c:44
struct _FDO_EXTENSION * PFDO_EXTENSION
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421

◆ IssueSyncIoControlRequest()

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 at line 19 of file utils.c.

27 {
28  PIRP Irp;
30  PKEVENT Event;
32  PAGED_CODE();
33 
34  /* Allocate a non-paged event */
36  if (!Event)
37  {
39  }
40 
41  /* Initialize it */
43 
44  /* Build the IRP */
52  Event,
53  &IoStatusBlock);
54  if (!Irp)
55  {
56  /* Fail, free the event */
59  }
60 
61  /* Call the driver and check if it's pending */
63  if (Status == STATUS_PENDING)
64  {
65  /* Wait on the driver */
68  }
69 
70  /* Free the event and return the Status */
72  return Status;
73 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_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
_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_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:318
_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:467
_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
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:318
#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 TAG_PARTMGR
Definition: partmgr.h:23
#define PAGED_CODE()

Referenced by FdoHandleStartDevice(), FdoIoctlDiskGetDriveGeometryEx(), and PartMgrRefreshDiskData().

◆ PartitionCreateDevice()

NTSTATUS PartitionCreateDevice ( _In_ PDEVICE_OBJECT  FDObject,
_In_ PPARTITION_INFORMATION_EX  PartitionEntry,
_In_ UINT32  OnDiskNumber,
_In_ PARTITION_STYLE  PartitionStyle,
_Out_ PDEVICE_OBJECT PDO 
)

Definition at line 15 of file partition.c.

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 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
LONG NTSTATUS
Definition: precomp.h:26
#define swprintf
Definition: precomp.h:40
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define FALSE
Definition: types.h:117
unsigned int UINT32
UNICODE_STRING DeviceName
Definition: partmgr.h:100
PVOID DeviceExtension
Definition: env_spec_w32.h:418
UINT64 PartitionLength
Definition: partmgr.h:73
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _PARTITION_EXTENSION::@1268::@1270 Gpt
UINT32 OnDiskNumber
Definition: partmgr.h:77
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
static const WCHAR L[]
Definition: oid.c:1250
PDEVICE_OBJECT LowerDevice
Definition: partmgr.h:69
UINT32 DetectedNumber
Definition: partmgr.h:76
#define ERR(fmt,...)
Definition: debug.h:110
PDEVICE_OBJECT DeviceObject
Definition: partmgr.h:68
#define INFO(fmt,...)
Definition: debug.h:13
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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
static SERVICE_STATUS status
Definition: service.c:31
struct _PARTITION_EXTENSION::@1268::@1271 Mbr
UINT64 StartingOffset
Definition: partmgr.h:72
#define PAGED_CODE()
Definition: ps.c:97

Referenced by PartMgrUpdatePartitionDevices().

◆ PartitionHandleDeviceControl()

NTSTATUS PartitionHandleDeviceControl ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)

Definition at line 449 of file partition.c.

452 {
454  PPARTITION_EXTENSION partExt = DeviceObject->DeviceExtension;
455  PFDO_EXTENSION fdoExtension = partExt->LowerDevice->DeviceExtension;
457 
458  ASSERT(!partExt->IsFDO);
459 
460  if (!partExt->IsEnumerated)
461  {
462  Irp->IoStatus.Status = STATUS_DEVICE_DOES_NOT_EXIST;
465  }
466 
467  switch (ioStack->Parameters.DeviceIoControl.IoControlCode)
468  {
469  // disk stuff
471  {
473  {
475  break;
476  }
477 
478  PartMgrAcquireLayoutLock(fdoExtension);
479 
480  // not supported on anything other than MBR
481  if (fdoExtension->DiskData.PartitionStyle != PARTITION_STYLE_MBR)
482  {
484  PartMgrReleaseLayoutLock(fdoExtension);
485  break;
486  }
487 
488  PPARTITION_INFORMATION partInfo = Irp->AssociatedIrp.SystemBuffer;
489 
490  *partInfo = (PARTITION_INFORMATION){
491  .PartitionType = partExt->Mbr.PartitionType,
492  .StartingOffset.QuadPart = partExt->StartingOffset,
493  .PartitionLength.QuadPart = partExt->PartitionLength,
494  .HiddenSectors = partExt->Mbr.HiddenSectors,
495  .PartitionNumber = partExt->DetectedNumber,
496  .BootIndicator = partExt->Mbr.BootIndicator,
497  .RecognizedPartition = partExt->Mbr.RecognizedPartition,
498  .RewritePartition = FALSE,
499  };
500 
501  PartMgrReleaseLayoutLock(fdoExtension);
502 
503  Irp->IoStatus.Information = sizeof(*partInfo);
505  break;
506  }
508  {
510  {
512  break;
513  }
514 
515  PPARTITION_INFORMATION_EX partInfoEx = Irp->AssociatedIrp.SystemBuffer;
516 
517  PartMgrAcquireLayoutLock(fdoExtension);
518 
519  *partInfoEx = (PARTITION_INFORMATION_EX){
521  .PartitionLength.QuadPart = partExt->PartitionLength,
522  .PartitionNumber = partExt->DetectedNumber,
523  .PartitionStyle = fdoExtension->DiskData.PartitionStyle,
524  .RewritePartition = FALSE,
525  };
526 
527  if (fdoExtension->DiskData.PartitionStyle == PARTITION_STYLE_MBR)
528  {
529  partInfoEx->Mbr = (PARTITION_INFORMATION_MBR){
530  .PartitionType = partExt->Mbr.PartitionType,
531  .HiddenSectors = partExt->Mbr.HiddenSectors,
532  .BootIndicator = partExt->Mbr.BootIndicator,
533  .RecognizedPartition = partExt->Mbr.RecognizedPartition,
534  };
535  }
536  else
537  {
538  partInfoEx->Gpt = (PARTITION_INFORMATION_GPT){
539  .PartitionType = partExt->Gpt.PartitionType,
540  .PartitionId = partExt->Gpt.PartitionId,
541  .Attributes = partExt->Gpt.Attributes,
542  };
543 
544  RtlCopyMemory(partInfoEx->Gpt.Name,
545  partExt->Gpt.Name,
546  sizeof(partInfoEx->Gpt.Name));
547  }
548 
549  PartMgrReleaseLayoutLock(fdoExtension);
550 
551  Irp->IoStatus.Information = sizeof(*partInfoEx);
553  break;
554  }
556  {
557  PSET_PARTITION_INFORMATION inputBuffer = Irp->AssociatedIrp.SystemBuffer;
558  if (!VerifyIrpInBufferSize(Irp, sizeof(*inputBuffer)))
559  {
561  break;
562  }
563 
564  PartMgrAcquireLayoutLock(fdoExtension);
565 
566  // these functions use on disk numbers, not detected ones
568  fdoExtension->DiskData.BytesPerSector,
569  partExt->OnDiskNumber,
570  inputBuffer->PartitionType);
571 
572  if (NT_SUCCESS(status))
573  {
574  partExt->Mbr.PartitionType = inputBuffer->PartitionType;
575  }
576 
577  PartMgrReleaseLayoutLock(fdoExtension);
578 
579  Irp->IoStatus.Information = 0;
580  break;
581  }
583  {
584  PSET_PARTITION_INFORMATION_EX inputBuffer = Irp->AssociatedIrp.SystemBuffer;
585  if (!VerifyIrpInBufferSize(Irp, sizeof(*inputBuffer)))
586  {
588  break;
589  }
590 
591  PartMgrAcquireLayoutLock(fdoExtension);
592 
593  // these functions use on disk numbers, not detected ones
595  partExt->OnDiskNumber,
596  inputBuffer);
597 
598  if (NT_SUCCESS(status))
599  {
600  if (fdoExtension->DiskData.PartitionStyle == PARTITION_STYLE_MBR)
601  {
602  partExt->Mbr.PartitionType = inputBuffer->Mbr.PartitionType;
603  }
604  else
605  {
606  partExt->Gpt.PartitionType = inputBuffer->Gpt.PartitionType;
607  partExt->Gpt.PartitionId = inputBuffer->Gpt.PartitionId;
608  partExt->Gpt.Attributes = inputBuffer->Gpt.Attributes;
609 
610  RtlMoveMemory(partExt->Gpt.Name,
611  inputBuffer->Gpt.Name,
612  sizeof(partExt->Gpt.Name));
613  }
614  }
615 
616  PartMgrReleaseLayoutLock(fdoExtension);
617 
618  Irp->IoStatus.Information = 0;
619  break;
620  }
622  {
623  PGET_LENGTH_INFORMATION lengthInfo = Irp->AssociatedIrp.SystemBuffer;
624  if (!VerifyIrpOutBufferSize(Irp, sizeof(*lengthInfo)))
625  {
627  break;
628  }
629 
630  PartMgrAcquireLayoutLock(fdoExtension);
631 
632  lengthInfo->Length.QuadPart = partExt->PartitionLength;
633 
634  PartMgrReleaseLayoutLock(fdoExtension);
635 
637  Irp->IoStatus.Information = sizeof(*lengthInfo);
638  break;
639  }
640  case IOCTL_DISK_VERIFY:
641  {
642  PVERIFY_INFORMATION verifyInfo = Irp->AssociatedIrp.SystemBuffer;
643  if (!VerifyIrpInBufferSize(Irp, sizeof(*verifyInfo)))
644  {
646  break;
647  }
648 
649  // Partition device should just adjust the starting offset
650  verifyInfo->StartingOffset.QuadPart += partExt->StartingOffset;
652  }
654  {
655  fdoExtension->LayoutValid = FALSE;
657 
659  break;
660  }
662  {
664  }
665  // volume stuff (most of that should be in volmgr.sys one it is implemented)
667  {
668  PVOLUME_DISK_EXTENTS volExts = Irp->AssociatedIrp.SystemBuffer;
669 
670  // we fill only one extent entry so sizeof(*volExts) is enough
671  if (!VerifyIrpOutBufferSize(Irp, sizeof(*volExts)))
672  {
674  break;
675  }
676 
677  PartMgrAcquireLayoutLock(fdoExtension);
678 
679  // the only type of volume we support right now is disk partition
680  // so this structure is simple
681 
682  *volExts = (VOLUME_DISK_EXTENTS) {
683  .NumberOfDiskExtents = 1,
684  .Extents = {{
685  .DiskNumber = fdoExtension->DiskData.DeviceNumber,
686  .StartingOffset.QuadPart = partExt->StartingOffset,
687  .ExtentLength.QuadPart = partExt->PartitionLength
688  }}
689  };
690 
691  PartMgrReleaseLayoutLock(fdoExtension);
692 
694  Irp->IoStatus.Information = sizeof(*volExts);
695  break;
696  }
697  case IOCTL_VOLUME_ONLINE:
698  {
700  break;
701  }
703  {
704  PVOLUME_GET_GPT_ATTRIBUTES_INFORMATION gptAttrs = Irp->AssociatedIrp.SystemBuffer;
705  if (!VerifyIrpOutBufferSize(Irp, sizeof(*gptAttrs)))
706  {
708  break;
709  }
710 
711  // not supported on anything other than GPT
712  if (fdoExtension->DiskData.PartitionStyle != PARTITION_STYLE_GPT)
713  {
715  break;
716  }
717 
718  gptAttrs->GptAttributes = partExt->Gpt.Attributes;
719 
721  Irp->IoStatus.Information = sizeof(*gptAttrs);
722  break;
723  }
724  // mountmgr stuff
726  {
727  PMOUNTDEV_NAME name = Irp->AssociatedIrp.SystemBuffer;
728 
729  if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT)))
730  {
732  break;
733  }
734 
735  name->NameLength = partExt->DeviceName.Length;
736 
737  // return NameLength back
738  if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT) + name->NameLength))
739  {
740  Irp->IoStatus.Information = sizeof(USHORT);
742  break;
743  }
744 
745  RtlCopyMemory(name->Name, partExt->DeviceName.Buffer, name->NameLength);
746 
748  Irp->IoStatus.Information = sizeof(USHORT) + name->NameLength;
749  break;
750  }
752  {
753  PMOUNTDEV_UNIQUE_ID uniqueId = Irp->AssociatedIrp.SystemBuffer;
754 
755  if (!partExt->VolumeInterfaceName.Buffer)
756  {
758  break;
759  }
760 
761  if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT)))
762  {
764  break;
765  }
766 
767  uniqueId->UniqueIdLength = partExt->VolumeInterfaceName.Length;
768 
769  // return UniqueIdLength back
770  if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT) + uniqueId->UniqueIdLength))
771  {
772  Irp->IoStatus.Information = sizeof(USHORT);
774  break;
775  }
776 
777  RtlCopyMemory(uniqueId->UniqueId,
778  partExt->VolumeInterfaceName.Buffer,
779  uniqueId->UniqueIdLength);
780 
782  Irp->IoStatus.Information = sizeof(USHORT) + uniqueId->UniqueIdLength;
783  break;
784  }
785  default:
787  }
788 
789  Irp->IoStatus.Status = status;
791  return status;
792 }
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
UNICODE_STRING VolumeInterfaceName
Definition: partmgr.h:99
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define IOCTL_STORAGE_MEDIA_REMOVAL
Definition: ntddstor.h:104
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PDEVICE_OBJECT LowerDevice
Definition: partmgr.h:38
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
LONG NTSTATUS
Definition: precomp.h:26
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_INFORMATION PARTITION_INFORMATION
NTSTATUS NTAPI IoSetPartitionInformationEx(IN PDEVICE_OBJECT DeviceObject, IN ULONG PartitionNumber, IN PSET_PARTITION_INFORMATION_EX PartitionInfo)
Definition: fstubex.c:2341
PARTITION_INFORMATION_MBR Mbr
Definition: imports.h:226
LARGE_INTEGER Length
Definition: imports.h:232
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
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
UNICODE_STRING DeviceName
Definition: partmgr.h:100
#define IOCTL_DISK_VERIFY
Definition: cdrw_usr.h:170
struct _FDO_EXTENSION::@1263 DiskData
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IOCTL_VOLUME_ONLINE
Definition: ntddvol.h:62
#define IoCompleteRequest
Definition: irp.c:1240
#define IOCTL_DISK_SET_PARTITION_INFO
Definition: ntdddisk.h:214
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
#define IOCTL_DISK_UPDATE_PROPERTIES
Definition: ntdddisk.h:242
UINT64 PartitionLength
Definition: partmgr.h:73
FORCEINLINE BOOLEAN VerifyIrpOutBufferSize(_In_ PIRP Irp, _In_ SIZE_T Size)
Definition: partmgr.h:147
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _PARTITION_EXTENSION::@1268::@1270 Gpt
UINT32 OnDiskNumber
Definition: partmgr.h:77
LARGE_INTEGER StartingOffset
Definition: imports.h:221
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
PDEVICE_OBJECT LowerDevice
Definition: partmgr.h:69
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: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 NumberOfDiskExtents
Definition: ntddvol.h:119
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:2342
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
unsigned short USHORT
Definition: pedump.c:61
#define IOCTL_DISK_SET_PARTITION_INFO_EX
Definition: ntdddisk.h:217
Definition: name.c:38
NTSTATUS FASTCALL IoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
Definition: ntoskrnl.c:61
BOOLEAN IsEnumerated
Definition: partmgr.h:78
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
FORCEINLINE VOID PartMgrAcquireLayoutLock(_In_ PFDO_EXTENSION FDOExtension)
Definition: partmgr.h:177
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
struct _PARTITION_EXTENSION::@1268::@1271 Mbr
UCHAR UniqueId[1]
Definition: imports.h:139
UINT64 StartingOffset
Definition: partmgr.h:72
#define IOCTL_DISK_GET_PARTITION_INFO_EX
Definition: ntddk_ex.h:206
LONGLONG QuadPart
Definition: typedefs.h:114
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:656
Definition: ps.c:97

Referenced by PartMgrDeviceControl().

◆ PartitionHandlePnp()

NTSTATUS PartitionHandlePnp ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)

Definition at line 385 of file partition.c.

388 {
389  PPARTITION_EXTENSION partExt = DeviceObject->DeviceExtension;
392 
393  PAGED_CODE();
394 
395  switch (ioStack->MinorFunction)
396  {
397  case IRP_MN_START_DEVICE:
398  {
400  break;
401  }
403  {
405  break;
406  }
411  case IRP_MN_STOP_DEVICE:
412  {
414  break;
415  }
417  {
418  status = PartitionHandleRemove(partExt, FALSE);
419  break;
420  }
422  {
423  status = PartitionHandleRemove(partExt, TRUE);
424  break;
425  }
426  case IRP_MN_QUERY_ID:
427  {
428  status = PartitionHandleQueryId(partExt, Irp);
429  break;
430  }
432  {
434  break;
435  }
436  default:
437  {
438  Irp->IoStatus.Information = 0;
440  }
441  }
442 
443  Irp->IoStatus.Status = status;
445  return status;
446 }
#define IRP_MN_CANCEL_REMOVE_DEVICE
return STATUS_NOT_SUPPORTED
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_ID
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS PartitionHandleDeviceRelations(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:247
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_REMOVE_DEVICE
#define IoCompleteRequest
Definition: irp.c:1240
static NTSTATUS PartitionHandleQueryId(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:286
static NTSTATUS PartitionHandleQueryCapabilities(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:364
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IRP_MN_STOP_DEVICE
#define IRP_MN_START_DEVICE
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
static NTSTATUS PartitionHandleStartDevice(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:91
#define IRP_MN_QUERY_DEVICE_RELATIONS
NTSTATUS PartitionHandleRemove(_In_ PPARTITION_EXTENSION PartExt, _In_ BOOLEAN FinalRemove)
Definition: partition.c:175
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_CANCEL_STOP_DEVICE
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
#define IRP_MN_QUERY_CAPABILITIES
#define PAGED_CODE()
Definition: ps.c:97

Referenced by PartMgrPnp().

◆ PartitionHandleRemove()

NTSTATUS PartitionHandleRemove ( _In_ PPARTITION_EXTENSION  PartExt,
_In_ BOOLEAN  FinalRemove 
)

Definition at line 175 of file partition.c.

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 }
PDEVICE_OBJECT LowerDevice
Definition: partmgr.h:38
LONG NTSTATUS
Definition: precomp.h:26
static const WCHAR PartitionSymLinkFormat[]
Definition: partition.c:10
#define swprintf
Definition: precomp.h:40
#define FALSE
Definition: types.h:117
struct _FDO_EXTENSION::@1263 DiskData
PVOID DeviceExtension
Definition: env_spec_w32.h:418
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define NULL
Definition: types.h:112
#define INFO(fmt,...)
Definition: debug.h:13
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
Definition: ps.c:97

Referenced by FdoHandleSurpriseRemoval(), PartitionHandlePnp(), and PartMgrUpdatePartitionDevices().

◆ PartMgrAcquireLayoutLock()

FORCEINLINE VOID PartMgrAcquireLayoutLock ( _In_ PFDO_EXTENSION  FDOExtension)

Definition at line 177 of file partmgr.h.

179 {
180  PAGED_CODE();
181 
182  KeWaitForSingleObject(&FDOExtension->SyncEvent, Executive, KernelMode, FALSE, NULL);
183 }
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 FALSE
Definition: types.h:117
#define NULL
Definition: types.h:112
#define PAGED_CODE()

Referenced by FdoHandleDeviceRelations(), FdoIoctlDiskCreateDisk(), FdoIoctlDiskDeleteDriveLayout(), FdoIoctlDiskGetDriveGeometryEx(), FdoIoctlDiskGetDriveLayout(), FdoIoctlDiskGetDriveLayoutEx(), FdoIoctlDiskGetPartitionInfo(), FdoIoctlDiskGetPartitionInfoEx(), FdoIoctlDiskSetDriveLayout(), FdoIoctlDiskSetDriveLayoutEx(), FdoIoctlDiskUpdateProperties(), PartitionHandleDeviceControl(), and PartitionHandleQueryId().

◆ PartMgrReleaseLayoutLock()

◆ VerifyIrpInBufferSize()

FORCEINLINE BOOLEAN VerifyIrpInBufferSize ( _In_ PIRP  Irp,
_In_ SIZE_T  Size 
)

Definition at line 162 of file partmgr.h.

165 {
167  if (ioStack->Parameters.DeviceIoControl.InputBufferLength < Size)
168  {
169  Irp->IoStatus.Information = Size;
170  return FALSE;
171  }
172  return TRUE;
173 }
#define TRUE
Definition: types.h:120
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128

Referenced by FdoIoctlDiskCreateDisk(), FdoIoctlDiskSetDriveLayout(), FdoIoctlDiskSetDriveLayoutEx(), PartitionHandleDeviceControl(), and ScsiPortDeviceControl().

◆ VerifyIrpOutBufferSize()

FORCEINLINE BOOLEAN VerifyIrpOutBufferSize ( _In_ PIRP  Irp,
_In_ SIZE_T  Size 
)

Definition at line 147 of file partmgr.h.

150 {
152  if (ioStack->Parameters.DeviceIoControl.OutputBufferLength < Size)
153  {
154  Irp->IoStatus.Information = Size;
155  return FALSE;
156  }
157  return TRUE;
158 }
#define TRUE
Definition: types.h:120
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128

Referenced by FdoIoctlDiskGetDriveLayout(), FdoIoctlDiskGetDriveLayoutEx(), FdoIoctlDiskGetPartitionInfo(), FdoIoctlDiskGetPartitionInfoEx(), PartitionHandleDeviceControl(), and ScsiPortDeviceControl().