How to judge a hard disk is a USB hard disk?

I want to known whether a disk is a USB hard disk when mounting volume in my driver.
Thank you !

Query StorageDeviceProperty and check STORAGE_DEVICE_DESCRIPTOR->BusType or
build a PnP tree with Bus, Removal and Ejection relations.


Slava Imameyev, xxxxx@hotmail.com

wrote in message news:xxxxx@ntfsd…
>I want to known whether a disk is a USB hard disk when mounting volume in
>my driver.
> Thank you !
>

DDK says:
Only Plug and Play drivers can issue IOCTL_STORAGE_QUERY_PROPERTY requests. Legacy drivers should use IOCTL_SCSI_GET_INQUIRY_DATA and IOCTL_SCSI_GET_CAPABILITIES to get inquiry and capabilities data.

Can I use IOCTL_STORAGE_QUERY_PROPERTY in sfilter? Sfilter is a legacy drivers.

> Can I use IOCTL_STORAGE_QUERY_PROPERTY in sfilter?

Yes, you can. This is a device IOCTL and if the device( driver ) doesn’t
want to process this request it will return an error.


Slava Imameyev, xxxxx@hotmail.com

wrote in message news:xxxxx@ntfsd…
> DDK says:
> Only Plug and Play drivers can issue IOCTL_STORAGE_QUERY_PROPERTY
> requests. Legacy drivers should use IOCTL_SCSI_GET_INQUIRY_DATA and
> IOCTL_SCSI_GET_CAPABILITIES to get inquiry and capabilities data.
>
> Can I use IOCTL_STORAGE_QUERY_PROPERTY in sfilter? Sfilter is a legacy
> drivers.
>

I use IOCTL_STORAGE_QUERY_PROPERTY in my sfilter as follows:
BOOLEAN
sfQueryDeviceProperty(
PDEVICE_OBJECT pDeviceObject,
PSTORAGE_DEVICE_DESCRIPTOR pDevDesc
)
{
PIRP pIrp;
KEVENT event;
IO_STATUS_BLOCK IoStatusBlock;
PIO_STACK_LOCATION pIoStackLocation;
PDEVICE_OBJECT pDevObj;
STORAGE_PROPERTY_QUERY Query;
DWORD dwOutBytes;

// Initialize the event
KeInitializeEvent (&event, SynchronizationEvent, FALSE);
pDevObj = IoGetAttachedDeviceReference(pDeviceObject);
Query.QueryType = PropertyStandardQuery;
Query.PropertyId = StorageDeviceProperty;
// Allocate an irp for this request. This could also come from a
// private pool, for instance.
pIrp = IoBuildDeviceIoControlRequest(
IOCTL_STORAGE_QUERY_PROPERTY,
pDevObj,
&Query,
sizeof(STORAGE_PROPERTY_QUERY),
pDevDesc,
pDevDesc->Size,
TRUE, // INTERNAL
&event,
&IoStatusBlock);

if(!pIrp)
{
// Failure!
ObDereferenceObject(pDevObj);
KdPrint((“[sfQueryRelations] IoAllocateIrp Failed…\n”));
return FALSE;
}

// Build the IRP’s main body
// Send it to the FSD
(void) IoCallDriver (pDevObj, pIrp);

// Wait for the I/O
KeWaitForSingleObject (&event, Executive, KernelMode, TRUE, 0);

ObDereferenceObject(pDevObj);

// 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);

return STATUS_MORE_PROCESSING_REQUIRED;
}

******Then I call the function in SfMountCompletion( ) function like this:

PDEVICE_OBJECT PhyDevObj;
CHAR Enumer[1024];
ULONG ulSize;
STORAGE_DEVICE_DESCRIPTOR DevDesc;
sfQueryDeviceProperty(vpb->RealDevice,&DevDesc);

Are there some problems the way I used? I don’t known where the problem is.

Why don’t U use ZwDeviceIoControlFile to query the driver? I uesd to get the capacity of the disk with IOCTL_STORAGE_QUERY_PROPERTY in the routine.

i want to judge it in mountcompletion, and if i use ZwDeviceIoControlFile, i should get the device’s handle, so how to get it here, it can not be got with zwopenfile, so please help me.

judge a hard disk is a USB hard disk ?
I don’t know how do this at kernel mode,
i just call GetDriveType at user mode and write the fix driver letter ,
then when call DriverEntry read the fix driver letter form registry.

So how can i get the current dispatch function hande IRP is wether for a USB
or hard disk?

дÈëÏûÏ¢ÐÂÎÅ:xxxxx@ntfsd…
>i want to judge it in mountcompletion, and if i use ZwDeviceIoControlFile,
>i should get the device’s handle, so how to get it here, it can not be got
>with zwopenfile, so please help me.
>