none
filter driver to block read and write requests to u-disk RRS feed

  • Question

  • read and write operation needs password. if password is wrong, all read and write requests are blocked.

    my code segment is below:

    NTSTATUS
    USBSCSICompletion( IN PDEVICE_OBJECT DeviceObject,
                       IN PIRP Irp,
                       IN PVOID Context )
    {
        PDEVICE_EXTENSION pdx = ( PDEVICE_EXTENSION )
                                       DeviceObject->DeviceExtension;
    
    	IoAcquireRemoveLock(&pdx->RemoveLock,Irp);
    
        PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation( Irp );
    
    	PSCSI_REQUEST_BLOCK CurSrb=irpStack->Parameters.Scsi.Srb; 
    	PCDB cdb = (PCDB)CurSrb->Cdb; 
    	UCHAR opCode=cdb->CDB6GENERIC.OperationCode; 
    
    	if(opCode==SCSIOP_MODE_SENSE  && CurSrb->DataBuffer 
    		&& CurSrb->DataTransferLength >= 
    		sizeof(MODE_PARAMETER_HEADER))
    	{
    		KdPrint(("SCSIOP_MODE_SENSE comming!\n"));
    
    		PMODE_PARAMETER_HEADER modeData = (PMODE_PARAMETER_HEADER)CurSrb->DataBuffer;
    
    		modeData->DeviceSpecificParameter |= MODE_DSP_WRITE_PROTECT;
    	} 
    
    	if (opCode == SCSIOP_READ)
    	{
    		Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
    		Irp->IoStatus.Information = 0;
    		IoCompleteRequest(Irp, IO_NO_INCREMENT);
    	}
    
    	if ( Irp->PendingReturned )
    	{
    		IoMarkIrpPending( Irp );
    	} 
    
    	IoReleaseRemoveLock(&pdx->RemoveLock,Irp);
    
    	return Irp->IoStatus.Status ;
    } 

    but when I plug in my u-disk to my computer, windows7 32bit goes to blue screen immediately.

    and the log file segment is below:

    PFN_LIST_CORRUPT (4e)
    Typically caused by drivers passing bad memory descriptor lists (ie: calling
    MmUnlockPages twice with the same list, etc).  If a kernel debugger is
    available get the stack trace.
    Arguments:
    Arg1: 00000007, A driver has unlocked a page more times than it locked it
    Arg2: 0007e861, page frame number
    Arg3: 00000001, current share count
    Arg4: 00000000, 0
    can anyone tell me how to correct my code? thanks!

    Tuesday, May 17, 2016 9:09 AM

All replies

  • I guess the first question is why are you failing things on the completion, it is much easier to fail on the request.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Tuesday, May 17, 2016 11:03 AM