ZwReadFile, ZwWriteFile within IOCTL?

Hallo!

I wrote some kind of “virtual hdd drive” using the KMDF.
With my driver I simulate a HDD and translate all read and write requests to
read and write operations on a file using ZwReadFile and ZwWriteFile.
The file was created / opened with ZwCreateFile in the DeviceAdd function.

As far as I tested the driver, no problem occured.
Is it save to use these functions (ZwReadFile, ZwWriteFile) within an IOCTL?

Markus

It is only safe if your IOCTL routine runs at PASSIVE_LEVEL. If other
KM drivers are going to send you i/o or you are doing this in response
to upper storage levels, you will get I/O at dispatch level.

BTW, you can use a WDFIOTARGET for managing the file handle. You open
the target and then use WdfIoTargetFormatRequestForRead/
WdfIoTargetFormatRequestForWrite + WdfRequestSend. The Zw routines
might be good enough for your purposes, but I thought I would throw this
out there…

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Markus
Sent: Saturday, September 09, 2006 2:36 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] ZwReadFile, ZwWriteFile within IOCTL?

Hallo!

I wrote some kind of “virtual hdd drive” using the KMDF.
With my driver I simulate a HDD and translate all read and write
requests to
read and write operations on a file using ZwReadFile and ZwWriteFile.
The file was created / opened with ZwCreateFile in the DeviceAdd
function.

As far as I tested the driver, no problem occured.
Is it save to use these functions (ZwReadFile, ZwWriteFile) within an
IOCTL?

Markus


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Well as long as everything is going ok Zw*, the user might be pleased. But
if there is a “bad situation” the user might be angry.
So thanks for the hint! I’ll try it to make my driver robust and use these
Wdf-functions.

Markus

“Doron Holan” schrieb im Newsbeitrag
news:xxxxx@ntdev…
It is only safe if your IOCTL routine runs at PASSIVE_LEVEL. If other
KM drivers are going to send you i/o or you are doing this in response
to upper storage levels, you will get I/O at dispatch level.

BTW, you can use a WDFIOTARGET for managing the file handle. You open
the target and then use WdfIoTargetFormatRequestForRead/
WdfIoTargetFormatRequestForWrite + WdfRequestSend. The Zw routines
might be good enough for your purposes, but I thought I would throw this
out there…

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Markus
Sent: Saturday, September 09, 2006 2:36 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] ZwReadFile, ZwWriteFile within IOCTL?

Hallo!

I wrote some kind of “virtual hdd drive” using the KMDF.
With my driver I simulate a HDD and translate all read and write
requests to
read and write operations on a file using ZwReadFile and ZwWriteFile.
The file was created / opened with ZwCreateFile in the DeviceAdd
function.

As far as I tested the driver, no problem occured.
Is it save to use these functions (ZwReadFile, ZwWriteFile) within an
IOCTL?

Markus


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

KMDF routines are not any more robust then the Zw routines if you are
doing synchronous I/O. If you are doing async i/o, the WDFIOTARGET
provides i/o tracking until the i/o completes, the Zw routines do not
provide such tracking. If you are performing sync i/o, I would stick
w/the Zw routines.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Markus
Sent: Saturday, September 09, 2006 4:01 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] ZwReadFile, ZwWriteFile within IOCTL?

Well as long as everything is going ok Zw*, the user might be pleased.
But
if there is a “bad situation” the user might be angry.
So thanks for the hint! I’ll try it to make my driver robust and use
these
Wdf-functions.

Markus

“Doron Holan” schrieb im Newsbeitrag
news:xxxxx@ntdev…
It is only safe if your IOCTL routine runs at PASSIVE_LEVEL. If other
KM drivers are going to send you i/o or you are doing this in response
to upper storage levels, you will get I/O at dispatch level.

BTW, you can use a WDFIOTARGET for managing the file handle. You open
the target and then use WdfIoTargetFormatRequestForRead/
WdfIoTargetFormatRequestForWrite + WdfRequestSend. The Zw routines
might be good enough for your purposes, but I thought I would throw this
out there…

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Markus
Sent: Saturday, September 09, 2006 2:36 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] ZwReadFile, ZwWriteFile within IOCTL?

Hallo!

I wrote some kind of “virtual hdd drive” using the KMDF.
With my driver I simulate a HDD and translate all read and write
requests to
read and write operations on a file using ZwReadFile and ZwWriteFile.
The file was created / opened with ZwCreateFile in the DeviceAdd
function.

As far as I tested the driver, no problem occured.
Is it save to use these functions (ZwReadFile, ZwWriteFile) within an
IOCTL?

Markus


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> If you are doing async i/o, the WDFIOTARGET provides i/o tracking

until the i/o completes, the Zw routines do not provide such tracking.

The Zw routines can be made async and notified via APC or an event the i/o is complete. How does WDFIOTARGET compare or contrast to this?

And to the OP, there could be trouble with your file handle you need to overcome if you use the Zw routines from an IOCTL because it will be a different process context than where it was opened.

eof

The WDFIOTARGET uses WDFREQUESTS (PIRPS) and does not use APCs or
events. This means you can use a completion routine to be notified of
completion.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@email.com
Sent: Saturday, September 09, 2006 10:36 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] ZwReadFile, ZwWriteFile within IOCTL?

If you are doing async i/o, the WDFIOTARGET provides i/o tracking
until the i/o completes, the Zw routines do not provide such tracking.

The Zw routines can be made async and notified via APC or an event the
i/o is complete. How does WDFIOTARGET compare or contrast to this?

And to the OP, there could be trouble with your file handle you need to
overcome if you use the Zw routines from an IOCTL because it will be a
different process context than where it was opened.

eof


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer