LTRData / ImDisk

ImDisk Virtual Disk Driver
GNU General Public License v2.0
426 stars 72 forks source link

Unable to unmount: access denied #10

Closed nohopestage closed 2 years ago

nohopestage commented 2 years ago

When I access the mounted volume and then try to unmount it, sometimes it says access denied and I'm unable to do so, even though I'm not using the volume anymore. The only option in such a case is to restart my computer. What could be the problem?

LTRData commented 2 years ago

Not sure really, does it work if you try -D switch instead of -d at the command line? Do you get other error messages if you try that? Could you try with Process Explorer and see if there are any processes holding open handles to the volume when this happens? (Search both for ImDisk and the drive letter.) Chances are that something like an antivirus application or similar is holding something open for a longer time then expected.

nohopestage commented 2 years ago

It did work with -D, which I overlooked, and I didn't get any error messages with that. I've tried -R, but that didn't really remove the VD. It was still visible in both explorer (though I couldn't access it anymore) and imdisk -l. I couldn't find any processes holding open handles to the volume. Should I always use -D? Thanks for the reply

LTRData commented 2 years ago

Are you sure that you are running the command with administrative privilegies? If you are running as a regular user, it fails to safely dismount the file system and this causes exactly this behaviour.

Btw, -R is only meant for "emergency" scenarios and should not normally be used if there are other ways available.

nohopestage commented 2 years ago

I did try running it with as both regular user and administrator. Both resulted in the same output:

Flushing file buffers...
Locking volume...
E: Access is denied.

Btw, as I've just found out there is a .NET library, I tried unmounting the VD that way, which gave me the same error. Is there a way to use -D in RemoveDevice()? If not, could such an option be added as an optional bool parameter?

LTRData commented 2 years ago

I don't remember right now, I have not used it for many years. I can check later and come back!

LTRData commented 2 years ago

It appears that you could set ImDiskAPI.APIFlags = UnsafeNativeMethods.ImDiskAPIFlags.ForceDismount before you call RemoveDevice.

nohopestage commented 2 years ago

That way it does remove the device from explorer. However, the device is still listed in -l, and when I try to detach it again, it says:

Error opening device: The device has been removed.

That prevents ImDisk from uninstalling. Device disappears from both explorer and -l when I detach it with -D.

LTRData commented 2 years ago

Yes, that is expected. If the volume is in use by something and cannot be safely dismounted, when you force it to dismount it needs to stay present until the last reference to it goes away. The ImDisk driver will repeatedly check and see if it is still in use and if not, it will eventually delete the device object and after that the driver can be uninstalled.