Get Serial Number from scsi harddisk.

Hello Everybody

Does anybody know if I can read the ID of a scsi harddisk?
Reading the ID of IDE disks like discribed in http://dev-archive.earthweb.com/system/DiskId32.shtml works fine, but my software is going to run on servers which normally have scsi drives working in raid mode.
I think on scsi drives a serial number is implemented much longer than on IDE drives, but I have not yet found out how to get it.

Can anybody help, please?!
[466 byte] By [ham7446] at [2007-11-18 19:11:53]
# 1 Re: Get Serial Number from scsi harddisk.
Perhaps you can use GetVolumeInformation.
Marc G at 2007-11-11 1:18:20 >
# 2 Re: Get Serial Number from scsi harddisk.
Well...what do you mean by ID? The serial number? AFAIK, most SCSI disks do not have one...
Andreas Masur at 2007-11-11 1:19:20 >
# 3 Re: Get Serial Number from scsi harddisk.
I want serial number of the physical scsi hard disk.
I not want the volume serial number.

Help me, please...
ham7446 at 2007-11-11 1:20:21 >
# 4 Re: Get Serial Number from scsi harddisk.
Do a search for 'ASPI (Advanced SCSI Programming Interface)'. It might be that the 'DeviceIoControl()' function also is able to gather this information...
Andreas Masur at 2007-11-11 1:21:26 >
# 5 Re: Get Serial Number from scsi harddisk.
Why, does the error occur in the DeviceIoControl function?

#define FILE_DEVICE_SCSI 0x0000001b
#define IOCTL_SCSI_MINIPORT_IDENTIFY ((FILE_DEVICE_SCSI << 16) + 0x0501)
#define IOCTL_SCSI_MINIPORT 0x0004D008 // see NTDDSCSI.H for definition

int ReadIdeDriveAsScsiDriveInNT (void)
{
int done = FALSE;
int controller = 0;

for (controller = 0; controller < 16; controller++)
{
HANDLE hScsiDriveIOCTL = 0;
char driveName [256];

// Try to get a handle to PhysicalDrive IOCTL, report failure
// and exit if can't.
sprintf (driveName, "\\\\.\\Scsi%d:", controller);

// Windows NT, Windows 2000, any rights should do
hScsiDriveIOCTL = CreateFile (driveName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
// if (hScsiDriveIOCTL == INVALID_HANDLE_VALUE)
// printf ("Unable to open SCSI controller %d, error code: 0x%lX\n",
// controller, GetLastError ());

if (hScsiDriveIOCTL != INVALID_HANDLE_VALUE)
{
int drive = 0;

for (drive = 0; drive < 2; drive++)
{
char buffer [sizeof (SRB_IO_CONTROL) + SENDIDLENGTH];
SRB_IO_CONTROL *p = (SRB_IO_CONTROL *) buffer;
SENDCMDINPARAMS *pin =
(SENDCMDINPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));
DWORD dummy;

memset (buffer, 0, sizeof (buffer));
p -> HeaderLength = sizeof (SRB_IO_CONTROL);
p -> Timeout = 10000;
p -> Length = SENDIDLENGTH;
p -> ControlCode = IOCTL_SCSI_MINIPORT_IDENTIFY;
strncpy ((char *) p -> Signature, "SCSIDISK", 8);

pin -> irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;
pin -> bDriveNumber = drive;

if (DeviceIoControl (hScsiDriveIOCTL, IOCTL_SCSI_MINIPORT,
buffer,
sizeof (SRB_IO_CONTROL) +
sizeof (SENDCMDINPARAMS) - 1,
buffer,
sizeof (SRB_IO_CONTROL) + SENDIDLENGTH,
&dummy, NULL))
{
SENDCMDOUTPARAMS *pOut =
(SENDCMDOUTPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));
IDSECTOR *pId = (IDSECTOR *) (pOut -> bBuffer);
if (pId -> sModelNumber [0])
{
DWORD diskdata [256];
int ijk = 0;
USHORT *pIdSector = (USHORT *) pId;

for (ijk = 0; ijk < 256; ijk++)
diskdata [ijk] = pIdSector [ijk];

PrintIdeInfo (controller * 2 + drive, diskdata);

done = TRUE;
}
}
}
CloseHandle (hScsiDriveIOCTL);
}
}

return done;
}
ham7446 at 2007-11-11 1:22:25 >
# 6 Re: Get Serial Number from scsi harddisk.
Well...what error? Call 'GetLastError()' to retrieve the specific error code...
Andreas Masur at 2007-11-11 1:23:22 >
# 7 Re: Get Serial Number from scsi harddisk.
error code = 1, error message = "Incorrect Function"
ham7446 at 2007-11-11 1:24:29 >
# 8 Re: Get Serial Number from scsi harddisk.
Are you using Win95/98.
I got this one from MSDN:

Windows NT IOCTL Unavailable with Windows 95
Windows NT uses a miniport IOCTL interface that is not available with Windows 95.

Windows NT allows you to send IOCTLs to SCSI miniports, using CreateFile, and a filespec such as "\\.\Scsi0" and "\\.\c:". A sample application that uses this technique is found in the Windows NT DDK: \ddk\src\storage\class\spti.

Windows 95 does not support this Windows NT IOCTL technique.
qcnitin at 2007-11-11 1:25:21 >