Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


How to identify a disk in Windows kernel driver?

buxingzhe_nealbuxingzhe_neal Member Posts: 4
edited July 22 in NTDEV

Hi professionals, I'm a newer to windows kernel driver development and I'm working on a disk filter driver which is a boot driver.
Firstly let me try describing the problem as I could. For the driver, in 'DriverEntry' routine, the driver just loads its parameters from registry and initializes the driver entry points, at the end registers a routine to trigger "BootDriverReInitialization" action. The critical filtering function stack is setup in "BootDriverReInitialization" routine. In order to make the parameters to be configurated for different VMs, I'd like to read the settings from file on a specific small VHD disk created by ourselves, and override the default values that read from registry earlier. Then we can setup filtering function with different settings per VM(shared OS image with same registry settings). The job that I have to do next is to identify the disk, read the configuration from this disk and override the default settings with new values.

Here are my questions:
1. Is it safe to load configuration from disk file at that point?
2. How can I identify the VHD disk in a safe and simpler way but not to enumerate all disks by checking if the specific config file exists on the disk?

Any help or suggestion would be appreciated.

Post edited by Peter_Viscarola_(OSR) on

Comments

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 9,025

    (Moved to appropriate location)

    Peter Viscarola
    OSR
    @OSRDrivers

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,373

    If the VHD is not located on the disk you are filtering, then I believe there are no guarantees of disk order. It's somewhat problematic to have the driver for disk A assume the presence of and rely on disk B. Even if it the drive you are filtering, how are you going to mount the VHD?

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • MBond2MBond2 Member Posts: 477

    the short answer is no, you cannot store your configuration anywhere except in the designated registry key

  • buxingzhe_nealbuxingzhe_neal Member Posts: 4
    edited July 25

    @Tim_Roberts said:
    If the VHD is not located on the disk you are filtering, then I believe there are no guarantees of disk order. It's somewhat problematic to have the driver for disk A assume the presence of and rely on disk B. Even if it the drive you are filtering, how are you going to mount the VHD?

    One thing is that the VMs are created by Hypervisor or Azure platform with the same OS image and a small VHD is attached to each VM as a data disk as well. The disk we're filtering is not the VHD disk, generally the OS disk. As I know, 'BootDriverReInitialization' is entered when all devices have been enumerated and started. Now in this reinitialization routine, we can read the configure file in the right disk with symbolic link like '\Device\Harddisk{1,2,3}\Partition1\configfile.ini'. But we worry if we access the disks like this, it will change the disk initialization order and make something unexpected.

  • buxingzhe_nealbuxingzhe_neal Member Posts: 4

    @MBond2 said:
    the short answer is no, you cannot store your configuration anywhere except in the designated registry key

    Thanks for your answer, then any way to make the driver dynamically configured?

  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,559

    Of course you can store config data on your own (vhd) disk attached to the vm. I know of at least two commercial products that do this and they are deployed all over the planet. As you noted, you can just enumerate all the disks and look for your config data signature. Accessing the disk is not going to change the initialization order. It has to have been initialized in order to access it.

    If you have an immutable boot/system disk (for example it gets reset on each boot) the registry is obviously out as a way to customize each instance.

  • buxingzhe_nealbuxingzhe_neal Member Posts: 4

    @Mark_Roddy said:
    Of course you can store config data on your own (vhd) disk attached to the vm. I know of at least two commercial products that do this and they are deployed all over the planet. As you noted, you can just enumerate all the disks and look for your config data signature. Accessing the disk is not going to change the initialization order. It has to have been initialized in order to access it.

    If you have an immutable boot/system disk (for example it gets reset on each boot) the registry is obviously out as a way to customize each instance.

    Thanks for your answer. Yes, you're right, we just have an immutable system disk and it gets reset on each boot.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 12 September 2022 Live, Online
Internals & Software Drivers 23 October 2022 Live, Online
Kernel Debugging 14 November 2022 Live, Online
Developing Minifilters 5 December 2022 Live, Online