Hi all.
I want to attach a usb storage in minifilter.
In the InstanceSetupCallback routine:
Firstly,I judge the VolumeDeviceType.If the VolumeDeviceType
!= FILE_DEVICE_DISK_FILE_SYSTEM,return STATUS_FLT_DO_NOT_ATTACH.
Secondly,I get the VolumeProperties.
finally,if the flag FILE_REMOVABLE_MEDIA is on
in VolumeProperties->DeviceCharacteristics,return STATUS_SUCCESS to attach
the device.
Following are my codes in detail:
NTSTATUS
ScannerInstanceSetup (
__in PCFLT_RELATED_OBJECTS FltObjects,
__in FLT_INSTANCE_SETUP_FLAGS Flags,
__in DEVICE_TYPE VolumeDeviceType,
__in FLT_FILESYSTEM_TYPE VolumeFilesystemType
)
{
PFLT_VOLUME_PROPERTIES VolumeProperties;
ULONG returnLength;
NTSTATUS status;
UNREFERENCED_PARAMETER( Flags );
UNREFERENCED_PARAMETER( VolumeFilesystemType );
PAGED_CODE();
_asm int 3;
DbgPrint((“InstanceSetup…\n”));
if(FILE_DEVICE_DISK_FILE_SYSTEM != VolumeDeviceType) {
DbgPrint((“The VolumeDeviceType is not FILE_DEVICE_DISK_FILE_SYSTEM\n”));
return STATUS_FLT_DO_NOT_ATTACH;
}
DbgPrint((“The VolumeDeviceType is FILE_DEVICE_DISK_FILE_SYSTEM\n”));
// Allocate the memery for VolumeProperties
VolumeProperties = ( PFLT_VOLUME_PROPERTIES )ExAllocatePoolWithTag (
NonPagedPool,
sizeof(FLT_VOLUME_PROPERTIES) + 512,
FILE_POOL_TAG );
if( NULL == VolumeProperties ) {
DbgPrint((“InstanceSetupCallback: not enough memory to allocate
FLT_VOLUME_PROPERTIES\n” ));
return STATUS_FLT_DO_NOT_ATTACH;
}
returnLength = 0;
status = FltGetVolumeProperties( FltObjects->Volume,
VolumeProperties,
sizeof(FLT_VOLUME_PROPERTIES) + 512,
&returnLength );
if ( !NT_SUCCESS(status) ) {
DbgPrint((“InstanceSetupCallback: Error geting volume properties\n”
));
return STATUS_FLT_DO_NOT_ATTACH;
}
// Judge the information of the volume properties
// _asm int 3;
if(FILE_DEVICE_DISK_FILE_SYSTEM != VolumeProperties->DeviceType) {
DbgPrint((“The VolumeDeviceType is not FILE_DEVICE_DISK_FILE_SYSTEM\n”));
return STATUS_FLT_DO_NOT_ATTACH;
}
DbgPrint((“The VolumeDeviceType is FILE_DEVICE_DISK_FILE_SYSTEM\n”));
// _asm int 3;
if( !FlagOn(FILE_REMOVABLE_MEDIA, VolumeProperties->DeviceCharacteristics) )
{
DbgPrint((“The DeviceCharacteristics is not FILE_REMOVABLE_MEDIA\n”));
return STATUS_FLT_DO_NOT_ATTACH;
}
DbgPrint((“The DeviceCharacteristics is FILE_REMOVABLE_MEDIA\n”));
DbgPrint((“The Device is attached!!!\n”));
return STATUS_SUCCESS;
}
If it is not available??please tell me the reason and give me another
method??Thank you???