non-blocking file open?

From a thread inside the kernel I need to open a file, and compute the hash of its contents.
I do this for a list of files collected in another context.

Occasionally, my ZwCreateFile hangs … forever I think, I have not waited long enough to know, but I think its forever.

Is there a way to have a timeout on a file open?

Am I specifying something wrong that is perhaps trying to gain exclusive access?

Here is code snip:

if (KeGetCurrentIrql() != PASSIVE_LEVEL) {
TRACE(DL_ERROR, “CtIsBinaryFileType KeGetCurrentIrql is not PASSIVE_LEVEL ???\n”) ;
return FALSE;
}

RtlZeroMemory( &ioStatusBlock, sizeof(ioStatusBlock) );
RtlInitUnicodeString(&pathName, wstrPathName);
InitializeObjectAttributes(&objectAttr, &pathName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);

status = ZwCreateFile(&myFileHandle, // FileHandle
GENERIC_READ, // DesiredAccess
&objectAttr, // ObjectAttributes
&ioStatusBlock, // IoStatusBlock
NULL, // AllocationSize
FILE_ATTRIBUTE_NORMAL, // FileAttributes
FILE_SHARE_READ | FILE_SHARE_WRITE, // ShareAccess (0 = exclusive access)
FILE_OPEN, // CreateDisposition
FILE_SYNCHRONOUS_IO_NONALERT, // CreateOptions
NULL, // EaBuffer
0); // EaLength

>Occasionally, my ZwCreateFile hangs … forever I think, I have not waited

long enough to know, but I think its forever.

Ha! My usual response to, “it hangs forever” is, “well, forever is a long
time, are you sure you waited forever?” so this made my afternoon…

Can you post the call stack of the hanging thread?

-scott


Scott Noone
Consulting Associate and Chief System Problem Analyst
OSR Open Systems Resources, Inc.
http://www.osronline.com

Apologies, ship week(s) and this has not re-occurred where i can trap the call stack.
As it turns out it wasn’t forever in human terms, but was almost forever in computer terms.

It stayed hung on that open for almost 2 minutes, it was a windows update file, so perhaps they held it exclusive while downloading something from the web… don’t know.

My basic question remains though, is it possible to have io, open in this case, be non-blocking.
My memory is fuzzy, but I thought on linux I could do non-blocking io.

IO is non-blocking in Windows for the most part, but most Create/Open
calls are blocking.

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@gmail.com” wrote in message
news:xxxxx@ntfsd:

> Apologies, ship week(s) and this has not re-occurred where i can trap the call stack.
> As it turns out it wasn’t forever in human terms, but was almost forever in computer terms.
>
> It stayed hung on that open for almost 2 minutes, it was a windows update file, so perhaps they held it exclusive while downloading something from the web… don’t know.
>
> My basic question remains though, is it possible to have io, open in this case, be non-blocking.
> My memory is fuzzy, but I thought on linux I could do non-blocking io.