#include <initguid.h> // Guid definition
#include <devguid.h> // Device guids
#include <setupapi.h> // for SetupDiXxx functions.
-#include <cfgmgr32.h> // for SetupDiXxx functions.
#include <ntddscsi.h>
+#define INQUIRY_SIZE 36
typedef struct _SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER {
SCSI_PASS_THROUGH_DIRECT spt;
struct dev_info_spti {
char *drvpath;
char *name;
+ char *inquirydata;
int mediainserted;
HANDLE handle;
int isatapi;
int type;
int bus, path, target, lun;
+ int scanmode;
};
static uae_sem_t scgp_sem;
static int total_devices;
-static int adddrive (char *drvpath, int bus, int pathid, int targetid, int lunid)
-{
- struct dev_info_spti *di;
- int cnt = total_devices, i;
- if (cnt >= MAX_TOTAL_DEVICES)
- return 0;
- for (i = 0; i < total_devices; i++) {
- di = &dev_info[i];
- if (!strcmp(drvpath, di->drvpath))
- return 0;
- }
- write_log("SPTI: unit %d '%s' added\n", total_devices, drvpath);
- di = &dev_info[total_devices];
- di->drvpath = my_strdup(drvpath);
- di->type = 0;
- di->bus = bus;
- di->path = pathid;
- di->target = targetid;
- di->lun = lunid;
- total_devices++;
- return 1;
+static void close_scsi_device (int unitnum)
+{
+ write_log ("SPTI: unit %d closed\n", unitnum);
+ if (dev_info[unitnum].handle != INVALID_HANDLE_VALUE)
+ CloseHandle (dev_info[unitnum].handle);
+ dev_info[unitnum].handle = INVALID_HANDLE_VALUE;
}
-int rescan(void);
-static int open_scsi_bus (int flags)
+static void free_scsi_device(int dev)
{
- int i;
-
- total_devices = 0;
- uae_sem_init (&scgp_sem, 0, 1);
- for (i = 0; i < MAX_TOTAL_DEVICES; i++) {
- memset (&dev_info[i], 0, sizeof (struct dev_info_spti));
- dev_info[i].handle = INVALID_HANDLE_VALUE;
- }
- if (!scsibuf)
- scsibuf = VirtualAlloc (NULL, DEVICE_SCSI_BUFSIZE, MEM_COMMIT, PAGE_READWRITE);
- rescan();
- return total_devices;
+ close_scsi_device (dev);
+ xfree(dev_info[dev].name);
+ xfree(dev_info[dev].drvpath);
+ xfree(dev_info[dev].inquirydata);
+ dev_info[dev].name = NULL;
+ dev_info[dev].drvpath = NULL;
+ dev_info[dev].inquirydata = NULL;
+ memset(&dev_info[dev], 0, sizeof (struct dev_info_spti));
}
-#if 0
+int rescan(void);
static int open_scsi_bus (int flags)
{
- int dwDriveMask;
- int drive, firstdrive;
- char tmp[10], tmp2[10];
int i;
total_devices = 0;
- firstdrive = 0;
uae_sem_init (&scgp_sem, 0, 1);
for (i = 0; i < MAX_TOTAL_DEVICES; i++) {
memset (&dev_info[i], 0, sizeof (struct dev_info_spti));
}
if (!scsibuf)
scsibuf = VirtualAlloc (NULL, DEVICE_SCSI_BUFSIZE, MEM_COMMIT, PAGE_READWRITE);
- dwDriveMask = GetLogicalDrives ();
- device_debug ("SPTI: drive mask = %08.8X\n", dwDriveMask);
- dwDriveMask >>= 2; // Skip A and B drives...
- for( drive = 'C'; drive <= 'Z'; drive++) {
- if (dwDriveMask & 1) {
- int dt;
- sprintf( tmp, "%c:\\", drive );
- sprintf( tmp2, "%c:\\.", drive );
- dt = GetDriveType (tmp);
- device_debug ("SPTI: drive %c type %d\n", drive, dt);
- if (dt == DRIVE_CDROM) {
- if (!firstdrive)
- firstdrive = drive;
- if (adddrive (total_devices, drive))
- total_devices++;
- }
- }
- dwDriveMask >>= 1;
- }
+ rescan();
return total_devices;
}
-#endif
static void close_scsi_bus (void)
{
int i;
VirtualFree (scsibuf, 0, MEM_RELEASE);
scsibuf = 0;
- for (i = 0; i < total_devices; i++) {
- xfree(dev_info[i].name);
- xfree(dev_info[i].drvpath);
- dev_info[i].name = NULL;
- dev_info[i].drvpath = NULL;
- }
+ for (i = 0; i < total_devices; i++)
+ free_scsi_device(i);
}
static int inquiry (int unitnum, int *type, uae_u8 *inquirydata, int *inqlen)
{
uae_u8 cmd[6] = { 0x12,0,0,0,36,0 }; /* INQUIRY */
- uae_u8 out[36];
+ uae_u8 out[INQUIRY_SIZE] = { 0 };
int outlen = sizeof (out);
uae_u8 *p = execscsicmd_in (unitnum, cmd, sizeof (cmd), &outlen);
int v = 0;
*type = 0x1f;
if (!p) {
if (log_scsi)
- write_log("SPTI: INQUIRY failed!?\n");
+ write_log("SPTI: INQUIRY failed\n");
return 0;
}
- *inqlen = outlen > 36 ? 36 : outlen;
+ *inqlen = outlen > INQUIRY_SIZE ? INQUIRY_SIZE : outlen;
if (outlen >= 1)
*type = p[0] & 31;
if (outlen >= 2 && (p[0] & 31) == 5 && (p[2] & 7) == 0)
v = 1;
memcpy (inquirydata, p, *inqlen);
if (log_scsi) {
- if (outlen >= 36)
+ if (outlen >= INQUIRY_SIZE)
write_log("SPTI: INQUIRY: %02.2X%02.2X%02.2X %d '%-8.8s' '%-16.16s'\n",
p[0], p[1], p[2], v, p + 8, p + 16);
}
return v >= 0 ? 1 : 0;
}
-static void close_scsi_device (int unitnum)
-{
- write_log ("SPTI: cd unit %d closed\n", unitnum);
- if (dev_info[unitnum].handle != INVALID_HANDLE_VALUE)
- CloseHandle (dev_info[unitnum].handle);
- dev_info[unitnum].handle = INVALID_HANDLE_VALUE;
-}
-
int open_scsi_device (int unitnum)
{
HANDLE h;
if (h == INVALID_HANDLE_VALUE) {
write_log ("SPTI: failed to open unit %d err=%d ('%s')\n", unitnum, GetLastError(), dev);
} else {
- uae_u8 inqdata[37] = { 0 };
+ uae_u8 inqdata[INQUIRY_SIZE + 1] = { 0 };
int inqlen;
dev_info[unitnum].isatapi = inquiry (unitnum, &dev_info[unitnum].type, inqdata, &inqlen);
if (inqlen == 0) {
xfree (dev);
return 0;
}
- inqdata[36] = 0;
+ inqdata[INQUIRY_SIZE] = 0;
if (dev_info[unitnum].type == INQ_ROMD) {
dev_info[unitnum].mediainserted = mediacheck (unitnum);
write_log ("SPTI: unit %d opened [%s], %s, '%s'\n", unitnum,
unitnum, dev_info[unitnum].type, inqdata + 8);
}
dev_info[unitnum].name = my_strdup (inqdata + 8);
+ dev_info[unitnum].inquirydata = xmalloc (INQUIRY_SIZE);
+ memcpy (dev_info[unitnum].inquirydata, inqdata, INQUIRY_SIZE);
xfree (dev);
return 1;
}
return 0;
}
+static int adddrive (char *drvpath, int bus, int pathid, int targetid, int lunid, int scanmode)
+{
+ struct dev_info_spti *di;
+ int cnt = total_devices, i;
+ int freeit = 1;
+
+ if (cnt >= MAX_TOTAL_DEVICES)
+ return 0;
+ for (i = 0; i < total_devices; i++) {
+ di = &dev_info[i];
+ if (!strcmp(drvpath, di->drvpath))
+ return 0;
+ }
+ write_log("SPTI: unit %d '%s' added\n", total_devices, drvpath);
+ di = &dev_info[total_devices];
+ di->drvpath = my_strdup(drvpath);
+ di->type = 0;
+ di->bus = bus;
+ di->path = pathid;
+ di->target = targetid;
+ di->lun = lunid;
+ di->scanmode = scanmode;
+ total_devices++;
+ if (open_scsi_device(cnt)) {
+ for (i = 0; i < cnt; i++) {
+ if (!memcmp(di->inquirydata, dev_info[i].inquirydata, INQUIRY_SIZE) && di->scanmode != dev_info[i].scanmode) {
+ write_log("duplicate device, skipped..\n");
+ break;
+ }
+ }
+ if (i == cnt) {
+ freeit = 0;
+ close_scsi_device(cnt);
+ }
+ }
+ if (freeit) {
+ free_scsi_device(cnt);
+ total_devices--;
+ }
+ return 1;
+}
+
static struct device_info *info_device (int unitnum, struct device_info *di)
{
if (unitnum >= MAX_TOTAL_DEVICES || dev_info[unitnum].handle == INVALID_HANDLE_VALUE)
0, 0, 0, 0, 0, 0, 0, check_isatapi
};
-#define SCSI_INFO_BUFFER_SIZE 0x5000 // Big enough to hold all Bus/Device info.
-static char* BusType[] = {
- "UNKNOWN", // 0x00
- "SCSI",
- "ATAPI",
- "ATA",
- "IEEE 1394",
- "SSA",
- "FIBRE",
- "USB",
- "RAID"
-};
-
-static void GetInquiryData(PCTSTR pDevId, DWORD idx)
-{
- SP_DEVICE_INTERFACE_DATA interfaceData;
- PSP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetailData = NULL;
- STORAGE_PROPERTY_QUERY query;
- PSTORAGE_ADAPTER_DESCRIPTOR adpDesc;
- PSCSI_BUS_DATA BusData;
- PSCSI_INQUIRY_DATA InquiryData;
- PSCSI_ADAPTER_BUS_INFO AdapterInfo;
- HANDLE hDevice;
- BOOL status;
- DWORD index = 0;
- HDEVINFO hIntDevInfo;
- UCHAR outBuf[512];
- BOOL Claimed;
- ULONG returnedLength;
- SHORT Bus,
- Luns;
- DWORD interfaceDetailDataSize,
- reqSize,
- errorCode;
-
-
- hIntDevInfo = SetupDiGetClassDevs (
- &StoragePortClassGuid,
- pDevId, // Enumerator
- NULL, // Parent Window
- (DIGCF_PRESENT | DIGCF_INTERFACEDEVICE // Only Devices present & Interface class
- ));
-
- if (hIntDevInfo == INVALID_HANDLE_VALUE) {
- write_log ("SetupDiGetClassDevs failed with error: %d\n", GetLastError());
- return;
- }
-
- interfaceData.cbSize = sizeof (SP_INTERFACE_DEVICE_DATA);
-
- status = SetupDiEnumDeviceInterfaces (
- hIntDevInfo, // Interface Device Info handle
- 0,
- (LPGUID) &StoragePortClassGuid,
- index, // Member
- &interfaceData // Device Interface Data
- );
-
- if (status == FALSE) {
- errorCode = GetLastError();
- if (errorCode == ERROR_NO_MORE_ITEMS)
- return;
- write_log ("SetupDiEnumDeviceInterfaces failed with error: %d\n", errorCode);
- return;
- }
-
- //
- // Find out required buffer size, so pass NULL
- //
-
- status = SetupDiGetDeviceInterfaceDetail (
- hIntDevInfo, // Interface Device info handle
- &interfaceData, // Interface data for the event class
- NULL, // Checking for buffer size
- 0, // Checking for buffer size
- &reqSize, // Buffer size required to get the detail data
- NULL // Checking for buffer size
- );
-
- //
- // This call returns ERROR_INSUFFICIENT_BUFFER with reqSize
- // set to the required buffer size. Ignore the above error and
- // pass a bigger buffer to get the detail data
- //
-
- if (status == FALSE) {
- errorCode = GetLastError();
- if (errorCode != ERROR_INSUFFICIENT_BUFFER) {
- write_log ("SetupDiGetDeviceInterfaceDetail failed with error: %d\n", errorCode);
- return;
- }
- }
-
- //
- // Allocate memory to get the interface detail data
- // This contains the devicepath we need to open the device
- //
-
- interfaceDetailDataSize = reqSize;
- interfaceDetailData = malloc (interfaceDetailDataSize);
- if (interfaceDetailData == NULL) {
- write_log ("Unable to allocate memory to get the interface detail data.\n");
- return;
- }
- interfaceDetailData->cbSize = sizeof (SP_INTERFACE_DEVICE_DETAIL_DATA);
-
- status = SetupDiGetDeviceInterfaceDetail (
- hIntDevInfo, // Interface Device info handle
- &interfaceData, // Interface data for the event class
- interfaceDetailData, // Interface detail data
- interfaceDetailDataSize, // Interface detail data size
- &reqSize, // Buffer size required to get the detail data
- NULL); // Interface device info
-
- if (status == FALSE) {
- write_log ("Error in SetupDiGetDeviceInterfaceDetail failed with error: %d\n", GetLastError());
- return;
- }
-
- //
- // Now we have the device path. Open the device interface
- // to get adapter property and inquiry data
-
-
- hDevice = CreateFile(
- interfaceDetailData->DevicePath, // device interface name
- GENERIC_READ | GENERIC_WRITE, // dwDesiredAccess
- FILE_SHARE_READ | FILE_SHARE_WRITE, // dwShareMode
- NULL, // lpSecurityAttributes
- OPEN_EXISTING, // dwCreationDistribution
- 0, // dwFlagsAndAttributes
- NULL // hTemplateFile
- );
-
- //
- // We have the handle to talk to the device.
- // So we can release the interfaceDetailData buffer
- //
-
- free (interfaceDetailData);
-
- if (hDevice == INVALID_HANDLE_VALUE) {
- write_log ("CreateFile failed with error: %d\n", GetLastError());
- CloseHandle ( hDevice );
- return;
- }
-
- query.PropertyId = StorageAdapterProperty;
- query.QueryType = PropertyStandardQuery;
-
- status = DeviceIoControl(
- hDevice,
- IOCTL_STORAGE_QUERY_PROPERTY,
- &query,
- sizeof(STORAGE_PROPERTY_QUERY),
- &outBuf,
- 512,
- &returnedLength,
- NULL
- );
- if (!status) {
- write_log ("IOCTL failed with error code%d.\n\n", GetLastError());
- } else {
- adpDesc = (PSTORAGE_ADAPTER_DESCRIPTOR) outBuf;
- write_log ("\nAdapter Properties\n");
- write_log ("------------------\n");
- write_log ("Bus Type : %s\n", BusType[adpDesc->BusType]);
- write_log ("Max. Tr. Length: 0x%x\n", adpDesc->MaximumTransferLength );
- write_log ("Max. Phy. Pages: 0x%x\n", adpDesc->MaximumPhysicalPages );
- write_log ("Alignment Mask : 0x%x\n", adpDesc->AlignmentMask );
- }
-
- AdapterInfo = (PSCSI_ADAPTER_BUS_INFO) malloc(SCSI_INFO_BUFFER_SIZE) ;
- if (AdapterInfo == NULL) {
- CloseHandle (hDevice);
- return;
- }
-
- // Get the SCSI inquiry data for all devices for the given SCSI bus
- status = DeviceIoControl(
- hDevice,
- IOCTL_SCSI_GET_INQUIRY_DATA,
- NULL,
- 0,
- AdapterInfo,
- SCSI_INFO_BUFFER_SIZE,
- &returnedLength,
- NULL );
-
- if (!status) {
- write_log ("Error in IOCTL_SCSI_GET_INQUIRY_DATA\n" );
- free (AdapterInfo);
- CloseHandle (hDevice);
- return;
- }
-
- write_log ("Initiator Path ID Target ID LUN Claimed Device \n");
- write_log ("---------------------------------------------------------\n");
-
- for (Bus = 0; Bus < AdapterInfo->NumberOfBuses; Bus++) {
- int luncheck = 0;
- BusData = &AdapterInfo->BusData[Bus];
- InquiryData = (PSCSI_INQUIRY_DATA) ( (PUCHAR) AdapterInfo + BusData->InquiryDataOffset );
- for (Luns = 0; Luns < BusData->NumberOfLogicalUnits; Luns++) {
- char label[100];
- int type = InquiryData->InquiryData[0] & 0x1f;
- Claimed = InquiryData->DeviceClaimed;
- write_log (" %3d %d %d %d %s %d\n",
- BusData->InitiatorBusId, InquiryData->PathId, InquiryData->TargetId,
- InquiryData->Lun, Claimed ? "Yes" : "No ", type);
- if (Claimed == 0 && !luncheck && type != INQ_DASD) {
- luncheck = 1;
- sprintf (label, "SCSI(%d):%d:%d:%d:%d", idx, BusData->InitiatorBusId,
- InquiryData->PathId, InquiryData->TargetId, InquiryData->Lun);
- adddrive (label, idx, InquiryData->PathId, InquiryData->TargetId, InquiryData->Lun);
- }
- InquiryData = (PSCSI_INQUIRY_DATA) ( (PUCHAR) AdapterInfo + InquiryData->NextInquiryDataOffset );
- } // for Luns
- } // for Bus
-
- write_log ("\n" );
- free (AdapterInfo);
- CloseHandle (hDevice);
-}
-
-#if 0
-static void GetChildDevices(DEVINST DevInst)
-{
- DEVINST childDevInst;
- DEVINST siblingDevInst;
- CONFIGRET configRetVal;
- TCHAR deviceInstanceId[MAX_DEVICE_ID_LEN];
-// HDEVINFO tmpdi;
-
- configRetVal = CM_Get_Child (
- &childDevInst,
- DevInst,
- 0 );
-
- if (configRetVal == CR_NO_SUCH_DEVNODE) {
- write_log ("No child devices\n");
- return;
- }
-
- if (configRetVal != CR_SUCCESS) {
- write_log ("CM_Get_Child failed with error: %x\n", configRetVal);
- return;
- }
-
- do {
-
- // Get the Device Instance ID using the handle
- configRetVal = CM_Get_Device_ID(
- childDevInst,
- deviceInstanceId,
- sizeof(deviceInstanceId)/sizeof(TCHAR),
- 0
- );
- if (configRetVal != CR_SUCCESS) {
- write_log ("CM_Get_Device_ID: Get Device Instance ID failed with error: %x\n", configRetVal);
- return;
- }
-
- write_log ("'%s'\n", deviceInstanceId);
-#if 0
- tmpdi = SetupDiCreateDeviceInfoList (NULL, NULL);
- if (tmpdi) {
- SP_DEVINFO_DATA did;
- did.cbSize = sizeof (did);
- SetupDiOpenDeviceInfo(tmpdi, deviceInstanceId, NULL, 0, &did);
- adddrive (deviceInstanceId, -1, -1, -1, -1);
- SetupDiDestroyDeviceInfoList (tmpdi);
- }
-#endif
- // Get sibling
- configRetVal = CM_Get_Sibling (
- &siblingDevInst,
- childDevInst,
- 0 );
-
- if (configRetVal == CR_NO_SUCH_DEVNODE)
- return;
-
- if (configRetVal != CR_SUCCESS) {
- write_log ("CM_Get_Sibling failed with error: 0x%X\n", configRetVal);
- return;
- }
- childDevInst = siblingDevInst;
-
- } while (TRUE);
-
-}
-#endif
-
-static BOOL GetRegistryProperty(HDEVINFO DevInfo, DWORD Index, int *first)
-{
- SP_DEVINFO_DATA deviceInfoData;
- DWORD errorCode;
- DWORD bufferSize = 0;
- DWORD dataType;
- LPTSTR buffer = NULL;
- BOOL status;
- CONFIGRET configRetVal;
- TCHAR deviceInstanceId[MAX_DEVICE_ID_LEN];
-
- // Get the DEVINFO data. This has the handle to device instance
- deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
- status = SetupDiEnumDeviceInfo(
- DevInfo, // Device info set
- Index, // Index in the info set
- &deviceInfoData); // Info data. Contains handle to dev inst
-
- if (status == FALSE) {
- errorCode = GetLastError();
- if (errorCode == ERROR_NO_MORE_ITEMS) {
- if (*first)
- write_log ("SPTI: No SCSI adapters detected\n");
- return FALSE;
- }
- write_log ("SetupDiEnumDeviceInfo failed with error: %d\n", errorCode);
- return FALSE;
- }
- *first = 0;
-
- // Get the Device Instance ID using the handle
- configRetVal = CM_Get_Device_ID(
- deviceInfoData.DevInst, // Handle to dev inst
- deviceInstanceId, // Buffer to receive dev inst
- sizeof(deviceInstanceId)/sizeof(TCHAR), // Buffer size
- 0); // Must be zero
- if (configRetVal != CR_SUCCESS) {
- write_log ("CM_Get_Device_ID failed with error: %d\n", configRetVal);
- return FALSE;
- }
-
- //
- // We won't know the size of the HardwareID buffer until we call
- // this function. So call it with a null to begin with, and then
- // use the required buffer size to Alloc the necessary space.
- // Call it again with the obtained buffer size
- //
- status = SetupDiGetDeviceRegistryProperty(
- DevInfo,
- &deviceInfoData,
- SPDRP_HARDWAREID,
- &dataType,
- (PBYTE)buffer,
- bufferSize,
- &bufferSize);
-
- if (status == FALSE) {
- errorCode = GetLastError();
- if (errorCode != ERROR_INSUFFICIENT_BUFFER) {
- if (errorCode == ERROR_INVALID_DATA) {
- //
- // May be a Legacy Device with no HardwareID. Continue.
- //
- write_log ("No Hardware ID, may be a legacy device!\n");
- } else {
- write_log ("SetupDiGetDeviceRegistryProperty failed with error: %d\n", errorCode);
- return FALSE;
- }
- }
- }
-
- //
- // We need to change the buffer size.
- //
- buffer = LocalAlloc(LPTR, bufferSize);
- status = SetupDiGetDeviceRegistryProperty(
- DevInfo,
- &deviceInfoData,
- SPDRP_HARDWAREID,
- &dataType,
- (PBYTE)buffer,
- bufferSize,
- &bufferSize);
-
- if (status == FALSE) {
- errorCode = GetLastError();
- if (errorCode == ERROR_INVALID_DATA) {
- //
- // May be a Legacy Device with no HardwareID. Continue.
- //
- write_log ("No Hardware ID, may be a legacy device!\n");
- } else {
- write_log ("SetupDiGetDeviceRegistryProperty failed with error: %d\n", errorCode);
- return FALSE;
- }
- }
- write_log ("Device ID '%s'\n",buffer);
-
- if (buffer)
- LocalFree(buffer);
-
- // **** Now get the Device Description
-
- //
- // We won't know the size of the Location Information buffer until
- // we call this function. So call it with a null to begin with,
- // and then use the required buffer size to Alloc the necessary space.
- // Call it again with the obtained buffer size
- //
-
- status = SetupDiGetDeviceRegistryProperty(
- DevInfo,
- &deviceInfoData,
- SPDRP_DEVICEDESC,
- &dataType,
- (PBYTE)buffer,
- bufferSize,
- &bufferSize);
-
- if (status == FALSE) {
- errorCode = GetLastError();
- if (errorCode != ERROR_INSUFFICIENT_BUFFER) {
- if (errorCode == ERROR_INVALID_DATA) {
- write_log("No Device Description!\n");
- } else {
- write_log("SetupDiGetDeviceRegistryProperty failed with error: %d\n", errorCode);
- return FALSE;
- }
- }
- }
-
- //
- // We need to change the buffer size.
- //
-
- buffer = LocalAlloc(LPTR, bufferSize);
-
- status = SetupDiGetDeviceRegistryProperty(
- DevInfo,
- &deviceInfoData,
- SPDRP_DEVICEDESC,
- &dataType,
- (PBYTE)buffer,
- bufferSize,
- &bufferSize);
-
- if (status == FALSE) {
- errorCode = GetLastError();
- if (errorCode == ERROR_INVALID_DATA) {
- write_log ("No Device Description!\n");
- } else {
- write_log ("SetupDiGetDeviceRegistryProperty failed with error: %d\n", errorCode);
- return FALSE;
- }
- }
-
- write_log ("Device Description '%s'\n",buffer);
-
- if (buffer)
- LocalFree(buffer);
-
- // Reenumerate the SCSI adapter device node
- configRetVal = CM_Reenumerate_DevNode(deviceInfoData.DevInst, 0);
-
- if (configRetVal != CR_SUCCESS) {
- write_log ("CM_Reenumerate_DevNode failed with error: %d\n", configRetVal);
- return FALSE;
- }
-
- GetInquiryData ((PCTSTR)&deviceInstanceId, Index);
-#if 0
- // Find the children devices
- GetChildDevices (deviceInfoData.DevInst);
-#endif
- return TRUE;
-}
-
static int getCDROMProperty(int idx, HDEVINFO DevInfo, const GUID *guid)
{
SP_DEVICE_INTERFACE_DATA interfaceData;
if (status == FALSE)
return FALSE;
- adddrive (interfaceDetailData->DevicePath, -1, -1, -1, -1);
+ adddrive (interfaceDetailData->DevicePath, -1, -1, -1, -1, 1);
free (interfaceDetailData);
return TRUE;
}
+#define SCSI_INFO_BUFFER_SIZE 0x5000
+static void scanscsi(void)
+{
+ PSCSI_BUS_DATA BusData;
+ PSCSI_INQUIRY_DATA InquiryData;
+ PSCSI_ADAPTER_BUS_INFO AdapterInfo;
+ HANDLE h;
+ BOOL status;
+ BOOL Claimed;
+ ULONG returnedLength;
+ SHORT Bus, Luns;
+ DWORD bytesTransferred;
+ int idx;
+ char DeviceName[256];
+
+ AdapterInfo = (PSCSI_ADAPTER_BUS_INFO)xmalloc(SCSI_INFO_BUFFER_SIZE) ;
+ if (AdapterInfo == NULL)
+ return;
+
+ idx = 0;
+ for (;;) {
+ sprintf(DeviceName, "\\\\.\\Scsi%d:", idx++);
+ h = CreateFile (DeviceName,
+ GENERIC_READ | GENERIC_WRITE,
+ 0,
+ NULL, // no SECURITY_ATTRIBUTES structure
+ OPEN_EXISTING, // No special create flags
+ 0, // No special attributes
+ NULL);
+ if (h == INVALID_HANDLE_VALUE)
+ return;
+
+ if(!DeviceIoControl(h,
+ IOCTL_SCSI_RESCAN_BUS,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ &bytesTransferred,
+ NULL)) {
+ write_log( "Rescan SCSI port %d failed [Error %d]\n", idx - 1, GetLastError());
+ CloseHandle(h);
+ continue;
+ }
+
+ // Get the SCSI inquiry data for all devices for the given SCSI bus
+ status = DeviceIoControl(
+ h,
+ IOCTL_SCSI_GET_INQUIRY_DATA,
+ NULL,
+ 0,
+ AdapterInfo,
+ SCSI_INFO_BUFFER_SIZE,
+ &returnedLength,
+ NULL);
+
+ if (!status) {
+ write_log ("Error in IOCTL_SCSI_GET_INQUIRY_DATA\n" );
+ CloseHandle (h);
+ continue;
+ }
+
+ for (Bus = 0; Bus < AdapterInfo->NumberOfBuses; Bus++) {
+ int luncheck = 0;
+ BusData = &AdapterInfo->BusData[Bus];
+ InquiryData = (PSCSI_INQUIRY_DATA) ( (PUCHAR) AdapterInfo + BusData->InquiryDataOffset );
+ for (Luns = 0; Luns < BusData->NumberOfLogicalUnits; Luns++) {
+ char label[100];
+ int type = InquiryData->InquiryData[0] & 0x1f;
+ Claimed = InquiryData->DeviceClaimed;
+ write_log ("SCSI=%d Initiator=%d Path=%d Target=%d LUN=%d Claimed=%s Type=%d\n",
+ idx - 1,
+ BusData->InitiatorBusId, InquiryData->PathId, InquiryData->TargetId,
+ InquiryData->Lun, Claimed ? "Yes" : "No ", type);
+ if (Claimed == 0 && !luncheck) {
+ luncheck = 1;
+ sprintf (label, "SCSI(%d):%d:%d:%d:%d", idx - 1, BusData->InitiatorBusId,
+ InquiryData->PathId, InquiryData->TargetId, InquiryData->Lun);
+ adddrive (label, idx - 1, InquiryData->PathId, InquiryData->TargetId, InquiryData->Lun, 3);
+ }
+ InquiryData = (PSCSI_INQUIRY_DATA) ( (PUCHAR) AdapterInfo + InquiryData->NextInquiryDataOffset );
+ } // for Luns
+ } // for Bus
+ CloseHandle(h);
+ }
+}
+
static const GUID *guids[] = {
&GUID_DEVINTERFACE_CDROM,
&GUID_DEVCLASS_IMAGE,
&GUID_DEVCLASS_TAPEDRIVE,
NULL };
-static const char *scsinames[] = { "Tape", "Scanner", NULL };
+static const char *scsinames[] = { "Tape", "Scanner", "Changer", NULL };
static int rescan(void)
{
- HDEVINFO hDevInfo;
int idx, idx2;
- int first;
for (idx2 = 0; guids[idx2]; idx2++) {
- hDevInfo = SetupDiGetClassDevs(
+ HDEVINFO hDevInfo = SetupDiGetClassDevs(
guids[idx2],
NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
if (hDevInfo != INVALID_HANDLE_VALUE) {
SetupDiDestroyDeviceInfoList(hDevInfo);
}
}
-#if 0
+
for (idx2 = 0; scsinames[idx2]; idx2++) {
int max = 10;
for (idx = 0; idx < max; idx++) {
char tmp[100];
HANDLE h;
sprintf (tmp, "\\\\.\\%s%d", scsinames[idx2], idx);
- write_log("SPTI: %s\n", tmp);
h = CreateFile(tmp, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (h != INVALID_HANDLE_VALUE) {
- adddrive(tmp, -1, -1, -1, -1);
+ adddrive(tmp, -1, -1, -1, -1, 2);
CloseHandle(h);
if (idx == max - 1)
max++;
}
}
}
-#endif
if (currprefs.win32_uaescsimode == UAESCSI_SPTISCAN) {
write_log("SCSI adapter enumeration..\n");
- first = 1;
- hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_SCSIADAPTER, NULL, NULL, DIGCF_PRESENT);
- if (hDevInfo != INVALID_HANDLE_VALUE) {
- for (idx = 0; ; idx++) {
- if (!GetRegistryProperty(hDevInfo, idx, &first))
- break;
- }
- }
- SetupDiDestroyDeviceInfoList(hDevInfo);
+ scanscsi();
write_log("SCSI adapter enumeration ends\n");
}
return 1;