Hi,
Thanks for your reply.
I have tried it.
I not sure whether I got the Physical DeviceObject successfully because the
IoGetDeviceProperty failed for DevicePropertyBusTypeGuid!!!
However it was successful for DevicePropertyDeviceDescription and
DevicePropertyEnumeratorName
First one return me Generic Volume
2nd one Storage
So I guess I did it wronly?
I issue the IRP and call IoGetDeviceObject in MountCompletion routine in
sfilter driver
Hope you can help
thank you very much.
Below is a cut of my code:
BOOLEAN
sfQueryRelations(
PDEVICE_OBJECT pDeviceObject,
PFILE_OBJECT pFileObject,
PVOID *pPhysicalDeviceObject
)
{
PIRP pIrp;
KEVENT event;
IO_STATUS_BLOCK IoStatusBlock;
PIO_STACK_LOCATION pIoStackLocation;
PDEVICE_RELATIONS pDevice_Relations;
PDEVICE_OBJECT pDevObj;
// Initialize the event
KeInitializeEvent (&event, SynchronizationEvent, FALSE);
// Allocate an irp for this request. This could also come from a
// private pool, for instance.
pIrp = IoAllocateIrp (pDeviceObject->StackSize, FALSE);
if(!pIrp)
{
// Failure!
KdPrint((“[sfQueryRelations] IoAllocateIrp Failed…\n”));
return FALSE;
}
// Build the IRP’s main body
pIrp->UserEvent = &event;
pIrp->UserIosb = &IoStatusBlock;
pIrp->Tail.Overlay.Thread = PsGetCurrentThread();
pIrp->RequestorMode = KernelMode;
pIrp->Flags = 0;
// Set up the I/O stack location.
pIoStackLocation = IoGetNextIrpStackLocation (pIrp);
pIoStackLocation->MajorFunction = IRP_MJ_PNP;
pIoStackLocation->MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS;
pIoStackLocation->DeviceObject = pDeviceObject;
pIoStackLocation->FileObject = pFileObject;
pIoStackLocation->Parameters.QueryDeviceRelations.Type =
TargetDeviceRelation;
IoStatusBlock.Status = STATUS_NOT_SUPPORTED;
// Set the completion routine.
IoSetCompletionRoutine (pIrp, sfQueryRelationsComplete, 0, TRUE, TRUE,
TRUE);
// Send it to the FSD
(void) IoCallDriver (pDeviceObject, pIrp);
// Wait for the I/O
KeWaitForSingleObject (&event, Executive, KernelMode, TRUE, 0);
pDevice_Relations = (PDEVICE_RELATIONS )IoStatusBlock.Information;
KdPrint ((“count %d\n”, pDevice_Relations->Count));
pDevObj = (PDEVICE_OBJECT)pDevice_Relations->Objects[0];
KdPrint ((“pDevjObj devtype: %x flags %x\n”, pDevObj->DeviceType,
pDevObj->Flags));
(PDEVICE_OBJECT) *pPhysicalDeviceObject =
(PDEVICE_OBJECT)pDevice_Relations->Objects[0];
// Done! Note that since our completion routine frees the IRP we cannot
// touch the IRP now.
return NT_SUCCESS (IoStatusBlock.Status);
}
NTSTATUS
sfQueryRelationsComplete(
PDEVICE_OBJECT pDeviceObject,
PIRP pIrp,
PVOID pContext)
{
// Copy the status information back into the “user” IOSB.
*pIrp->UserIosb = pIrp->IoStatus;
if( !NT_SUCCESS(pIrp->IoStatus.Status) )
KdPrint((“ERROR ON IRP!!!: %x\n”, pIrp->IoStatus.Status ));
// Set the user event - wakes up the mainline code doing this.
KeSetEvent(pIrp->UserEvent, 0, FALSE);
// Free the IRP now that we are done with it.
IoFreeIrp(pIrp);
// We return STATUS_MORE_PROCESSING_REQUIRED because this “magic” return
value
// tells the I/O Manager that additional processing will be done by this
driver
// to the IRP - in fact, it might (as it is in this case) already BE
done - and
// the IRP cannot be completed.
return STATUS_MORE_PROCESSING_REQUIRED;
}
In sfMountCompletion routine
if (NT_SUCCESS (sfQueryRelations (RealDeviceObject, pIrpSp->FileObject,
&PhyDevObj)))
{
KdPrint ((“Success! DevType %x Flags %x\n”, PhyDevObj->DeviceType,
PhyDevObj->Flags));
}
regprop = DevicePropertyBusTypeGuid;
ntstatus = IoGetDeviceProperty (PhyDevObj, regprop, sizeof(guid), &guid,
&ulSize);
if (NT_SUCCESS (ntstatus))
{
KdPrint ((“Guid : data 4: %x data 1: %x\n”, guid.Data4, guid.Data1));
}
else
{
KdPrint ((“IoGetDeviceProperty failed\n”));
if (ntstatus == STATUS_BUFFER_TOO_SMALL)
KdPrint ((“STATUS_BUFFER_TOO_SMALL\n”));
else if (ntstatus == STATUS_INVALID_PARAMETER_2)
KdPrint ((“STATUS_INVALID_PARAMETER_2\n”));
else if (ntstatus == STATUS_INVALID_DEVICE_REQUEST)
KdPrint ((“STATUS_INVALID_DEVICE_REQUEST\n”));
}
From: “Maxim S. Shatskih”
>Reply-To: “Windows System Software Devs Interest List”
>
>To: “Windows System Software Devs Interest List”
>Subject: [ntdev] Re: disk type (Unsigned Mail)
>Date: Thu, 9 Oct 2003 06:41:59 +0400
>
> > What deviceobject should i use to query?
> > vpb->realdevice?
>
>Send MN_QUERY_RELATIONS/TargetDeviceRelation to Vpb->RealDevice and then
>IoGetDeviceProperty to this returned PDO.
>
> > and does iogetdeviceproperty works in win 2k?
>
>Surely.
>
>Maxim Shatskih, Windows DDK MVP
>StorageCraft Corporation
>xxxxx@storagecraft.com
>http://www.storagecraft.com
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
_________________________________________________________________
Find love on MSN Personals http://personals.msn.com.sg/