NIKHIL V S
NIKHIL V S

Reputation: 29

What is the IRP message generated on file delete in a filter driver?

I am trying to create a filter driver to block file deletion operations, but I can't identify the IRP message on deleting files.

I worked with the code below; it works in windows 7 but not in windows version 8 or later.

if (pIrp->MajorFunction==IRP_MJ_WRITE || pIrp->MajorFunction==IRP_MJ_SET_INFORMATION ||
            pIrp->MajorFunction==IRP_MJ_SET_VOLUME_INFORMATION || pIrp->MajorFunction==IRP_MJ_SET_SECURITY ||
            pIrp->MajorFunction==IRP_MJ_SET_QUOTA)
    {
                             DbgPrint("fdrv :Read only operation block");
            Irp->IoStatus.Status = STATUS_ACCESS_DENIED;//Deny Access
            Irp->IoStatus.Information = 0;
            IoCompleteRequest(Irp, IO_NO_INCREMENT);
            return STATUS_ACCESS_DENIED;

            }

Upvotes: 0

Views: 1051

Answers (1)

RbMm
RbMm

Reputation: 33716

exist 2 ways to delete file

--

union {
    PVOID Buffer;
    PFILE_DISPOSITION_INFORMATION pfdi;
    PFILE_DISPOSITION_INFORMATION_EX pfdi_ex;
};
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
switch (IrpSp->MajorFunction)
{
case IRP_MJ_SET_INFORMATION:
    Buffer = Irp->AssociatedIrp.SystemBuffer;
    switch (IrpSp->Parameters.SetFile.FileInformationClass)
    {
    case FileDispositionInformation:
        if (pfdi->DeleteFile)
        {
            //
        }
        break;
    case FileDispositionInformationEx:
        if (pfdi_ex->Flags & FILE_DISPOSITION_DELETE)
        {
            //
        }
        break;
    }
    break;
case IRP_MJ_CREATE:
    if (IrpSp->Parameters.Create.Options & FILE_DELETE_ON_CLOSE)
    {
        //
    }
    break;
}

Upvotes: 1

Related Questions