Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Hardware & Devices
  4. How to get SRB_HaId, SRB_Target and SRB_Lun?

How to get SRB_HaId, SRB_Target and SRB_Lun?

Scheduled Pinned Locked Moved Hardware & Devices
tutorialquestion
4 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Syouki_kou
    wrote on last edited by
    #1

    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!

    K 1 Reply Last reply
    0
    • S Syouki_kou

      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!

      K Offline
      K Offline
      kakan
      wrote on last edited by
      #2

      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);

      S 1 Reply Last reply
      0
      • K kakan

        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);

        S Offline
        S Offline
        Syouki_kou
        wrote on last edited by
        #3

        :-DThanks very very much, kakan. I get it.:laugh:

        K 1 Reply Last reply
        0
        • S Syouki_kou

          :-DThanks very very much, kakan. I get it.:laugh:

          K Offline
          K Offline
          kakan
          wrote on last edited by
          #4

          Your are welcome. I'm glad to be of help. Happy coding! Kakan

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups