Restart specific disk device without restarting Windows to apply changes

Hi Experts!

I have been working on DiskDrive KMDF UpperFilter Driver.
Let's say we installed the driver then restarted the system to apply changes but, I have been wondering if it is possible to force windows to re evaluate a specific disk device to apply changes on runtime. Because I have case in which I am using IOCTLs, It reflects or update in Disk Management but not in Explorer, each time to apply changes I have to restart the whole system.

Any suggestions that might help?

Since you are asking about working on a disk filter, you are probably asking about techniques to reduce the number of reboots needed during your debugging time?

When you say you are using IOCTLs, which ones and for what purpose?

Somehow, you have to restart the device. With some device classes, that can be done from Device Manager (and hence with APIs). With other device classes, the only way to restart the device is to reboot the computer.

1 Like

Thank you for the reply, When I Intercept IOCTL_DISK_IS_WRITABLE and send the request as STATUS_MEDIA_WRITE_PROTECTED for particular device it changes to Read Only in the device manager but not in the File Explorer. And after I restart the whole system then it takes effect. I mean It shows read only for the disk in File Explorer.

Hello sir!
Any suggestions for APIs? I tried Setup Api'@s SetUpDiRestartDevice.

If a volume on the disk has a mounted filesystem and is not considered 'removable', then you are not going to be able to restart the device.

1 Like

Thank you for the information, I will try and get back!

Hello Mark!
Just as you said, I tried using devcon to restart Removable disk device, It worked. But for other devices, Reboot is required. Is there any way to achieve it? Maybe sending specific IOCTL to PhysicalDrive?

I saw a tool doing what I want. Somehow that toll closed all the handles for the particular disk, How?

basically no. Your filter has to be active before other components access the disk.

Thanks for the response! will try for a while!

Hello @Mark_Roddy!
when dismounted the volume of the particular disk and mounted it again then it closed all the open handles and the properties which I wanted to update, got updated?!
But I am afraid that I am going in wrong way...
will dismounting and remounting the disk will give me a problem?
Any suggestions?

Try doing this on the system volume. You can't. Also a 'disk' contains zero or more 'partitions' each of which can be associated with zero or one 'volumes'. To remove a disk you have to unmount all the mounted volumes associated with that disk.

Hello @Mark_Roddy sir!
can you please take a look at it and tell if you have any idea or suggestion for it?
SetupDiRestartDevices : This function restarts a specified device or, if necessary, restarts all devices operated by the same function and filter drivers that operate the specified device. It’s used to restart a device after a configuration change or when a device’s state needs to be updated.
I am trying this for now!

My suggestion is literally RTFM.

  • If a system restart is necessary to start a device, SetupDiRestartDevices sets the DI_NEEDREBOOT flag in the Flags member of the SP_DEVINSTALL_PARAMETER structure that is associated with the device information element and sets the problem code for the device to CM_PROB_NEED_RESTART.

Without trying to be rude, think about what removable means to the OS. And non-removable.

If you are trying to reduce your debug time, why not just use a removable disk? There are lots of kinds to choose from