How to unload and reload a WDM driver?

Hi, all

We have a volume driver who atteched to lower disk device objects(got by IoRegisterPlugPlayNotification()) and create volume device objects for filesystem driver to mount.

Our requirement here is:
R1.This volume driver should be notified when lower disk device changed
R2.This volume driver can be unload and reload controled by an user process.

To fullfill R1, we need to support IRP_MJ_PNP, so it’s a WDM driver.
Recently this driver is installed by INF file and will be automatically load by system(Start=1).

So how to unload and reload(any times) a WDM driver in user space?

Thanks in advance

>IoRegisterPlugPlayNotification()) and create volume device objects for filesystem driver to mount.

Are these ones the PDOs?

If yes - then you’re a PnP driver, and must have the root-enumerated root device.

To unload the PnP driver, disable all its device objects.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

Why does supporting IoRegisterPlugPlayNotification, and being informed of changes in the lower disk device, make it necessary to write a WDM driver.

You *never* want to write a WDM driver (well, at least *I* don’t and I had about 15 years of experience doing it) when you can write a KMDF driver.

Peter
OSR

hello,

you havent mentioned how your driver is loaded? is it on the root bus by
any chance? are you acting as a volume manager? if you are, then the only
way to do it would be to destroy all the volume objects, but doing so would
mean that you require a reboot, since your OS will also be on a volume.

if i may suggest an alternate design, why dont you have an NDIS or filter
manager like design, where you have a stub driver loaded, and all the
business logic in another driver which would be loaded and controlled by
this stub. Very similar to filtermanager’s design. This would be difficult
to design perfectly and write, but once done could solve your reboot issue,
unless u find a bug in the stub driver itself.

On Fri, May 31, 2013 at 8:03 AM, wrote:

> Hi, all
>
> We have a volume driver who atteched to lower disk device objects(got by
> IoRegisterPlugPlayNotification()) and create volume device objects for
> filesystem driver to mount.
>
> Our requirement here is:
> R1.This volume driver should be notified when lower disk device changed
> R2.This volume driver can be unload and reload controled by an user
> process.
>
> To fullfill R1, we need to support IRP_MJ_PNP, so it’s a WDM driver.
> Recently this driver is installed by INF file and will be automatically
> load by system(Start=1).
>
> So how to unload and reload(any times) a WDM driver in user space?
>
> Thanks in advance
>
>
> —
> NTDEV is sponsored by OSR
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>



- ab

Thanks for your reply.

@Maxim
On notified by IoRegisterPlugPlayNotification(), I created filter devices attached to the lower disk devicies, and then create volome objects who will send IRPs to the filter devices when receiving from the upper.
I’m not quiet sure whether they are PDOs or not? How to confirm it? Thanks

disable all its device objects
You mean like rightclick to disable a device in Device Manager?

@Peter
Hi, Peter, When I say it’s a WDM driver, I just means that it’s not a *legacy* driver who can be stoped and unload by SCM.

@amitr0

Thank you.

Currently my volume driver is load by system on boot time.,but it’s nobody’s upper filter.
I don’t think it is “on the root bus” but it’s desired to act like a simplified “volume manager”, it’s not like OS’s volume manager.
Just as I said upper, we create filter device objects on lower disk device objects, and create volume device objects on demand. Later upper file system driver will mount on it.

In Unload routine, I detach and delete all the device objects I’ve created, but just don’t know how to trigger Unload.(If it’s a legacy driver, we use SCM services)

Currently the driver’s design can not be changed because it’s the first version and all the functions are ok except the “unload and reload driver”, but I will spent my time to learn the filtermanager’s like design and maybe use it in later version.

On the what bus is it on, either it is a software only PnP device or
else it attaches to a PDO of a hardware based bus. You talk about a
lower disk, so somehow you are connecting to the disk.

If you have created a volume device object the system will grab it, even
if there is not a known file system on the image, the system uses the
raw file system to grab the device object. This is probably why your
drivers unload routine is not being called, there are references to the
device objects it creates, which means it can’t be unloaded.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

fanggai318wy@163.com” wrote in message
news:xxxxx@ntdev:

> @amitr0
>
> Thank you.
>
> Currently my volume driver is load by system on boot time.,but it’s nobody’s upper filter.
> I don’t think it is “on the root bus” but it’s desired to act like a simplified “volume manager”, it’s not like OS’s volume manager.
> Just as I said upper, we create filter device objects on lower disk device objects, and create volume device objects on demand. Later upper file system driver will mount on it.
>
> In Unload routine, I detach and delete all the device objects I’ve created, but just don’t know how to trigger Unload.(If it’s a legacy driver, we use SCM services)
>
> Currently the driver’s design can not be changed because it’s the first version and all the functions are ok except the “unload and reload driver”, but I will spent my time to learn the filtermanager’s like design and maybe use it in later version.

Hi, Don

I think it’s a software only PnP device.
Following is the info get from devicetree:
my_volume is the driver I want to unload and reload
–1).before unmount–
DRV \Driver\my_volume
DEV \Device{x-x-x-x}
FS File System(unnamed) - \FileSystem\MyFsd
ATT Attached:(unnamed) - \FileSystem\FltMgr
DEV \Device{x-x-x-x}

–2).after unmount–
DRV \Driver\my_volume
DEV \Device{x-x-x-x}
DEV \Device{x-x-x-x}

So it seems that there is no extra reference by the raw file system.
And my question is, since can’t use SCM, how to trigger the Unload routine? Send an IOCTL to detach and delete all devobjs and the Unload routine will be called automatically?

You talk about a lower disk, so somehow you are connecting to the disk.
Using the SymbolicLinkName in DEVICE_INTERFACE_CHANGE_NOTIFICATION, I get the lower [PhysicalDeviceObject], on which I create a [FilterDeviceObject].
Then I create a [VolumeDeviceObject], who has a internal connection with the [FilterDeviceObject].
When receiving any read/write related IRPs, the [VolumeDeviceObject] send it to the [FilterDeviceObject].
Is these information enough?