Microsoft KB Archive/308669

= How to rescan the SCSI bus for new devices =

Article ID: 308669

Article Last Modified on 11/23/2005

-

APPLIES TO


 * Microsoft Win32 Device Driver Kit for Windows 2000
 * Microsoft Windows XP Driver Development Kit
 * Microsoft Windows Server 2003 Driver Development Kit

-



This article was previously published under Q308669



SUMMARY
You can use the Rescan sample program, which is available through this article, to enumerate all available SCSI adapters on the system and initiate bus rescan. This will find new devices that have been added to the bus since the previous bus scan.

The sample also obtains a handle to the device to send IOCTL commands to get the adapter properties. The sample also demonstrates enumeration of child devices through two different techniques. The first technique gets the inquiry data for each SCSI adapter, and the second technique uses the CM_xxx APIs.



MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

Rescan1.exe

Release Date: OCT-17-2001

For more information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to obtain Microsoft support files from online services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help prevent any unauthorized changes to the file. The Rescan1.exe file contains the following files:

File          Description - Rescan        Implements the Win32 application to enumerate devices Rescan.h      Header file for rescan.c Sources        DDK build instructions Makefile      Standard Windows 2000 makefile Rescan.txt    The documentation for these samples (this article) Rescan.exe    Windows 2000 executable program (free build)

Device enumeration
This sample uses the Setup class GUID GUID_DEVCLASS_SCSIADAPTER to enumerate all the SCSI adapters that are installed on the system. The sample gets the registry properties to obtain the device properties. It then initiates bus rescan and gets child device properties.

In order for a Win32 application to send IOCTLs, the application should have the handle to the device. To obtain the device handle, the application can use the device interface name to open the device. The SCSI port driver exposes this interface by registering the device interface. It uses the StoragePortClassGuid interface GUID for device registration. A Win32 application can use the SetupDi APIs with the same interface GUID to obtain this interface name. If this is done in a loop, all the registered SCSI adapter interfaces can be obtained. Because the SCSI port driver provides these values, this will work for all types of adapters that the SCSI port driver manages.

Adapter properties
You can use the IOCTL_STORAGE_QUERY_PROPERTY to get the adapter properties. This IOCTL takes the data structure STORAGE_PROPERTY_QUERY as an argument. Before you call this IOCTL, you must set the STORAGE_PROPERTY_ID and STORAGE_QUERY_TYPE member. You can set the STORAGE_PROPERTY_ID to either StorageAdapterProperty or StorageDeviceProperty. StorageAdapterProperty returns the properties of the adapters and StorageDeviceProperty returns the properties of the devices. This data structure and its member values are defined in \NTddk\Src\NTddstor.h.

This sample uses StorageAdapterProperty to obtain the adapter properties. This returns the STORAGE_ADAPTER_DESCRIPTOR data structure that contains adapter properties, such as the bus type, maximum transfer length, and alignment mask.

Child device properties
This sample uses the IOCTL_SCSI_GET_INQUIRY_DATA IOCTL to get the inquiry data from each bus. It then lists all devices with the SCSI address and device type.

The second technique that the sample demonstrates uses the CM_xxx APIs to get all the child devices of an adapter. It also gets the device instance ID for each child device.

Building the sample

 * 1) Select Free Build Environment or Checked Build Environment under your Development Kits program group to set basic environment variables that the build utility needs.
 * 2) Change to the directory that contains the device source code. For example, CD C:\Rescan.
 * 3) Run build -ceZ or use the macro BLD.

This invokes the Microsoft make routines that produce a log file called Buildxxx.log plus Buildxxx.wrn and Buildxxx.err if there are any warnings or errors (where xxx stands for &quot;fre&quot; or &quot;chk&quot;, depending on the environment that you chose). If the build succeeds, the executable file Rescan.exe will be placed in a platform-specific subdirectory of your  directory as specified in the Sources file.

Running the Rescan.exe sample
This sample does not take any arguments, so simply execute it from a command prompt window. It will list each SCSI adapter and its child devices' properties.

