Compuware Corporation Compuware NuMega home page NuMega Lab
teal

DriverStudio
 · Home
Driver Products  · DriverStudio
 · DriverBundle
 · Previews
 · Compatibility Downloads  · Wizards
 · Utilities
 · NT source examples
 · VxD source examples
 · WDM source examples Resources  · Technical papers
 · Useful links
 · Technical tips Support  · Support
 · Knowledge base
 · Problem submission
 · Product registration
 · Release notes Shop NuMega  · Buy it!
 · Price list
 · How to buy
 · Sales offices

 
Y2K Compliance

 
More information

Driver Technical Tips
Walking the Hardware Tree (Windows 95/98)

The Windows 95 Plug and Play subsystem models the buses and installed physical devices using a set of devnodes. A devnode is just a data structure that contains information about the state of the device, such as its hardware ID and its configuration.

The figure below shows a portion of the hardware tree for one of the development machines at NuMega:

hardware tree

Devnodes also describe how the corresponding device is related to other buses and devices in the system. Each devnode has a parent, which is typically the devnode of the bus on which the corresponding device resides. Devnodes for buses also have parents, because the buses in a computer system can be thought of as being hierarchically bridged together. Taken together, the set of linked devnodes form a tree structure known as the hardware tree.

The hardware tree is a dynamic description of all the active buses and devices in the system. The operating system builds this tree as devices are detected, and maintains it continuously as devices are added and removed. Unlike the registry, which stores similar information for all enumerated devices in a relatively flat structure, the hardware tree dynamically models in a hierarchical fashion the interconnections of currently present devices.

Occasionally, a driver developer needs to walk the hardware tree. This would be necessary for building a list of active devices, for determining if a particular hardware resource is in use, or for determining the bus topology of the system. You can use this code in a device driver to walk the hardware tree:


typedef VOID (*TREEWALKCALLBACK)(DEVNODE DevNode);



VOID WalkHardwareTree(DEVNODE Node, TREEWALKCALLBACK NodeCallback)

{

	DEVNODE Child, Sibling;



	// if paramter Node is NULL, the caller is initializing the

	// walk. To initialize the walk, we get the root devnode by

	// calling CONFIGMG_Locate_DevNode with NULL as the hardware ID.



	if (Node == 0)

	{

		CONFIGMG_Locate_DevNode(&Node, NULL, 0);

		

		// If the root is not found, something is very wrong!

		// Terminate the attempted walk by returning.



		if (Node == 0)

			return;

	}



	// At this point we have a devnode, so let the callback Know about it.



	NodeCallback(Node);

	

	// Now see if it has any children. If not, just return.



	if ( CONFIGMG_Get_Child(&Child, Node, 0) != CR_SUCCESS)

		return;



	else

	{



	// The node passed in has at least one child. Walk this subtree.



		WalkHardwareTree(Child, NodeCallback);



	// Now walk subtree of any siblings.



	while ( CONFIGMG_Get_Sibling(&Sibling, Child, 0) == CR_SUCCESS )

	{

		WalkHardwareTree(Sibling, NodeCallback);

		Child = Sibling;	

	}

}

} 

Back to technical tip start page.

 

DriverCentral · DriverStudio · Free downloads · Resources · Support and Services · Shop NuMega
Compuware NuMega · Tel: +1 603 578-8400 · Updated: 9 August 1999 · Problems? Contact our webmaster.