From 2d6c6fa38d6dc40503f246b97b67b0472e561e0f Mon Sep 17 00:00:00 2001 From: Victor Perevertkin Date: Sun, 6 Dec 2020 19:47:15 +0300 Subject: [PATCH] [PARTMGR] Register a disk interface for disk PDO CORE-14187 --- drivers/storage/partmgr/partmgr.c | 33 +++++++++++++++++++++++++++++++ drivers/storage/partmgr/partmgr.h | 1 + 2 files changed, 34 insertions(+) diff --git a/drivers/storage/partmgr/partmgr.c b/drivers/storage/partmgr/partmgr.c index 8abfdccedd6..75ca8451137 100644 --- a/drivers/storage/partmgr/partmgr.c +++ b/drivers/storage/partmgr/partmgr.c @@ -846,6 +846,32 @@ FdoHandleStartDevice( } FdoExtension->DiskData.DeviceNumber = deviceNumber.DeviceNumber; + + // register the disk interface + // partmgr.sys from Windows 8.1 also registers a mysterious GUID_DEVINTERFACE_HIDDEN_DISK here + UNICODE_STRING interfaceName; + status = IoRegisterDeviceInterface(FdoExtension->PhysicalDiskDO, + &GUID_DEVINTERFACE_DISK, + NULL, + &interfaceName); + + if(!NT_SUCCESS(status)) + { + ERR("Failed to register GUID_DEVINTERFACE_DISK, status %x\n", status); + return status; + } + + FdoExtension->DiskInterfaceName = interfaceName; + status = IoSetDeviceInterfaceState(&interfaceName, TRUE); + + INFO("Disk interface %wZ\n", &interfaceName); + + if (!NT_SUCCESS(status)) + { + RtlFreeUnicodeString(&interfaceName); + RtlInitUnicodeString(&FdoExtension->DiskInterfaceName, NULL); + } + return status; } @@ -1002,6 +1028,13 @@ FdoHandleRemoveDevice( ASSERT(partExt->DeviceRemoved); } + if (FdoExtension->DiskInterfaceName.Buffer) + { + IoSetDeviceInterfaceState(&FdoExtension->DiskInterfaceName, FALSE); + RtlFreeUnicodeString(&FdoExtension->DiskInterfaceName); + RtlInitUnicodeString(&FdoExtension->DiskInterfaceName, NULL); + } + // Send the IRP down the stack IoSkipCurrentIrpStackLocation(Irp); Irp->IoStatus.Status = STATUS_SUCCESS; diff --git a/drivers/storage/partmgr/partmgr.h b/drivers/storage/partmgr/partmgr.h index 71eccfb8823..28d350c5363 100644 --- a/drivers/storage/partmgr/partmgr.h +++ b/drivers/storage/partmgr/partmgr.h @@ -44,6 +44,7 @@ typedef struct _FDO_EXTENSION SINGLE_LIST_ENTRY PartitionList; UINT32 EnumeratedPartitionsTotal; + UNICODE_STRING DiskInterfaceName; struct { UINT64 DiskSize;