I am having an issue with getting a Storport Virtual Miniport driver to access a file in a path

I am having an issue with getting a Storport Virtual Miniport driver to access a file in a path. I am almost done with getting persistent file backing implemented into it. The issue is found in its usage of ZwCreateFile and/or the fact that it is trying to access the drive when it is not ready. How do I fix it? The code can be downloaded by going to Filebin | 88rf7M88pIDpMZwh.

I'm not sure what you're expecting us to say. If the drive isn't ready, then you have to wait for it to be ready. There is no magic back door.

How do I go about doing that in the code?

are you trying to access a file on a path that should be routed through the drive(s) that you are trying to handle? or on some other disk handled by a different controller?

divers generally don't access files for 'persistent backing'. So maybe your whole virtual drive is a file on a different device? Or maybe you are trying to store some kind of configuration data in a file - which is usually stored in the registry

  1. Then how do drivers like Phantom Drive, etc. work?
  2. The path is C:\image.img or C:\image.bin.

How do you know what C: maps to? That can change between boots. You need to use some lower-level methods to identify your drive, if you need to access the device at boot time. Are you backing files from a different drive?

I tried using /??/C:\test.bin. It didn't work.

That ought to be \??\C:\test.bin and as a string it is
"\\??\\C:\\test.bin".
Also, what error is returned?

And finally, it is unlikely anyone is going to click that link to download your code. Either copy the relevant code here or put it up on github.

so your goal is to mount a file as a disk. Similar to the way that you can mount a .ISO or .VHDX file?

The actual file is stored on some other volume (i.e. C:\ or D:) and file system (i.e. NTFS) and your driver will present a new disk device using the contents of that file as the sectors of that disk?

And presumably, your problem is that during a reboot, you are encountering an error when you try to access this path - this is where you get device not ready?

Assuming that the answer is yes to all of these questions, your problem is that you should not present your device so early in the boot sequence. There is a reason why the standard 'mount' functions in explorer don't persist after a reboot. But presumably you want yours to persist. For that to happen properly, you need to wait until the file system on the volume your image file resides on has been mounted before you enumerate your virtual disk

The code can be found at bus-filter-framework/WDKStorPortVirtualMiniport at implement-persistent-file-backing-retry-2 · Zero3K/bus-filter-framework · GitHub.

There are several different driver projects in there, and a couple of INF files. Which one is yours? It looks like there's code to implement a RAM disk, and a filter on top of it. The RAM disk is root enumerated, which means it might get started well before any drives become ready.

The code that needs looking at is in the WDKStorPortVirtualMiniport folder. The other driver isn't that problematic.