views:

78

answers:

1

I am writing a windows filesystem minifilter driver that must fail I/O Request Packets (IRP's) in a preoperation callback based on their type (read/write).
How can I find out from the callback parameters (or elsewhere?) if the operation is read-like ( only reads data ) or it's write-like ( modifies data on the disk - write, delete, format etc ) ?

Here is a list of major IRP codes.

I'm thinking on stuff like:

Data->Iopb->TargetFileObject->ReadAccess 
Data->Iopb->TargetFileObject->WriteAccess 

But I'm not sure, I think these are available only in postoperation callback. The documentation is really cumbersome.

Code sample for further clarification:

FLT_PREOP_CALLBACK_STATUS
Fail (
    __inout PFLT_CALLBACK_DATA Data,
    __in PCFLT_RELATED_OBJECTS FltObjects,
    __deref_out_opt PVOID *CompletionContext
    )
{
    FLT_PREOP_CALLBACK_STATUS status = FLT_PREOP_SUCCESS_NO_CALLBACK;
    //********************************************************************
    if ( IS_WRITE_LIKE(Data, FltObjects)  ) { // ??? HOW DO I FIND OUT ???
    //********************************************************************  
        if( FLT_IS_FASTIO_OPERATION(Data) ){
            status = FLT_PREOP_DISALLOW_FASTIO;
        } else {
            status = FLT_PREOP_COMPLETE;
        }
        Data->IoStatus.Status = STATUS_ACCESS_DENIED;
        Data->IoStatus.Information = 0;
        return status;

    }
    return status;
}
A: 

Here is an euristic list I got after a lot of trial and error:

write-like:

IRP_MJ_SET_EA
IRP_MJ_SET_INFORMATION
IRP_MJ_SET_QUOTA
IRP_MJ_SET_SECURITY
IRP_MJ_SET_VOLUME_INFORMATION
IRP_MJ_WRITE 

read-like:

IRP_MJ_CREATE
IRP_MJ_DEVICE_CONTROL
IRP_MJ_FILE_SYSTEM_CONTROL
IRP_MJ_FLUSH_BUFFERS
IRP_MJ_INTERNAL_DEVICE_CONTROL
IRP_MJ_QUERY_EA
IRP_MJ_QUERY_INFORMATION
IRP_MJ_QUERY_QUOTA
IRP_MJ_QUERY_SECURITY
IRP_MJ_QUERY_VOLUME_INFORMATION
IRP_MJ_READ
IRP_MJ_OPERATION_END
clyfe
I have not sat down to verify this but I would have thought IRP_MJ_CREATE was "write-like", depending on flags. No criticism, just a question.
Jan
Thank you for your feedback, I'll dig in some more, I belive you are right.
clyfe