Storage drivers

Is it legal to call WaitFor* functions in the IRP_MJ_READ/WRITE dispatch
handlers in a storage driver (e.g. CD-ROM)? Seems like the DDK says
no, but there are some sample drivers that do it anyway. Does it matter
if the device cannot possibly hold a page file due to being read-only,
or if the device is removable?

Thanks.

Joe Black

Concerned about your privacy? Follow this link to get
FREE encrypted email: https://www.hushmail.com/?l=2

Free, ultra-private instant messaging with Hush Messenger
https://www.hushmail.com/services.php?subloc=messenger&l=434

Promote security and make money with the Hushmail Affiliate Program:
https://www.hushmail.com/about.php?subloc=affiliate&l=427

In general this is bad practice in any Read/Write dispatch routine, forget
about storage drivers. What exactly are you trying to do that you believe
requires you to do a synchronous wait?

(Instead of blocking the dispatch routine, consider queueing the request and
signalling some worker thread that does whatever hideous blocking nonsense
you must do.)

What if you aren’t at < DISPATCH_LEVEL?

The storage sample drivers I browsed do not block on read/write requests.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joe Black
Sent: Monday, February 16, 2004 1:18 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Storage drivers

Is it legal to call WaitFor* functions in the
IRP_MJ_READ/WRITE dispatch handlers in a storage driver (e.g.
CD-ROM)? Seems like the DDK says no, but there are some
sample drivers that do it anyway. Does it matter if the
device cannot possibly hold a page file due to being
read-only, or if the device is removable?

Thanks.

Joe Black

Concerned about your privacy? Follow this link to get FREE
encrypted email: https://www.hushmail.com/?l=2

Free, ultra-private instant messaging with Hush Messenger
https://www.hushmail.com/services.php?subloc=messenger&l=434

Promote security and make money with the Hushmail Affiliate Program:
https://www.hushmail.com/about.php?subloc=affiliate&l=427


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

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

On Mon, 2004-02-16 at 12:38, Mark Roddy wrote:

In general this is bad practice in any Read/Write dispatch routine,

forget about storage drivers. What exactly are you trying to do that

you believe requires you to do a synchronous wait?

Any hardware that interrupts as a response to its command could work
with that model (perhaps not should, but could). What if you have 3
command/interrupt phases that you have to go through to service a read
or write?

I know there are other ways to do this, one of which you outline below,
but I’m more curious about the principle.

The storage sample drivers I browsed do not block on read/write
requests.

In the current DDK, in floppy.c, FloppyReadWrite (the dispatch handler
for IRP_MJ_READ) calls ExAcquireFastMutex.

Joe Black

Concerned about your privacy? Follow this link to get
FREE encrypted email: https://www.hushmail.com/?l=2

Free, ultra-private instant messaging with Hush Messenger
https://www.hushmail.com/services.php?subloc=messenger&l=434

Promote security and make money with the Hushmail Affiliate Program:
https://www.hushmail.com/about.php?subloc=affiliate&l=427

“Joe Black” wrote in message news:xxxxx@ntdev…
> On Mon, 2004-02-16 at 12:38, Mark Roddy wrote:
> > In general this is bad practice in any Read/Write dispatch routine,
>
> > forget about storage drivers. What exactly are you trying to do that
>
> > you believe requires you to do a synchronous wait?
>
> Any hardware that interrupts as a response to its command could work
> with that model (perhaps not should, but could). What if you have 3
> command/interrupt phases that you have to go through to service a read
> or write?
>
> I know there are other ways to do this, one of which you outline below,
> but I’m more curious about the principle.
>

The unix model of sleeping in the toplevel entry points for device drivers
should not be used in NT. It probably shouldn’t be used in unix either, but
that is a different story. The issue is that NT has an asynchronous IO model
and your driver should not, unless it absolutely has to, break that model by
imposing its own synchronous IO model on top of it.

Staged IO requests are quite common. They require an event-driven state
machine to process them, they do not require a synchronous programming
model.

> > The storage sample drivers I browsed do not block on read/write
> > requests.
>
> In the current DDK, in floppy.c, FloppyReadWrite (the dispatch handler
> for IRP_MJ_READ) calls ExAcquireFastMutex.
>

Yes indeed I was afraid that it would be floppy. Please ignore just about
everything that the floppy driver does. You will be a better kernel
programmer for doing so :slight_smile:



=====================
Mark Roddy
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com
xxxxx@hollistech.com

Well in principle it’s a bad thing to do. Windows lets the caller
determine if they want the I/O request to be synchronous or asynchronous

  • by blocking in the dispatching thread you’re forcing them into a
    synchronous operation regardless of what they requested when they opened
    the file.

It’s a bad idea in storage in particular for two reasons:

  1. storage drivers (including the file systems) will dispatch I/O in
    completion routines or timers which are typically running at dispatch
    level. You can’t reliably block in your dispatch routine because you
    might be at dispatch level.

  2. when in the paging path you become part of a dependency chain where
    improper blocking can result in a deadlock. For example, say the lock
    you want is being held by a thread that’s trying to allocate memory,
    which cause the system to try and clear some paged memory out which
    causes a paging I/O to your device which blocks because of the lock
    you’re holding.

In the case of the floppy driver it never becomes part of that
dependency chain. In the case of a read-only volume #2 also probably
doesn’t apply (until someone decides to use your driver in an embedded
system that boots from a hibernation file and caches writes in a filter
above your driver). But #1 still applies and it’s generally very hard
to figure out how your driver will be used after you’ve sold the
hardware.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joe Black
Sent: Monday, February 16, 2004 11:30 AM
To: Windows System Software Devs Interest List
Subject: RE: RE: [ntdev] Storage drivers

On Mon, 2004-02-16 at 12:38, Mark Roddy wrote:

In general this is bad practice in any Read/Write dispatch routine,

forget about storage drivers. What exactly are you trying to do that

you believe requires you to do a synchronous wait?

Any hardware that interrupts as a response to its command could work
with that model (perhaps not should, but could). What if you have 3
command/interrupt phases that you have to go through to service a read
or write?

I know there are other ways to do this, one of which you outline below,
but I’m more curious about the principle.

The storage sample drivers I browsed do not block on read/write
requests.

In the current DDK, in floppy.c, FloppyReadWrite (the dispatch handler
for IRP_MJ_READ) calls ExAcquireFastMutex.

Joe Black

Concerned about your privacy? Follow this link to get FREE encrypted
email: https://www.hushmail.com/?l=2

Free, ultra-private instant messaging with Hush Messenger
https://www.hushmail.com/services.php?subloc=messenger&l=434

Promote security and make money with the Hushmail Affiliate Program:
https://www.hushmail.com/about.php?subloc=affiliate&l=427


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

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

The floppy uses a thread to process requests. The wait is done in the
context of the thread (PASSIVE_LEVEL). In this case, you can do some things
you can not normally do, but there is a serious performance hit when doing
this. The floppy device is so slow, it does not matter that it is being
processed in a thread; the device is far slower than the context switch
between the dispatch caller and the posting to the thread queue.

Jamey

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Peter Wieland
Sent: Monday, February 16, 2004 11:57 AM
To: Windows System Software Devs Interest List
Subject: RE: RE: [ntdev] Storage drivers

Well in principle it’s a bad thing to do. Windows lets the caller
determine if they want the I/O request to be synchronous or asynchronous

  • by blocking in the dispatching thread you’re forcing them into a
    synchronous operation regardless of what they requested when they opened
    the file.

It’s a bad idea in storage in particular for two reasons:

  1. storage drivers (including the file systems) will dispatch I/O in
    completion routines or timers which are typically running at dispatch
    level. You can’t reliably block in your dispatch routine because you
    might be at dispatch level.

  2. when in the paging path you become part of a dependency chain where
    improper blocking can result in a deadlock. For example, say the lock
    you want is being held by a thread that’s trying to allocate memory,
    which cause the system to try and clear some paged memory out which
    causes a paging I/O to your device which blocks because of the lock
    you’re holding.

In the case of the floppy driver it never becomes part of that
dependency chain. In the case of a read-only volume #2 also probably
doesn’t apply (until someone decides to use your driver in an embedded
system that boots from a hibernation file and caches writes in a filter
above your driver). But #1 still applies and it’s generally very hard
to figure out how your driver will be used after you’ve sold the
hardware.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joe Black
Sent: Monday, February 16, 2004 11:30 AM
To: Windows System Software Devs Interest List
Subject: RE: RE: [ntdev] Storage drivers

On Mon, 2004-02-16 at 12:38, Mark Roddy wrote:

In general this is bad practice in any Read/Write dispatch routine,

forget about storage drivers. What exactly are you trying to do that

you believe requires you to do a synchronous wait?

Any hardware that interrupts as a response to its command could work
with that model (perhaps not should, but could). What if you have 3
command/interrupt phases that you have to go through to service a read
or write?

I know there are other ways to do this, one of which you outline below,
but I’m more curious about the principle.

The storage sample drivers I browsed do not block on read/write
requests.

In the current DDK, in floppy.c, FloppyReadWrite (the dispatch handler
for IRP_MJ_READ) calls ExAcquireFastMutex.

Joe Black

Concerned about your privacy? Follow this link to get FREE encrypted
email: https://www.hushmail.com/?l=2

Free, ultra-private instant messaging with Hush Messenger
https://www.hushmail.com/services.php?subloc=messenger&l=434

Promote security and make money with the Hushmail Affiliate Program:
https://www.hushmail.com/about.php?subloc=affiliate&l=427


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

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


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

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

Thanks for the help, Mark.

On Mon, 2004-02-16 at 13:40, Mark Roddy wrote:

Yes indeed I was afraid that it would be floppy. Please ignore just
about everything that the floppy driver does. You will be a better
kernel programmer for doing so :slight_smile:

That clarifies a lot.

Joe Black

Concerned about your privacy? Follow this link to get
FREE encrypted email: https://www.hushmail.com/?l=2

Free, ultra-private instant messaging with Hush Messenger
https://www.hushmail.com/services.php?subloc=messenger&l=434

Promote security and make money with the Hushmail Affiliate Program:
https://www.hushmail.com/about.php?subloc=affiliate&l=427

Since I have done a lot of work with the floppy driver I will chime in
with a couple of points. Forget any concept of the floppy driver being
part of what everyone else means by the terms ‘storage’ or ‘storage
stack’. The floppy driver has a couple of major problems with the
hardware that nothing can help. 1) The floppy controller can only
select and turn on the motor for one device at a time. I have tried
using plain DOS and dinging the ports directly without any success - the
hardware just turns on the first one selected and ignores the other
bits. 2) The hardware is fixed in location (ports and IRQ) and the
system DMA is not optional.

The floppy driver overcomes most of the problems by putting all requests
requiring access to the media into a queue serviced by a single worker
thread. Those requests that can be satisfied from information already
available in the driver are serviced immediately, but read & write are
always queued. With 2000, the port access was moved to FDC.SYS so that
floppy controller based tape backup units could be more easily serviced
without crashing the system when floppy.sys and another driver were
attempting to control the floppy controller. Another interesting
‘feature’ of the floppy driver is that when no control information is
seen on a piece of media, no attempt to read that media will succeed
until a media change is seen. A format can reset that flag, but
otherwise only removal and reinsertion of the media will get it to
actually try a read.

BTW, the floppy driver has stalls between some phases for specific
floppy controllers/drives. Other storage devices should avoid all of
these limitations since speed is more of a concern for them than the
floppy driver which has a channel that can only do about 330kbps
sustained transfer rate.

“Joe Black” wrote in message news:xxxxx@ntdev…
> On Mon, 2004-02-16 at 12:38, Mark Roddy wrote:
> > In general this is bad practice in any Read/Write dispatch routine,
>
> > forget about storage drivers. What exactly are you trying to do that
>
> > you believe requires you to do a synchronous wait?
>
> Any hardware that interrupts as a response to its command could work
> with that model (perhaps not should, but could). What if you have 3
> command/interrupt phases that you have to go through to service a read
> or write?
>
> I know there are other ways to do this, one of which you outline
below,
> but I’m more curious about the principle.
>
> > The storage sample drivers I browsed do not block on read/write
> > requests.
>
> In the current DDK, in floppy.c, FloppyReadWrite (the dispatch handler
> for IRP_MJ_READ) calls ExAcquireFastMutex.
>
> Joe Black
>
>
>
>
> Concerned about your privacy? Follow this link to get
> FREE encrypted email: https://www.hushmail.com/?l=2
>
> Free, ultra-private instant messaging with Hush Messenger
> https://www.hushmail.com/services.php?subloc=messenger&amp;l=434
>
> Promote security and make money with the Hushmail Affiliate Program:
> https://www.hushmail.com/about.php?subloc=affiliate&amp;l=427
>

On Mon, 16 Feb 2004 12:09:15 -0800 Jamey Kirby
wrote:
>The floppy uses a thread to process requests. The wait is done in
>the
>context of the thread (PASSIVE_LEVEL).

The first ExAcquireFastMutex() in the IRP_MJ_READ handler is before the
request is queued to the thread, FWIW. However, the offending mutex
lock could be eliminated.

Joe Black

Concerned about your privacy? Follow this link to get
FREE encrypted email: https://www.hushmail.com/?l=2

Free, ultra-private instant messaging with Hush Messenger
https://www.hushmail.com/services.php?subloc=messenger&amp;l=434

Promote security and make money with the Hushmail Affiliate Program:
https://www.hushmail.com/about.php?subloc=affiliate&amp;l=427