What does STATUS_PENDING mean for ZwWriteFile?

We perform the following operations from a system thread in our file system
filter driver:

  1. Open a file for buffered i/o without the SYNCHRONIZE flag.
  2. Make several calls to ZwWriteFile with Non-paged pool buffers.
  3. Free the buffers when the call returns - without waiting when the return is
    STATUS_PENDING
  4. Repeat (thousands of times)

After performing the above for a period of time when the system is flooded with
file accesses and the cpu running at 100% we experience memory access violations
when making kernel calls - usually KeWaitForSingleObject(…) throws an
access-violation exception.

When we modify step 1) to include the SYNCHRONIZE flag and step 3) to wait for
the file handle to be signaled before we free the buffer, we don’t get these
memory access violations.

The questions that I have are:

  1. Does STATUS_PENDING mean that the call to ZwWriteFile has not copied the
    buffer and it should not be freed?
  2. Are the modifications that we made masking the true problem, or is that
    the proper method for dealing with the STATUS_PENDING return value from
    ZwWriteFile? The documentation is not clear on this topic.

Thanks

If you want synchronous I/O, you should specify that in the options
(FILE_SYNCHRONOUS_IO_NONALERT or FILE_SYNCHRONOUS_IO_ALERT). The
SYNCHRONIZE right has to do with the ability to perform certain
synchronization operations on the file object itself.

STATUS_PENDING tells you the I/O is in progress and indeterminate state.
Often the I/O is done by the time you get this return (it is decoupled,
so you just don’t know the order of events any longer) and even after
you free the buffer it might not be used afterwards - if you enabled
driver verifier the system would “blow up” very quickly in the
situations you are describing.

If you want to free the buffer, either wait until the I/O is done or
perform the operations in an APC - you can specify these options in your
call to ZwWriteFile. Or specify that you want the OS to wait on the I/O
for you (the FILE_SYNCHRONOUS_IO_NONALERT bit).

Regards,

Tony

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

Looking forward to seeing you at the Next OSR File Systems Class October
18, 2004 in Silicon Valley!

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Kevin Eichenberg
Sent: Wednesday, May 26, 2004 9:57 AM
To: ntfsd redirect
Subject: [ntfsd] What does STATUS_PENDING mean for ZwWriteFile?

We perform the following operations from a system thread in our file
system
filter driver:

  1. Open a file for buffered i/o without the SYNCHRONIZE flag.
  2. Make several calls to ZwWriteFile with Non-paged pool buffers.
  3. Free the buffers when the call returns - without waiting when the
    return is
    STATUS_PENDING
  4. Repeat (thousands of times)

After performing the above for a period of time when the system is
flooded with
file accesses and the cpu running at 100% we experience memory access
violations
when making kernel calls - usually KeWaitForSingleObject(…) throws an
access-violation exception.

When we modify step 1) to include the SYNCHRONIZE flag and step 3) to
wait for
the file handle to be signaled before we free the buffer, we don’t get
these
memory access violations.

The questions that I have are:

  1. Does STATUS_PENDING mean that the call to ZwWriteFile has not
    copied the
    buffer and it should not be freed?
  2. Are the modifications that we made masking the true problem, or is
    that
    the proper method for dealing with the STATUS_PENDING return value from
    ZwWriteFile? The documentation is not clear on this topic.

Thanks


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

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

> 1) Does STATUS_PENDING mean that the call to ZwWriteFile has not copied
the

buffer and it should not be freed?

Yes. Wait on the event handle provided to ZwWriteFile to be sure on completion.
This is the Win32’s ERROR_IO_PENDING.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com