Drivers for Virtual devices

Hello,

Do drivers for virtual devices need to handle PnP ? I have a driver which
creates some virtual
devices when an appropriate IOCTL is sent to the control object.
So is there any real need to make this driver PnP ? In case it need to be a
PnP - how will
these virtual device objects be controlled by PnP manager since they are
created on the fly
and not in AddDevice() ?

Thanks.

The answer here depends on who is going to open these dynamically
created devices and how they are going to be notified of their arrival.
If these new devices are opened by the app which sent the IOCTL, there
is no need for pnp. If you want to use device interfaces as the
notification mechanism, you need pnp. If that is the case, you are
describing a bus driver. Each dynamic device is a new child. Look at
the ddk example toaster/busenum. You may want to consider making each
child a raw device, that way an FDO does not need to be loaded on it.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary Brown
Sent: Friday, February 11, 2005 8:15 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Drivers for Virtual devices

Hello,

Do drivers for virtual devices need to handle PnP ? I have a driver
which
creates some virtual
devices when an appropriate IOCTL is sent to the control object.
So is there any real need to make this driver PnP ? In case it need to
be a
PnP - how will
these virtual device objects be controlled by PnP manager since they are
created on the fly
and not in AddDevice() ?

Thanks.


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 answer here depends on who is going to open these dynamically

> created devices and how they are going to be notified of their arrival.
The application which will create the devices will come to know the
device names as a part of the IOCTL to create these devices. Once the
devices
are created, only the app be using those.

Thanks,
Gary.

“Doron Holan” wrote in message
news:xxxxx@ntdev…
The answer here depends on who is going to open these dynamically
created devices and how they are going to be notified of their arrival.
If these new devices are opened by the app which sent the IOCTL, there
is no need for pnp. If you want to use device interfaces as the
notification mechanism, you need pnp. If that is the case, you are
describing a bus driver. Each dynamic device is a new child. Look at
the ddk example toaster/busenum. You may want to consider making each
child a raw device, that way an FDO does not need to be loaded on it.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary Brown
Sent: Friday, February 11, 2005 8:15 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Drivers for Virtual devices

Hello,

Do drivers for virtual devices need to handle PnP ? I have a driver
which
creates some virtual
devices when an appropriate IOCTL is sent to the control object.
So is there any real need to make this driver PnP ? In case it need to
be a
PnP - how will
these virtual device objects be controlled by PnP manager since they are
created on the fly
and not in AddDevice() ?

Thanks.


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

OK. Next question. Why do you need separate device objects? You can
use the object namespace after your device name (it is passed to you in
the FilePath field of PFILE_OBJECT during IRP_MJ_CREATE) as a way to
distinguish between different “parts” of the base device object. You
can then allocate your own context and stuff it into FsContext and have
a per handle context.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary Brown
Sent: Friday, February 11, 2005 8:44 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Drivers for Virtual devices

> The answer here depends on who is going to open these dynamically
> created devices and how they are going to be notified of their
arrival.
The application which will create the devices will come to know the
device names as a part of the IOCTL to create these devices. Once the
devices
are created, only the app be using those.

Thanks,
Gary.

“Doron Holan” wrote in message
news:xxxxx@ntdev…
The answer here depends on who is going to open these dynamically
created devices and how they are going to be notified of their arrival.
If these new devices are opened by the app which sent the IOCTL, there
is no need for pnp. If you want to use device interfaces as the
notification mechanism, you need pnp. If that is the case, you are
describing a bus driver. Each dynamic device is a new child. Look at
the ddk example toaster/busenum. You may want to consider making each
child a raw device, that way an FDO does not need to be loaded on it.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary Brown
Sent: Friday, February 11, 2005 8:15 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Drivers for Virtual devices

Hello,

Do drivers for virtual devices need to handle PnP ? I have a driver
which
creates some virtual
devices when an appropriate IOCTL is sent to the control object.
So is there any real need to make this driver PnP ? In case it need to
be a
PnP - how will
these virtual device objects be controlled by PnP manager since they are
created on the fly
and not in AddDevice() ?

Thanks.


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@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Actually only one device is created per IOCTL call and not multiple
as I had incorrectly mentioned earlier. Sorry about that.

This is a virtual disk driver which uses a file as a backing store. It
accepts
IOCTL’s to mount the drive OR dismount one. Once a virtual volume
is created, the app will use it and when done will dismount it. Multiple
virtual drives are supported.

One more question -
When dismounting a virtual volume, how do I make sure that the volume
is not in use ? That device could be serving a read/write request…

Thanks

“Doron Holan” wrote in message
news:xxxxx@ntdev…
OK. Next question. Why do you need separate device objects? You can
use the object namespace after your device name (it is passed to you in
the FilePath field of PFILE_OBJECT during IRP_MJ_CREATE) as a way to
distinguish between different “parts” of the base device object. You
can then allocate your own context and stuff it into FsContext and have
a per handle context.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary Brown
Sent: Friday, February 11, 2005 8:44 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Drivers for Virtual devices

>> The answer here depends on who is going to open these dynamically
>> created devices and how they are going to be notified of their
arrival.
The application which will create the devices will come to know the
device names as a part of the IOCTL to create these devices. Once the
devices
are created, only the app be using those.

Thanks,
Gary.

“Doron Holan” wrote in message
news:xxxxx@ntdev…
The answer here depends on who is going to open these dynamically
created devices and how they are going to be notified of their arrival.
If these new devices are opened by the app which sent the IOCTL, there
is no need for pnp. If you want to use device interfaces as the
notification mechanism, you need pnp. If that is the case, you are
describing a bus driver. Each dynamic device is a new child. Look at
the ddk example toaster/busenum. You may want to consider making each
child a raw device, that way an FDO does not need to be loaded on it.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary Brown
Sent: Friday, February 11, 2005 8:15 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Drivers for Virtual devices

Hello,

Do drivers for virtual devices need to handle PnP ? I have a driver
which
creates some virtual
devices when an appropriate IOCTL is sent to the control object.
So is there any real need to make this driver PnP ? In case it need to
be a
PnP - how will
these virtual device objects be controlled by PnP manager since they are
created on the fly
and not in AddDevice() ?

Thanks.


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@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Gary Brown wrote:

Actually only one device is created per IOCTL call and not multiple
as I had incorrectly mentioned earlier. Sorry about that.

This is a virtual disk driver which uses a file as a backing store. It
accepts
IOCTL’s to mount the drive OR dismount one. Once a virtual volume
is created, the app will use it and when done will dismount it. Multiple
virtual drives are supported.

One more question -
When dismounting a virtual volume, how do I make sure that the volume
is not in use ? That device could be serving a read/write request…

Walter Oney’s book describes a simple method for this. Add a counter to
your device context. Add functions called LockDevice and UnlockDevice
that increment and decrement the counter (using the Interlocked APIs).
When the device is loaded, and at the beginning of every IRP, lock the
device. When the IRP is done, unlock the device. When the count goes
to zero, Unlock fires an event.

Now, your close handler can undo the very first lock, look at the use
count, and use KeWaitForSingleObject to wait for the event.

First, some good functionality - like device interfaces - requires a PDO,
and thus PnP.
Second, the virtual device is often implemented as root-enumerated - thus,
PnP.

PnP and POWER IRPs are only sent to the stacks with a PDO at bottom (well,
POWER also sent to FSDs IIRC). So, if you have no PDO but just a device created
by IoCreateDevice, then forget about PnP handling - you do not need it.

Device object becomes a PDO if either:
a) it was reported to PnP by its parent in the parent’s response to
MN_DEVICE_RELATIONS/BusRelations. Needless to say that the parent must be a PnP
device too, even if it is system-supplied “root parent”.
b) it was created by IoReportDetectedDevice.

Calling IoReportDetectedDevice with most parameters NULLs has its good
side. It allows your standalone device object to be a PDO and thus carry device
interfaces.

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

----- Original Message -----
From: “Gary Brown”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Friday, February 11, 2005 7:15 PM
Subject: [ntdev] Drivers for Virtual devices

> Hello,
>
> Do drivers for virtual devices need to handle PnP ? I have a driver which
> creates some virtual
> devices when an appropriate IOCTL is sent to the control object.
> So is there any real need to make this driver PnP ? In case it need to be a
> PnP - how will
> these virtual device objects be controlled by PnP manager since they are
> created on the fly
> and not in AddDevice() ?
>
> Thanks.
>
>
>
> —
> 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

You cannot do this reliably, at least on NT4 (on w2k+, you can use PnP
suicide technique by IoInvalidateDeviceState).

On NT4, never delete disk device objects. There is no BSOD-safe way of
doing this.

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

----- Original Message -----
From: “Gary Brown”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Friday, February 11, 2005 8:32 PM
Subject: Re:[ntdev] Drivers for Virtual devices

> Actually only one device is created per IOCTL call and not multiple
> as I had incorrectly mentioned earlier. Sorry about that.
>
> This is a virtual disk driver which uses a file as a backing store. It
> accepts
> IOCTL’s to mount the drive OR dismount one. Once a virtual volume
> is created, the app will use it and when done will dismount it. Multiple
> virtual drives are supported.
>
> One more question -
> When dismounting a virtual volume, how do I make sure that the volume
> is not in use ? That device could be serving a read/write request…
>
> Thanks
>
>
> “Doron Holan” wrote in message
> news:xxxxx@ntdev…
> OK. Next question. Why do you need separate device objects? You can
> use the object namespace after your device name (it is passed to you in
> the FilePath field of PFILE_OBJECT during IRP_MJ_CREATE) as a way to
> distinguish between different “parts” of the base device object. You
> can then allocate your own context and stuff it into FsContext and have
> a per handle context.
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Gary Brown
> Sent: Friday, February 11, 2005 8:44 AM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] Drivers for Virtual devices
>
> >> The answer here depends on who is going to open these dynamically
> >> created devices and how they are going to be notified of their
> arrival.
> The application which will create the devices will come to know the
> device names as a part of the IOCTL to create these devices. Once the
> devices
> are created, only the app be using those.
>
> Thanks,
> Gary.
>
>
> “Doron Holan” wrote in message
> news:xxxxx@ntdev…
> The answer here depends on who is going to open these dynamically
> created devices and how they are going to be notified of their arrival.
> If these new devices are opened by the app which sent the IOCTL, there
> is no need for pnp. If you want to use device interfaces as the
> notification mechanism, you need pnp. If that is the case, you are
> describing a bus driver. Each dynamic device is a new child. Look at
> the ddk example toaster/busenum. You may want to consider making each
> child a raw device, that way an FDO does not need to be loaded on it.
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Gary Brown
> Sent: Friday, February 11, 2005 8:15 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] Drivers for Virtual devices
>
> Hello,
>
> Do drivers for virtual devices need to handle PnP ? I have a driver
> which
> creates some virtual
> devices when an appropriate IOCTL is sent to the control object.
> So is there any real need to make this driver PnP ? In case it need to
> be a
> PnP - how will
> these virtual device objects be controlled by PnP manager since they are
> created on the fly
> and not in AddDevice() ?
>
> Thanks.
>
>
>
> —
> 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@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

> ----------

From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Maxim S. Shatskih[SMTP:xxxxx@storagecraft.com]
Reply To: Windows System Software Devs Interest List
Sent: Friday, February 11, 2005 10:58 PM
To: Windows System Software Devs Interest List
Subject: Re: Re:[ntdev] Drivers for Virtual devices

On NT4, never delete disk device objects. There is no BSOD-safe way of
doing this.

Really? Our driver first dismounts virtual drive (using FSCTLs) and if successful, fails all new requests for this device. Device is deleted when reference count becomes zero. It can takes ages, sometimes, and a thread is used to check dismounted devices in regular interval. What is wrong with it? We use this approach about 8 years and never had a BSOD.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

Thanks for the replies so far.

You cannot do this reliably, at least on NT4 (on w2k+, you can use PnP
suicide technique by IoInvalidateDeviceState).

This means that I’ll have to use PnP :frowning:

On NT4, never delete disk device objects. There is no BSOD-safe way of
doing this.

Isnt it that every device has a reference count and will be deleted only
when
the reference count reaches 0 ? DDK for IoDeleteDevice() says that device
will
not be deleted until reference count reaches 0. So if the device is deleted
when
there are no references could still cause isses ?

Thanks,
Gary.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
> You cannot do this reliably, at least on NT4 (on w2k+, you can use PnP
> suicide technique by IoInvalidateDeviceState).
>
> On NT4, never delete disk device objects. There is no BSOD-safe way of
> doing this.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From: “Gary Brown”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Friday, February 11, 2005 8:32 PM
> Subject: Re:[ntdev] Drivers for Virtual devices
>
>
> > Actually only one device is created per IOCTL call and not multiple
> > as I had incorrectly mentioned earlier. Sorry about that.
> >
> > This is a virtual disk driver which uses a file as a backing store. It
> > accepts
> > IOCTL’s to mount the drive OR dismount one. Once a virtual volume
> > is created, the app will use it and when done will dismount it. Multiple
> > virtual drives are supported.
> >
> > One more question -
> > When dismounting a virtual volume, how do I make sure that the volume
> > is not in use ? That device could be serving a read/write request…
> >
> > Thanks
> >
> >
> > “Doron Holan” wrote in message
> > news:xxxxx@ntdev…
> > OK. Next question. Why do you need separate device objects? You can
> > use the object namespace after your device name (it is passed to you in
> > the FilePath field of PFILE_OBJECT during IRP_MJ_CREATE) as a way to
> > distinguish between different “parts” of the base device object. You
> > can then allocate your own context and stuff it into FsContext and have
> > a per handle context.
> >
> > d
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Gary Brown
> > Sent: Friday, February 11, 2005 8:44 AM
> > To: Windows System Software Devs Interest List
> > Subject: Re:[ntdev] Drivers for Virtual devices
> >
> > >> The answer here depends on who is going to open these dynamically
> > >> created devices and how they are going to be notified of their
> > arrival.
> > The application which will create the devices will come to know the
> > device names as a part of the IOCTL to create these devices. Once the
> > devices
> > are created, only the app be using those.
> >
> > Thanks,
> > Gary.
> >
> >
> > “Doron Holan” wrote in message
> > news:xxxxx@ntdev…
> > The answer here depends on who is going to open these dynamically
> > created devices and how they are going to be notified of their arrival.
> > If these new devices are opened by the app which sent the IOCTL, there
> > is no need for pnp. If you want to use device interfaces as the
> > notification mechanism, you need pnp. If that is the case, you are
> > describing a bus driver. Each dynamic device is a new child. Look at
> > the ddk example toaster/busenum. You may want to consider making each
> > child a raw device, that way an FDO does not need to be loaded on it.
> >
> > d
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Gary Brown
> > Sent: Friday, February 11, 2005 8:15 AM
> > To: Windows System Software Devs Interest List
> > Subject: [ntdev] Drivers for Virtual devices
> >
> > Hello,
> >
> > Do drivers for virtual devices need to handle PnP ? I have a driver
> > which
> > creates some virtual
> > devices when an appropriate IOCTL is sent to the control object.
> > So is there any real need to make this driver PnP ? In case it need to
> > be a
> > PnP - how will
> > these virtual device objects be controlled by PnP manager since they are
> > created on the fly
> > and not in AddDevice() ?
> >
> > Thanks.
> >
> >
> >
> > —
> > 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@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
>
>