Dynamic Bus Driver

Hi guys,

I have a conceptual question about bus drivers. Again.

I have this bus driver here, which builds a virtual bus and creates a
certain number of devices on it. I would like to be able to remove
those devices on the fly. What would be the correct way to remove those
PDOs?

Should I invalidate my BusRelations first?
Should I just call IoDeleteDevice on the device I want to remove?
Should I send IRP_REMOVE_DEVICE through the PDO device stack?

I have found the bus driver article that was in NT Insider some time
ago, but it doesn’t say a word about removing the devices.

Any reply appreciated! TIA
Mathieu Routhier

You should invalidate your BusRelations and let PNP tell your driver
when it’s okay to delete the device.

You should not call IoDeleteDevice on a device you have reported to PNP
until you get a remove request.

You should not send PNP requests to your own stack in an effort to
destroy the device.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mathieu Routhier
Sent: Thursday, May 27, 2004 1:48 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Dynamic Bus Driver

Hi guys,

I have a conceptual question about bus drivers. Again.

I have this bus driver here, which builds a virtual bus and creates a
certain number of devices on it. I would like to be able to remove
those devices on the fly. What would be the correct way to remove those
PDOs?

Should I invalidate my BusRelations first?
Should I just call IoDeleteDevice on the device I want to remove?
Should I send IRP_REMOVE_DEVICE through the PDO device stack?

I have found the bus driver article that was in NT Insider some time
ago, but it doesn’t say a word about removing the devices.

Any reply appreciated! TIA
Mathieu Routhier


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

Furthermore, when you get a remove device on your PDO you to keep track
of whether you reported the PDO as missing to PNP. If you did report it
as missing, you delete the device object. If you did not report it as
missing, you keep the device object around and make that you can handle
getting a start irp or another remove device irp. You can get a remove
device by going into device manager and disabling (or uninstalling as
well) the child device. In essence, turn on the driver verifier and
test your code. The logic here is quite complex and you need to
absolutely get it right.

D

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Peter Wieland
Sent: Friday, May 28, 2004 4:59 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Dynamic Bus Driver

You should invalidate your BusRelations and let PNP tell your driver
when it’s okay to delete the device.

You should not call IoDeleteDevice on a device you have reported to PNP
until you get a remove request.

You should not send PNP requests to your own stack in an effort to
destroy the device.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mathieu Routhier
Sent: Thursday, May 27, 2004 1:48 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Dynamic Bus Driver

Hi guys,

I have a conceptual question about bus drivers. Again.

I have this bus driver here, which builds a virtual bus and creates a
certain number of devices on it. I would like to be able to remove
those devices on the fly. What would be the correct way to remove those
PDOs?

Should I invalidate my BusRelations first?
Should I just call IoDeleteDevice on the device I want to remove?
Should I send IRP_REMOVE_DEVICE through the PDO device stack?

I have found the bus driver article that was in NT Insider some time
ago, but it doesn’t say a word about removing the devices.

Any reply appreciated! TIA
Mathieu Routhier


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

> those devices on the fly. What would be the correct way to remove those

PDOs?

  • mark them as “lost” your own way and call
    IoInvalidateDeviceRelations(BusRelations)
  • the MN_QUERY_RELATIONS path must not return the “lost” PDOs
  • the MN_REMOVE_DEVICE path must destroy the “lost” PDOs

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

Peter, Doron and Maxim,

thanks to you, it now works perfectly! It’s amazing in the kernel how
many exceptions and special cases there are which need to be perfectly
handled. I’m glad to see there are knowledgeable people in here :slight_smile:

Mat

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, May 27, 2004 6:10 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Dynamic Bus Driver

Furthermore, when you get a remove device on your PDO you to keep track
of whether you reported the PDO as missing to PNP. If you did report it
as missing, you delete the device object. If you did not report it as
missing, you keep the device object around and make that you can handle
getting a start irp or another remove device irp. You can get a remove
device by going into device manager and disabling (or uninstalling as
well) the child device. In essence, turn on the driver verifier and
test your code. The logic here is quite complex and you need to
absolutely get it right.

D

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Peter Wieland
Sent: Friday, May 28, 2004 4:59 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Dynamic Bus Driver

You should invalidate your BusRelations and let PNP tell your driver
when it’s okay to delete the device.

You should not call IoDeleteDevice on a device you have reported to PNP
until you get a remove request.

You should not send PNP requests to your own stack in an effort to
destroy the device.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mathieu Routhier
Sent: Thursday, May 27, 2004 1:48 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Dynamic Bus Driver

Hi guys,

I have a conceptual question about bus drivers. Again.

I have this bus driver here, which builds a virtual bus and creates a
certain number of devices on it. I would like to be able to remove
those devices on the fly. What would be the correct way to remove those
PDOs?

Should I invalidate my BusRelations first?
Should I just call IoDeleteDevice on the device I want to remove?
Should I send IRP_REMOVE_DEVICE through the PDO device stack?

I have found the bus driver article that was in NT Insider some time
ago, but it doesn’t say a word about removing the devices.

Any reply appreciated! TIA
Mathieu Routhier


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

> thanks to you, it now works perfectly! It’s amazing in the kernel how

many exceptions and special cases

This is not an exception. If you will try to imagine the whole PnP picture -
then you will easily understand why it is so.

REMOVE IRP is sent down the stack a) on surprise removal b) on Enable/Disable
from Device Manager of DEVCON (SetupDiChangeState call).

In the first case, there is no more physical device in the machine, so, it is
correct to forget everything related to it, including the PDO.

In the second case, the structures necessary to start the device back must be
retained. They include the PDO at least.

Now what is “surprise removal”. This is a situation in PnP Manager when the
device disappears. This means - it was reported by some bus driver in previous
relations query, and not reported in the last relations query.

Thus the DDK’s rule: the PDO REMOVE path must destroy the PDO only if it was
not reported in the last relations.

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