How to know if file exist from minifilter

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

Open it with FltCreateFile() and check the status.

Ken


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gian-luca Tenti
Sent: Thursday, January 12, 2006 8:07 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] How to know if file exist from minifilter

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com