How to find hard disk device like: device\harddisk0\dr0 and so on...

Hello,

I’m trying to figure where to get the info to get the disks that are connected in a format of Device\HardDisk0\DR0, Device\HardDisk1\DR2 and so on…

It is the same as in DeviceTree.

Where do I dig this info from?

Thanks,

Connected in what way?

Please clarify your question.

Peter
OSR
@OSRDrivers

Enumerate all bearers of the Disk PnP devinterface using SetupDi calls.

For each, call IOCTL_STORAGE_GET_DEVICE_NUMBER

Then build the strings of Device\HardDisk%d\DR0

Or, better, avoid the latter names altogether. They are not persistent across boots and across USB flash drives plug/unplug, while the PnP names are persistent (with the only exception of USB flash drives without serial numbers, but I never ever saw one).


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

wrote in message news:xxxxx@ntdev…
> Hello,
>
> I’m trying to figure where to get the info to get the disks that are connected in a format of Device\HardDisk0\DR0, Device\HardDisk1\DR2 and so on…
>
> It is the same as in DeviceTree.
>
> Where do I dig this info from?
>
> Thanks,
>
>
>

Hello Peter and Shatskih and thanks for your comments

Peter,
The disks are connected via SATA. I need to get a list of them as it shows on DeviceTree.

Shatskih,
Some of the times it shows: Device\HardDisk1\DR2 . So, writing DR0 will not fit all cases.

I wonder where DeviceTree gets this info from?

Thanks,

Eli

in windos oses disk enumerations comes from disk.sys. disk.sys reads bios information with bios assembler codes or bios interrupts.in programming user side @"SYSTEM\CurrentControlSet\Services\Disk\Enum has enumeration values.

Disk.sys never ever calls BIOS assembler or BIOS interrupts.

The source is provided with the WDK

wrote in message news:xxxxx@ntdev…
> in windos oses disk enumerations comes from disk.sys. disk.sys reads bios information with bios assembler codes or bios interrupts.in programming user side @"SYSTEM\CurrentControlSet\Services\Disk\Enum has enumeration values.
>

Negative Mr. Kucuk. That’s the second time you’ve posted here, and the second time you’ve given bad information.

Please try to restrict your comments to those topics about which you actually know something.

If you cannot manage that level of discipline, we can help you by putting you on moderation so we can review and approve all your posts. You’ll be the first and only person ever put on moderation on the list, by the way.

Peter
OSR
@OSRDrivers

>Some of the times it shows: Device\HardDisk1\DR2 . So, writing DR0 will not fit all cases. I wonder where DeviceTree gets this info from?

Use the SysInternal’s WinObj utility. Select the \Device\HardDisk1 directory and you will see if DR2 actually exists it that directory. To me, it should be DR1, but I may be wrong.

Hi Ntdev Geek,

I need to get the information programmatically.

Any snippet will be helpful.

Thanks,

> Some of the times it shows: Device\HardDisk1\DR2 . So, writing DR0 will not fit all cases.

Forget these obsolete legacy names, which are BTW not persistent across reboots and across insertion of USB flash drives.

Use PnP interfaces and SetupUi APIs instead to find disks, partitions and volumes.


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

Hi Maxim,

I need this format because I hook a filter that needs to get it’s target name in the format of \device\harddisk\DR .

Thanks again for your help,

Eli

> I need this format because I hook a filter that needs to get it’s target name in the format of

The normal disk filters are PnP ones, and they are hooked irrespective to the name.


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

Hi,

I will need to load and unload upon request. Can you recommend a snippet to hook to \.\physicaldrive?

Thanks,

> I will need to load and unload upon request.

You cannot.

You can only switch your filter to no-op mode.


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

Trust Mr. Shatskih, the namespace you refer to is deprecated.

From user-mode:

  1. SetupDiGetClassDevs will return a handle to a set of devices, use GUID_DEVINTERFACE_DISK to restrict the set to hard disk storage devices.

Handle = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);

  1. Call SetupDiEnumDeviceInterfaces to get each device interface and call SetupDiGetDeviceInterfaceDetail to get the interface detail which is the path (symbolic link) to be passed to CreateFile to open the underlying device.

If you use Visual Studio and WDK, creating a basic WinUSB application project will give you a perfect example of an application opening a device with the SetupDi functions mentionned above.

From Kernel-mode:

Look at IoGetDeviceInterfaces. This function returns a list of device interface instances that matches the search criteria. Filter the search with GUID_DEVINTERFACE_DISK like in user mode. Each interface (symbolic link) can be passed to the IoGetDeviceObjectPointer to obtain the device at the top of the (disk) device’s stack. You can then call IoAttachDeviceToDeviceStack to place you’re own device at the top of that stack. Any IRP sent to the disk should be delivered to your driver unless an another driver attaches after your driver and filters IRPs.