Waiting on I/O in Driver

Hi–

Could not find any relevant Q&A on the list server on this topic.

I’m trying to wait on file I/O (ZwWriteFile ()) and am not able
to successfully use an event. The routine is called from an
IoQueueWorkItem-dispatched
routine. It errs with code 0xC0000008–Invalid Handle.

The Create:
InitializeObjectAttributes (&ObjectAttributes,
&unicodeFileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );

ntStatus = ZwCreateFile(&hHandle,
SYNCHRONIZE | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL, // alloc size = none
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OVERWRITE_IF,
FILE_SEQUENTIAL_ONLY
| FILE_NO_INTERMEDIATE_BUFFERING
| FILE_SYNCHRONOUS_IO_NONALERT,
NULL,0 );

The Write Attempt:
KEVENT event ;
KeInitializeEvent (&event, NotificationEvent, FALSE) ;

ntStatus = ZwWriteFile(hHandle,
&event,
NULL,NULL,
&IoStatus,
pDataBlock,
u32WriteAmount,
0,NULL );

ntStatus is == 0xC0000008.

The code works fine if I do not attempt to wait on the operation.
The DDK (apparently) recommends against using an event in this context
but there are times when I must not proceed until the I/O has completed.

What is the recommended way for waiting on file I/O in a driver?
Bob Loewer

Bob,

Your code passes in an address of an event OBJECT, not an event HANDLE. You
need to use ZwCreateEvent to get an event handle back.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: Bob Loewer [mailto:xxxxx@intercepts.biz]
Sent: Monday, March 11, 2002 4:31 PM
To: File Systems Developers
Subject: [ntfsd] Waiting on I/O in Driver

Hi–

Could not find any relevant Q&A on the list server on this topic.

I’m trying to wait on file I/O (ZwWriteFile ()) and am not able
to successfully use an event. The routine is called from an
IoQueueWorkItem-dispatched
routine. It errs with code 0xC0000008–Invalid Handle.

The Create:
InitializeObjectAttributes (&ObjectAttributes,
&unicodeFileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );

ntStatus = ZwCreateFile(&hHandle,
SYNCHRONIZE | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL, // alloc size = none
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OVERWRITE_IF,
FILE_SEQUENTIAL_ONLY
| FILE_NO_INTERMEDIATE_BUFFERING
| FILE_SYNCHRONOUS_IO_NONALERT,
NULL,0 );

The Write Attempt:
KEVENT event ;
KeInitializeEvent (&event, NotificationEvent, FALSE) ;

ntStatus = ZwWriteFile(hHandle,
&event,
NULL,NULL,
&IoStatus,
pDataBlock,
u32WriteAmount,
0,NULL );

ntStatus is == 0xC0000008.

The code works fine if I do not attempt to wait on the operation.
The DDK (apparently) recommends against using an event in this context
but there are times when I must not proceed until the I/O has completed.

What is the recommended way for waiting on file I/O in a driver?
Bob Loewer

You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to %%email.unsub%%