Hi,
in the IRP_MJ_CREATE Preop of a minifilter, I’ve to know if the file
exist.
I call the IoFastQueryNetworkAttributes but the system gives me an
unhandled exception and then a BSOD.
I’ve used also the IoCreateFileSpecifyDeviceObjectHint but with the same
result.
This is the Vladimir Chtchetkine’s code I’ve used.
NTSTATUS GetExistanceStatus( PUNICODE_STRING puPath, PIO_STATUS_BLOCK
pIoStatus )
{
NTSTATUS status = -1;
OBJECT_ATTRIBUTES aFileAttrib;
FILE_NETWORK_OPEN_INFORMATION aInfo;
ASSERT(KeGetCurrentIrql()==PASSIVE_LEVEL);
#if (WINVER>=0x500)
InitializeObjectAttributes( &aFileAttrib,
puPath,OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL );
#else
InitializeObjectAttributes( &aFileAttrib,
puPath,OBJ_CASE_INSENSITIVE, NULL, NULL );
#endif
//
// Use FastOpen (if possible). If not that call will roll
// create IRP.
//
status = IoFastQueryNetworkAttributes( &aFileAttrib, SYNCHRONIZE,
0,pIoStatus, &aInfo);
if( NT_SUCCESS(status) )
status = pIoStatus -> Status;
return status;
}
//
// Check if a local file or dir exists (via open)
//
BOOLEAN FileExist(PUNICODE_STRING puPath)
{
IO_STATUS_BLOCK IoStatus;
NTSTATUS status = GetExistanceStatus( puPath, &IoStatus );
if( NT_SUCCESS(status) )
{
return TRUE;
}
else if( (status == STATUS_OBJECT_NAME_NOT_FOUND) ||
(IoStatus.Information == FILE_DOES_NOT_EXIST) ||
(status == STATUS_OBJECT_PATH_NOT_FOUND) ||
(status == STATUS_OBJECT_NAME_INVALID) ||
(status == STATUS_OBJECT_PATH_INVALID) )
{
return FALSE;
}
return TRUE;
}
There is a way to know if a file exists?
Thank’s