I have a computer with SATA drives and code, which through Windows 7, returned location information as SCSI_ADDRESS. The following code works fine for Windows 7.
typedef struct _SCSI_ADDRESS {
ULONG Length;
UCHAR PortNumber;
UCHAR PathId;
UCHAR TargetId;
UCHAR Lun;
}SCSI_ADDRESS, *PSCSI_ADDRESS;
char[256] FileName;
strcpy(FileName, "\\?\ide#diskcrucial_ct250mx200ssd1__________________mu02____#4&1f5e0e69&0&0.0.0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}");
m_deviceHandle = CreateFile(FileName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING,
0);
SCSI_ADDRESS m_sa;
memset ((void *)&m_sa, 0, sizeof(SCSI_ADDRESS));
m_sa.Length = sizeof(SCSI_ADDRESS);
if (!DeviceIoControl(IOCTL_SCSI_GET_ADDRESS, &m_sa, sizeof(SCSI_ADDRESS), &m_sa, sizeof(SCSI_ADDRESS), &cbBytesReturned))
{
}
Under Windows 10, the Intel SATA driver returns a success code (true), but leaves the SCSI information as zeroes. I do notice that through Device Manager or Disk Management that the location is different for each SATA disk.
How do I obtain the location information?
I have an open link to the device and can obtain IOCTL_SCSI_* everything, just not the location ID.
Hardware
The disk attaches to the internal Intel SATA controller.
Controller: Intel ICH8R/DH/DO SATA AHCI Controller
Driver: iaStor.sys
Version: 8.9.0.1023
I am open to possibly a different driver that renders SCSI information, though the question would still be valid, as the Intel driver works.
UPDATE:
I found this post, which indicates to use 'get-disk | select *' in PowerShell. I do see location information
Location : Integrated : Adapter 0 : Channel 0 : Device 0
The information is not exactly "3" or "2", as shown in Device Manager. This method would be a pain in C++. I really am hoping for a Setupdi API or IOCTL method that obtains location information.
These two links, one and two, are interesting but not very helpful, so I list them here as part of my research. I already have the device path, hence unnecessary.
This link talks about implementing ManagementObjectSearcher
in C++.