How to get SRB_HaId, SRB_Target and SRB_Lun?
-
If i know the device drive letter, for example, J:(CD-ROM), how could i get its SRB_HaId(ASPI host adapter number), SRB_Target(Target's SCSI ID) and SRB_Lun(Target's logical unit number)?:suss: Enemy sighted, roger, go go go!
-
If i know the device drive letter, for example, J:(CD-ROM), how could i get its SRB_HaId(ASPI host adapter number), SRB_Target(Target's SCSI ID) and SRB_Lun(Target's logical unit number)?:suss: Enemy sighted, roger, go go go!
Do something like this (just plain C(++), no unicode support): char Drive[MAX_PATH]; char m_UseDrive = 'j'; HANDLE hDrive; sprintf(Drive,"\\\\.\\%c:", m_UseDrive); hDrive = CreateFile(Drive, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(hDrive == INVALID_HANDLE_VALUE) { // Error } // These defines comes from devioctl.h and ntddscsi.h // Include them if you've got them. #define FILE_DEVICE_CONTROLLER 0x00000004 #define IOCTL_SCSI_BASE FILE_DEVICE_CONTROLLER #define IOCTL_SCSI_GET_ADDRESS CTL_CODE(IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS) typedef struct _SCSI_ADDRESS { ULONG Length; // Contains the length of this structure in bytes. . UCHAR PortNumber; // Contains the number of the SCSI adapter. UCHAR PathId; // Contains the number of the bus. UCHAR TargetId; // Contains the number of the target device. UCHAR Lun; // Contains the logical unit number. }SCSI_ADDRESS, *PSCSI_ADDRESS; // The real code starts here #define MAX_DATA_BUFFER 2048 UCHAR dataBuffer[MAX_DATA_BUFFER]; ULONG bytesReturned; BOOL bRetVal; ZeroMemory(&dataBuffer[0], sizeof(dataBuffer)); // Get the device address information. bRetVal = DeviceIoControl(hDrive, IOCTL_SCSI_GET_ADDRESS, NULL, 0, dataBuffer, sizeof(dataBuffer), &bytesReturned, FALSE); if(bRetVal == TRUE && bytesReturned == sizeof(SCSI_ADDRESS)) { // OK! Got the SCSI address! PSCSI_ADDRESS ps = (PSCSI_ADDRESS)&dataBuffer[0]; // Check out ps printf("PortNumber:%d, PathId:%d, TargetId:%d, Lun:%d", ps->PortNumber, ps->PathId, ps->TargetId, ps->Lun); } CloseHandle(hDrive);
-
Do something like this (just plain C(++), no unicode support): char Drive[MAX_PATH]; char m_UseDrive = 'j'; HANDLE hDrive; sprintf(Drive,"\\\\.\\%c:", m_UseDrive); hDrive = CreateFile(Drive, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(hDrive == INVALID_HANDLE_VALUE) { // Error } // These defines comes from devioctl.h and ntddscsi.h // Include them if you've got them. #define FILE_DEVICE_CONTROLLER 0x00000004 #define IOCTL_SCSI_BASE FILE_DEVICE_CONTROLLER #define IOCTL_SCSI_GET_ADDRESS CTL_CODE(IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS) typedef struct _SCSI_ADDRESS { ULONG Length; // Contains the length of this structure in bytes. . UCHAR PortNumber; // Contains the number of the SCSI adapter. UCHAR PathId; // Contains the number of the bus. UCHAR TargetId; // Contains the number of the target device. UCHAR Lun; // Contains the logical unit number. }SCSI_ADDRESS, *PSCSI_ADDRESS; // The real code starts here #define MAX_DATA_BUFFER 2048 UCHAR dataBuffer[MAX_DATA_BUFFER]; ULONG bytesReturned; BOOL bRetVal; ZeroMemory(&dataBuffer[0], sizeof(dataBuffer)); // Get the device address information. bRetVal = DeviceIoControl(hDrive, IOCTL_SCSI_GET_ADDRESS, NULL, 0, dataBuffer, sizeof(dataBuffer), &bytesReturned, FALSE); if(bRetVal == TRUE && bytesReturned == sizeof(SCSI_ADDRESS)) { // OK! Got the SCSI address! PSCSI_ADDRESS ps = (PSCSI_ADDRESS)&dataBuffer[0]; // Check out ps printf("PortNumber:%d, PathId:%d, TargetId:%d, Lun:%d", ps->PortNumber, ps->PathId, ps->TargetId, ps->Lun); } CloseHandle(hDrive);
:-DThanks very very much, kakan. I get it.:laugh:
-
:-DThanks very very much, kakan. I get it.:laugh: