problem in using IOCTL_DISK_GET_DRIVE_GEOMETRY_EX in upper disk class filter driver;

I’m trying to get disk signature in my upper disk class filter driver during the AddDevice. But I’m getting some junk status value being returned? Below is the code. Any help. THaNKS.

NTSTATUS MyFltrGetDiskSignature (IN PDEVICE_OBJECT DeviceObject,
OUT PUNICODE_STRING DiskSignature)
{
NTSTATUS status = STATUS_SUCCESS;
IO_STATUS_BLOCK ioStatus;
KEVENT event;
PDEVICE_EXTENSION deviceExtension;
PIRP irp = NULL;
PDISK_GEOMETRY_EX diskGeometry;
ULONG size;
PCCHAR msg = “Disk signature %s\n”;

PAGED_CODE ();

deviceExtension = DeviceObject->DeviceExtension;
/* allocate memory
*/
size = sizeof (DISK_GEOMETRY_EX) +
sizeof (DISK_PARTITION_INFO) +
sizeof (DISK_DETECTION_INFO);

diskGeometry = (PDISK_GEOMETRY_EX)ExAllocatePool (PagedPool, size);

if (NULL == diskGeometry) {
status = STATUS_INSUFFICIENT_RESOURCES;
msg = “Fail to get build DiskGeometry\n”;
goto END;
}
KeInitializeEvent (&event, NotificationEvent, FALSE);
/* Request for the device geometry
*/
irp = IoBuildDeviceIoControlRequest (IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
deviceExtension->TargetDeviceObject,
NULL,
0,
(PVOID)diskGeometry,
size,
FALSE,
&event,
&ioStatus);
if (NULL == irp) {
status = STATUS_INSUFFICIENT_RESOURCES;
msg = “Fail to get build Irp\n”;
goto END;
}
status = IoCallDriver (deviceExtension->TargetDeviceObject, irp);

/*
* status that I get is : status = -1073741661
*
*/

if (STATUS_PENDING == status) {
KeWaitForSingleObject (&event, Executive, KernelMode, FALSE, NULL);
status = ioStatus.Status;
}
if (!NT_SUCCESS (status)) {
msg = “IoBuildDeviceIoControlRequest failed\n”;
goto END;
}

MyFltrAddDevice (DriverObject, PhysicalDeviceObject…)
{
status = IoCreateDevice (DriverObject,
DEVICE_EXTENSION_SIZE,
NULL,
FILE_DEVICE_DISK,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&filterDeviceObject);

if (!NT_SUCCESS (status)) {
MyDebugPrint (Cannot create filterDeviceObject\n");
return (status);
}
filterDeviceObject->Flags |= DO_DIRECT_IO;
deviceExtension = (PDEVICE_EXTENSION)filterDeviceObject->DeviceExtension;
RtlZeroMemory (deviceExtension, DEVICE_EXTENSION_SIZE);

deviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
deviceExtension->TargetDeviceObject = IoAttachDeviceToDeviceStack (filterDeviceObject,
PhysicalDeviceObject);
if (NULL == deviceExtension->TargetDeviceObject) {
ExFreePool (deviceExtension->DiskCounters);
deviceExtension->DiskCounters = NULL;
IoDeleteDevice (filterDeviceObject);
MyDebugPrint (“Unable to attach %X to target %X\n”,
filterDeviceObject,
PhysicalDeviceObject);

return (STATUS_NO_SUCH_DEVICE);
}
/* Save the filter device object in the device extension
*/
deviceExtension->DeviceObject = filterDeviceObject;
deviceExtension->PhysicalDeviceName.Buffer = deviceExtension->PhysicalDeviceNameBuffer;

// at the end of MyFltrAddDevice
MyFltrGetDiskSignature (FilterDeviceObject, &diskSignature);


}

Try hex ;), -1073741661 = 0xc00000a3. I am pretty sure you need to wait until the lower stack has processed the start irp before you can send this ioctl.

//
// MessageId: STATUS_DEVICE_NOT_READY
//
// MessageText:
//
// {Drive Not Ready}
// The drive is not ready for use; its door may be open. Please check drive %hs and make sure that a disk is inserted and that the drive door is closed.
//
#define STATUS_DEVICE_NOT_READY ((NTSTATUS)0xC00000A3L)

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Wednesday, June 18, 2008 1:26 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] problem in using IOCTL_DISK_GET_DRIVE_GEOMETRY_EX in upper disk class filter driver;

I’m trying to get disk signature in my upper disk class filter driver during the AddDevice. But I’m getting some junk status value being returned? Below is the code. Any help. THaNKS.

NTSTATUS MyFltrGetDiskSignature (IN PDEVICE_OBJECT DeviceObject,
OUT PUNICODE_STRING DiskSignature)
{
NTSTATUS status = STATUS_SUCCESS;
IO_STATUS_BLOCK ioStatus;
KEVENT event;
PDEVICE_EXTENSION deviceExtension;
PIRP irp = NULL;
PDISK_GEOMETRY_EX diskGeometry;
ULONG size;
PCCHAR msg = “Disk signature %s\n”;

PAGED_CODE ();

deviceExtension = DeviceObject->DeviceExtension;
/* allocate memory
*/
size = sizeof (DISK_GEOMETRY_EX) +
sizeof (DISK_PARTITION_INFO) +
sizeof (DISK_DETECTION_INFO);

diskGeometry = (PDISK_GEOMETRY_EX)ExAllocatePool (PagedPool, size);

if (NULL == diskGeometry) {
status = STATUS_INSUFFICIENT_RESOURCES;
msg = “Fail to get build DiskGeometry\n”;
goto END;
}
KeInitializeEvent (&event, NotificationEvent, FALSE);
/* Request for the device geometry
*/
irp = IoBuildDeviceIoControlRequest (IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
deviceExtension->TargetDeviceObject,
NULL,
0,
(PVOID)diskGeometry,
size,
FALSE,
&event,
&ioStatus);
if (NULL == irp) {
status = STATUS_INSUFFICIENT_RESOURCES;
msg = “Fail to get build Irp\n”;
goto END;
}
status = IoCallDriver (deviceExtension->TargetDeviceObject, irp);

/*
* status that I get is : status = -1073741661
*
*/

if (STATUS_PENDING == status) {
KeWaitForSingleObject (&event, Executive, KernelMode, FALSE, NULL);
status = ioStatus.Status;
}
if (!NT_SUCCESS (status)) {
msg = “IoBuildDeviceIoControlRequest failed\n”;
goto END;
}

MyFltrAddDevice (DriverObject, PhysicalDeviceObject…)
{
status = IoCreateDevice (DriverObject,
DEVICE_EXTENSION_SIZE,
NULL,
FILE_DEVICE_DISK,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&filterDeviceObject);

if (!NT_SUCCESS (status)) {
MyDebugPrint (Cannot create filterDeviceObject\n");
return (status);
}
filterDeviceObject->Flags |= DO_DIRECT_IO;
deviceExtension = (PDEVICE_EXTENSION)filterDeviceObject->DeviceExtension;
RtlZeroMemory (deviceExtension, DEVICE_EXTENSION_SIZE);

deviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
deviceExtension->TargetDeviceObject = IoAttachDeviceToDeviceStack (filterDeviceObject,
PhysicalDeviceObject);
if (NULL == deviceExtension->TargetDeviceObject) {
ExFreePool (deviceExtension->DiskCounters);
deviceExtension->DiskCounters = NULL;
IoDeleteDevice (filterDeviceObject);
MyDebugPrint (“Unable to attach %X to target %X\n”,
filterDeviceObject,
PhysicalDeviceObject);

return (STATUS_NO_SUCH_DEVICE);
}
/* Save the filter device object in the device extension
*/
deviceExtension->DeviceObject = filterDeviceObject;
deviceExtension->PhysicalDeviceName.Buffer = deviceExtension->PhysicalDeviceNameBuffer;

// at the end of MyFltrAddDevice
MyFltrGetDiskSignature (FilterDeviceObject, &diskSignature);


}


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Wow that was a very quick answer :slight_smile: Is there any way of getting the disk signature during the add device? I want to identify a particular disk when it gets added. Please see the following link for the previous discussion on this topic. Thanks.

http://www.osronline.com/showthread.cfm?link=132958

Is there some overwhelming reason why you cannot perform these
operations on the tail end of start device?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.com
Sent: Wednesday, June 18, 2008 4:50 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] problem in using IOCTL_DISK_GET_DRIVE_GEOMETRY_EX in
upper disk class filter driver;

Wow that was a very quick answer :slight_smile: Is there any way of getting the
disk signature during the add device? I want to identify a particular
disk when it gets added. Please see the following link for the previous
discussion on this topic. Thanks.

http://www.osronline.com/showthread.cfm?link=132958


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I was thinking that if I can identify the interesting disk in the AddDevice then driver does not have to attach to the stack of all other disks.

Because of the access issue it is simpler to always attach but to have a
flag for each instance that switches between active/passive filter mode.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.com
Sent: Wednesday, June 18, 2008 5:15 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] problem in using IOCTL_DISK_GET_DRIVE_GEOMETRY_EX in
upper disk class filter driver;

I was thinking that if I can identify the interesting disk in the
AddDevice then driver does not have to attach to the stack of all other
disks.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Thanks Mark. After you asked me the question I realized that will be the proper way and everything is working fine for me now. Thanks.