Detecting Removable Drives and Media

My application wants to restrict reading and writing to any removable media or removable Drive. I am planning to achieve this scenario by capturing IRP_MJ_CREATE Irp in my mini filter driver. When I will receive IRP_MJ_CREATE Irp, I will call IoGetDeviceProperty for getting DevicePropertyBusTypeGuid property. After getting Bus Property GUID I can compare it with standard Bus GUID.
Call to IoGetDeviceProperty fails… in above approach. Let me know what exactly I am doing wrong.

Source Code:

NTSTATUS
DiskPerfAddDevice(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
)
{
NTSTATUS status;
PDEVICE_OBJECT filterDeviceObject;
PDEVICE_EXTENSION deviceExtension;
PVOID RetGUID[35] = {0};
DWORD retGUIDLen = 35;
ULONG RetValLen = 0;
ULONG Count = 0;

PAGED_CODE();

if( IoGetDeviceProperty( PhysicalDeviceObject, DevicePropertyBusTypeGuid, retGUIDLen, RetGUID, &RetValLen ) == STATUS_SUCCESS )
{
DbgPrint(L"Successfully extracted Property\n");
}
status = IoCreateDevice(DriverObject,
DEVICE_EXTENSION_SIZE,
NULL,
FILE_DEVICE_DISK,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&filterDeviceObject);




So first of all I want to know Is my approach correct ? Or Is there any better approach ?

Sorry above code I ahve given wrong… its code I am trying with disk filter driver… so I should ask this part in NTDEV.

LOL. Good luck. Wait until you figure out that SATA reports as a
removable device. So you won’t know whether you are talking to SATA “in
the box” or SATA “in an enclosure”.

Tony
OSR