Hi All,
For checking whether a file for which an IRP_MJ_CREATE Packet has come
already exists or not, I am making an IRP in the IRP_MJ_CREATE routine and
then checking the status to know whether the file already exists.
The code for IRP creation is as follows.
irp->UserEvent = &event;
irp->UserIosb = &IoStatusBlock;
irp->Tail.Overlay.Thread = PsGetCurrentThread();
irp->Tail.Overlay.OriginalFileObject = FileObject;
irp->RequestorMode = KernelMode;
KeInitializeEvent(&event, SynchronizationEvent, FALSE);
DbgPrint(“Initialized Event”);
ioStackLocation = IoGetNextIrpStackLocation(irp);
ioOriginalStackLocation = IoGetNextIrpStackLocation(Irp);
ioStackLocation->MajorFunction = IRP_MJ_CREATE;
ioStackLocation->DeviceObject = fsdDevice;
ioStackLocation->FileObject = FileObject;
DbgPrint(“Done with the first part of stack allocation”);
//Change the Parameters to check the just existence of the file
ioStackLocation->Parameters.Create.Options=FILE_NON_DIRECTORY_FILE
|(FILE_OPEN <<24) ;
DbgPrint(“Set option”);
ioStackLocation->Parameters.Create.FileAttributes=FILE_ATTRIBUTE_NORMAL;
DbgPrint(“Set Attrib”);
ioStackLocation->Parameters.Create.ShareAccess= 0x0;
DbgPrint(“ShareAccess”);
ioStackLocation->Parameters.Create.SecurityContext->DesiredAccess=FILE_READ_ATTRIBUTES;
DbgPrint(“Desired Access”);
ioStackLocation->Parameters.Create.SecurityContext->FullCreateOptions=
ioOriginalStackLocation->Parameters.Create.Options;
DbgPrint(“Done with the second part”);
IoSetCompletionRoutine(irp, MyCreateCompletion, 0, TRUE, TRUE, TRUE);
DbgPrint(“Completion routine set”);
//IoCallDriver(
((PFILESPY_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->AttachedToDeviceObject,
irp );
(void)IoCallDriver(fsdDevice, irp);
DbgPrint(“Got the clue”);
KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, 0);
DbgPrint(“Came Back”);
if( IoStatusBlock.Information == FILE_CREATED )
DbgPrint(“Created”);
if( IoStatusBlock.Information == FILE_OPENED )
DbgPrint(“Opened”);
if( IoStatusBlock.Information == FILE_OVERWRITTEN )
DbgPrint(“Overwritten”);
if( IoStatusBlock.Information == FILE_SUPERSEDED )
DbgPrint(“Superseded”);
if( IoStatusBlock.Information == FILE_EXISTS )
DbgPrint(“Exists”);
if( IoStatusBlock.Information == FILE_DOES_NOT_EXIST )
DbgPrint(“DNE”);
Now I am getting exception 0xc0000005 in the lines.
ioStackLocation->Parameters.Create.SecurityContext->DesiredAccess=FILE_READ_ATTRIBUTES;
DbgPrint(“Desired Access”);
ioStackLocation->Parameters.Create.SecurityContext->FullCreateOptions=
ioOriginalStackLocation->Parameters.Create.Options;
DbgPrint(“Done with the second part”);
If i remove these lines, then on IoCallDriver I am getting the same
exception.
What might be the reason.
As per documentation it stands for.
//
// MessageId: STATUS_ACCESS_VIOLATION
//
// MessageText:
//
// The instruction at “0x%08lx” referenced memory at “0x%08lx”. The
memory could not be “%s”.
//
#define STATUS_ACCESS_VIOLATION ((NTSTATUS)0xC0000005L) //
winnt
But I am not geting clues.
Please Help
Regards
Lalit