阅读:1683回复:2
请教下sfilter查询绑定卷是否为USB总线类型
用了很多驱网上的代码,查询函数:
ULONG GetStorageDeviceBusType(IN PDEVICE_OBJECT DeviceObject) { PIRP NewIrp; PSTORAGE_DEVICE_DESCRIPTOR Descriptor; STORAGE_PROPERTY_QUERY Query; UCHAR Buffer[sizeof(STORAGE_DEVICE_DESCRIPTOR)]; KEVENT WaitEvent; NTSTATUS Status; IO_STATUS_BLOCK IoStatus; // first set the query properties Query.PropertyId = StorageDeviceProperty; Query.QueryType = PropertyStandardQuery; // initialize the waitable event KeInitializeEvent(&WaitEvent, NotificationEvent, FALSE); // we should build the query irp ourselves NewIrp = IoBuildDeviceIoControlRequest(IOCTL_STORAGE_QUERY_PROPERTY, DeviceObject, (PVOID)&Query, sizeof(Query), (PVOID)Buffer, sizeof(Buffer), FALSE, &WaitEvent, &IoStatus); if (NULL == NewIrp) // can't create new irp { DbgPrint("[%s] [%u] I can't create a new irp to query the property of device (%p)!\n", __FILE__, __LINE__, DeviceObject); return BusTypeUnknown; } // send this irp to the storage device Status = IoCallDriver(DeviceObject, NewIrp); if (Status == STATUS_PENDING) { Status = KeWaitForSingleObject(&WaitEvent, Executive, KernelMode, FALSE, NULL); Status = IoStatus.Status; } if (!NT_SUCCESS(Status)) { DbgPrint("[%s] [%u] Query IOCTL_STORAGE_QUERY_PROPERTY of device (%p) failed, Status=0x%08X!\n", __FILE__, __LINE__, DeviceObject, Status); return BusTypeUnknown; } Descriptor = (PSTORAGE_DEVICE_DESCRIPTOR)Buffer; return Descriptor->BusType; } 我是在SfFsControlMountVolumeComplete里: if (!SfIsAttachedToDevice( vpb->DeviceObject, &attachedDeviceObject )) { //KdPrint(("卷还没有绑定")); // // Attach to the new mounted volume. The file system device // object that was just mounted is pointed to by the VPB. // status = SfAttachToMountedDevice( vpb->DeviceObject, NewDeviceObject ); if (!NT_SUCCESS( status )) { //KdPrint(("卷绑定失败")); // // The attachment failed, cleanup. Since we are in the // post-mount phase, we can not fail this operation. // We simply won't be attached. The only reason this should // ever happen at this point is if somebody already started // dismounting the volume therefore not attaching should // not be a problem. // SfCleanupMountedDevice( NewDeviceObject ); IoDeleteDevice( NewDeviceObject ); } KdPrint(("查询卷设备类型...")); deviceType = GetStorageDeviceBusType(vpb->RealDevice); KdPrint(("devicetype:%d",deviceType)); ASSERT( NULL == attachedDeviceObject ); 这里调用的,请问我这样正确吗?为什么我不管放在哪儿都是错的,请求帮助下吧,两天没解决了,谢谢 |
|
沙发#
发布于:2012-04-28 14:59
你需要有下面的设备对象,对这个设备发送控制命令查询。
|
|
|
板凳#
发布于:2012-05-04 11:38
在SfFsControlMountVolumeComplete中
if(status==STATUS_SUCCESS) { if(newDevExt->StorageStackDeviceObject==NULL) { goto _Exit; } if(DeviceObject->DeviceType!=FILE_DEVICE_DISK_FILE_SYSTEM) { goto _Exit; } if(IsUSBDsk(newDevExt->StorageStackDeviceObject)==1) { goto _Exit; } } static int IsUSBDsk(PDEVICE_OBJECT pstDskDvc) { int iRet=0; NTSTATUS nFunRet; IO_STATUS_BLOCK stIOStatus; KEVENT stEvent; PIRP pstIOCtlIRP; PSTORAGE_DEVICE_DESCRIPTOR pstDvcDsc=NULL; STORAGE_PROPERTY_QUERY stDvcQuery; pstDvcDsc=(PSTORAGE_DEVICE_DESCRIPTOR)ExAllocatePool( NonPagedPool,sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512-1 ); pstDvcDsc->Size=sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1; stDvcQuery.PropertyId=StorageDeviceProperty; stDvcQuery.QueryType=PropertyStandardQuery; KeInitializeEvent(&stEvent,NotificationEvent,FALSE); if( (pstIOCtlIRP=IoBuildDeviceIoControlRequest( IOCTL_STORAGE_QUERY_PROPERTY, pstDskDvc, &stDvcQuery,sizeof(STORAGE_PROPERTY_QUERY), pstDvcDsc,pstDvcDsc->Size, FALSE, &stEvent, &stIOStatus))==NULL ) { SYCLCMN_LOG( (pszInf,"IsUSBDsk:IoBuildDeviceIoControlRequest ret NULL!!!") ); nFunRet=STATUS_INSUFFICIENT_RESOURCES; goto _Exit; } nFunRet=IoCallDriver(pstDskDvc,pstIOCtlIRP); if(nFunRet==STATUS_PENDING) { KeWaitForSingleObject(&stEvent,Executive,KernelMode,FALSE,NULL); nFunRet=stIOStatus.Status; } if( !NT_SUCCESS(nFunRet) ) { SYCLCMN_LOG( (pszInf,"IsUSBDsk:IoCallDriver ret %X!!!",nFunRet) ); goto _Exit; } if(pstDvcDsc->BusType==BusTypeUsb) { iRet=1; } _Exit: if(pstDvcDsc!=NULL) { ExFreePool(pstDvcDsc); } return iRet; } |
|